Class TranslationQueryTransformer

java.lang.Object
org.springframework.ai.rag.preretrieval.query.transformation.TranslationQueryTransformer
All Implemented Interfaces:
Function<Query,Query>, QueryTransformer

public final class TranslationQueryTransformer extends Object implements 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
  • 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