Class TranslationQueryTransformer
java.lang.Object
org.springframework.ai.rag.preretrieval.query.transformation.TranslationQueryTransformer
- All Implemented Interfaces:
Function<Query,,Query> QueryTransformer
Uses a large language model to translate a query to a target language that is supported
by the embedding model used to generate the document embeddings. If the query is
already in the target language, it is returned unchanged. If the language of the query
is unknown, it is also returned unchanged.
This transformer is useful when the embedding model is trained on a specific language and the user query is in a different language.
Example usage:
QueryTransformer transformer = TranslationQueryTransformer.builder()
.chatClientBuilder(chatClientBuilder)
.targetLanguage("english")
.build();
Query transformedQuery = transformer.transform(new Query("Hvad er Danmarks hovedstad?"));
- Since:
- 1.0.0
- Author:
- Thomas Vitale
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionTranslationQueryTransformer(org.springframework.ai.chat.client.ChatClient.Builder chatClientBuilder, org.springframework.ai.chat.prompt.PromptTemplate promptTemplate, String targetLanguage) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Transforms the given query according to the implemented strategy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.rag.preretrieval.query.transformation.QueryTransformer
apply
-
Constructor Details
-
TranslationQueryTransformer
public TranslationQueryTransformer(org.springframework.ai.chat.client.ChatClient.Builder chatClientBuilder, @Nullable org.springframework.ai.chat.prompt.PromptTemplate promptTemplate, String targetLanguage)
-
-
Method Details
-
transform
Description copied from interface:QueryTransformerTransforms the given query according to the implemented strategy.- Specified by:
transformin interfaceQueryTransformer- Parameters:
query- The original query to transform- Returns:
- The transformed query
-
builder
-