Class ExpandingQueryTransformer
java.lang.Object
dev.langchain4j.rag.query.transformer.ExpandingQueryTransformer
- All Implemented Interfaces:
QueryTransformer
A
Refer to
Configurable parameters (optional):
-
-
QueryTransformer that utilizes a ChatModel to expand a given Query.
Refer to
DEFAULT_PROMPT_TEMPLATE and implementation for more details.
Configurable parameters (optional):
-
promptTemplate: The prompt template used to instruct the LLM to expand the provided Query.
-
n: The number of Querys to generate. Default value is 3.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChatModelstatic final intstatic final PromptTemplateprotected final intprotected final PromptTemplate -
Constructor Summary
ConstructorsConstructorDescriptionExpandingQueryTransformer(ChatModel chatModel) ExpandingQueryTransformer(ChatModel chatModel, int n) ExpandingQueryTransformer(ChatModel chatModel, PromptTemplate promptTemplate) ExpandingQueryTransformer(ChatModel chatModel, PromptTemplate promptTemplate, Integer n) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()protected PromptcreatePrompt(Query query) transformAsync(Query query) Non-blocking counterpart ofQueryTransformer.transform(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.
-
Field Details
-
DEFAULT_PROMPT_TEMPLATE
-
DEFAULT_N
public static final int DEFAULT_N- See Also:
-
chatModel
-
promptTemplate
-
n
protected final int n
-
-
Constructor Details
-
ExpandingQueryTransformer
-
ExpandingQueryTransformer
-
ExpandingQueryTransformer
-
ExpandingQueryTransformer
-
-
Method Details
-
builder
-
transform
Description copied from interface:QueryTransformer- Specified by:
transformin interfaceQueryTransformer- Parameters:
query- TheQueryto be transformed.- Returns:
- A collection of one or more
Querys derived from the originalQuery.
-
transformAsync
Description copied from interface:QueryTransformerNon-blocking counterpart ofQueryTransformer.transform(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.The default implementation returns a failed future carrying
AsyncNotSupportedException: a transformer backed by a blocking LLM call (e.g. query compression/expansion) must opt in by overriding this method to stay off the calling thread. A transformer that cannot be made non-blocking is still usable from these modes viaDefaultRetrievalAugmentor, which offloads the blockingQueryTransformer.transform(Query)to its executor.- Specified by:
transformAsyncin interfaceQueryTransformer- Parameters:
query- TheQueryto be transformed.- Returns:
- A
CompletableFutureof one or moreQuerys derived from the originalQuery.
-
createPrompt
-
parse
-