Interface QueryTransformer

All Known Implementing Classes:
CompressingQueryTransformer, DefaultQueryTransformer, ExpandingQueryTransformer

public interface QueryTransformer
Transforms the given Query into one or multiple Querys.
The goal is to enhance retrieval quality by modifying or expanding the original Query.
Some known approaches to improve retrieval include:
- Query compression (see CompressingQueryTransformer)
- Query expansion (see ExpandingQueryTransformer)
- Query re-writing
- Step-back prompting
- Hypothetical document embeddings (HyDE)
Additional details can be found here.
See Also:
  • Method Details

    • transform

      Collection<Query> transform(Query query)
      Transforms the given Query into one or multiple Querys.
      Parameters:
      query - The Query to be transformed.
      Returns:
      A collection of one or more Querys derived from the original Query.
    • transformAsync

      @Experimental default CompletableFuture<Collection<Query>> transformAsync(Query query)
      Non-blocking counterpart of 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 via DefaultRetrievalAugmentor, which offloads the blocking transform(Query) to its executor.

      An implementation must not throw and must not return null: every failure, including an invalid argument, completes the returned future exceptionally.

      Parameters:
      query - The Query to be transformed.
      Returns:
      A CompletableFuture of one or more Querys derived from the original Query.
      Since:
      1.20.0