Interface QueryExpander


public interface QueryExpander
Service provider interface for model-backed retrieval query expansion.

Providers advertise the exact expansion modes and model identifiers they support through supports(Search.QueryExpansion, String) and are discovered with ServiceLoader. TnsAI does not bundle or impersonate an LLM: provider modules own inference, credentials, transport, and lifecycle management.

An expansion invocation must return only generated query variations. The runtime retains the original query, removes blank and duplicate variations, and enforces QueryExpander.Request.maxExpansions() as a hard bound.

Since:
0.13.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    Immutable input passed to a QueryExpander provider.
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates query variations for one retrieval request.
    boolean
    supports(com.tnsai.annotations.Search.QueryExpansion mode, String model)
    Returns whether this provider supports the exact mode/model pair.
  • Method Details

    • supports

      boolean supports(com.tnsai.annotations.Search.QueryExpansion mode, String model)
      Returns whether this provider supports the exact mode/model pair.

      The answer must be local — no network call — because Role initialization checks provider support before dispatch and the runtime rechecks it on every retrieval dispatch before consulting the result cache.

      Parameters:
      mode - expansion mode; never Search.QueryExpansion.NONE
      model - exact, case-sensitive model identifier
      Returns:
      true when this provider can serve the request
    • expand

      List<String> expand(QueryExpander.Request request)
      Generates query variations for one retrieval request.

      Implementations should observe QueryExpander.Request.cancellationToken() before and after blocking work.

      Parameters:
      request - immutable expansion request
      Returns:
      generated query variations, excluding the original query