Skip to content

Commit 0c5455e

Browse files
committed
Improve context formatting in QuestionAnswerAdvisor
- Add line breaks and clarify context boundaries in user text advice. This improve the performance of a Llama3.x - Update corresponding test to reflect new formatting
1 parent 4c83fe8 commit 0c5455e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@
5252
public class QuestionAnswerAdvisor implements CallAroundAdvisor, StreamAroundAdvisor {
5353

5454
private static final String DEFAULT_USER_TEXT_ADVISE = """
55-
Context information is below.
55+
56+
Context information is below, surrounded by ---------------------
57+
5658
---------------------
5759
{question_answer_context}
5860
---------------------
61+
5962
Given the context and provided history information and not prior knowledge,
6063
reply to the user comment. If the answer is not in the context, inform
6164
the user that you can't answer the question.

spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ public void qaAdvisorWithDynamicFilterExpressions() {
9797

9898
assertThat(userMessage.getContent()).isEqualToIgnoringWhitespace("""
9999
Please answer my question XYZ
100-
Context information is below.
100+
Context information is below, surrounded by ---------------------
101+
101102
---------------------
102103
doc1
103104
doc2
104105
---------------------
106+
105107
Given the context and provided history information and not prior knowledge,
106108
reply to the user comment. If the answer is not in the context, inform
107109
the user that you can't answer the question.

0 commit comments

Comments
 (0)