Skip to content

Commit 59fbd9e

Browse files
apappascsilayaperumalg
authored andcommitted
fix: remove default temperature on all QueryTransformer implementations
Signed-off-by: Alexandros Pappas <[email protected]> update documentation Signed-off-by: Alexandros Pappas <[email protected]>
1 parent edc3566 commit 59fbd9e

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/retrieval-augmented-generation.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Pre-Retrieval modules are responsible for processing the user query to achieve t
172172
A component for transforming the input query to make it more effective for retrieval tasks, addressing challenges
173173
such as poorly formed queries, ambiguous terms, complex vocabulary, or unsupported languages.
174174

175+
IMPORTANT: When using a `QueryTransformer`, it's recommended to configure the `ChatClient.Builder` with a low temperature (e.g., 0.0) to ensure more deterministic and accurate results, improving retrieval quality. The default temperature for most chat models is typically too high for optimal query transformation, leading to reduced retrieval effectiveness.
176+
175177
===== CompressionQueryTransformer
176178

177179
A `CompressionQueryTransformer` uses a large language model to compress a conversation history and a follow-up query

spring-ai-rag/src/main/java/org/springframework/ai/rag/preretrieval/query/transformation/CompressionQueryTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Query transform(Query query) {
8484
.user(user -> user.text(this.promptTemplate.getTemplate())
8585
.param("history", formatConversationHistory(query.history()))
8686
.param("query", query.text()))
87-
.options(ChatOptions.builder().temperature(0.0).build())
87+
.options(ChatOptions.builder().build())
8888
.call()
8989
.content();
9090

spring-ai-rag/src/main/java/org/springframework/ai/rag/preretrieval/query/transformation/RewriteQueryTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Query transform(Query query) {
8282
.user(user -> user.text(this.promptTemplate.getTemplate())
8383
.param("target", this.targetSearchSystem)
8484
.param("query", query.text()))
85-
.options(ChatOptions.builder().temperature(0.0).build())
85+
.options(ChatOptions.builder().build())
8686
.call()
8787
.content();
8888

spring-ai-rag/src/main/java/org/springframework/ai/rag/preretrieval/query/transformation/TranslationQueryTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Query transform(Query query) {
9191
.user(user -> user.text(this.promptTemplate.getTemplate())
9292
.param("targetLanguage", this.targetLanguage)
9393
.param("query", query.text()))
94-
.options(ChatOptions.builder().temperature(0.0).build())
94+
.options(ChatOptions.builder().build())
9595
.call()
9696
.content();
9797

0 commit comments

Comments
 (0)