Class LlmQueryRewriter
Rewrites follow-up queries into retrieval-ready form using an LLM, and can derive retrieval-oriented keywords for hybrid/text search. Uses StatelessMode internally so the rewriting call does not pollute conversation history.
public class LlmQueryRewriter : IQueryRewriter
- Inheritance
-
LlmQueryRewriter
- Implements
- Inherited Members
Constructors
LlmQueryRewriter(IAIService, uint, bool)
Creates a query rewriter that uses the specified AIService for rewriting queries into retrieval-ready form and optionally deriving retrieval-oriented keywords.
public LlmQueryRewriter(IAIService aiService, uint maxTokens = 250, bool extractKeywords = true)
Parameters
aiServiceIAIServiceThe AIService to use for query rewriting.
maxTokensuintMaximum tokens for the rewriter LLM response. Default is 250.
extractKeywordsboolWhen true (default), the rewriter also extracts retrieval-oriented keywords for the text/keyword search leg of hybrid search. When false, only query rewriting and search gate are performed.
Methods
RewriteAsync(string, IReadOnlyList<ConversationTurn>?, CancellationToken)
Rewrites the query into retrieval-ready form without depending on the caller's conversation state, and determines whether document search is needed.
public Task<QueryRewriteResult> RewriteAsync(string query, IReadOnlyList<ConversationTurn>? conversationHistory, CancellationToken cancellationToken = default)
Parameters
querystringThe current user query (e.g., "Tell me more about that").
conversationHistoryIReadOnlyList<ConversationTurn>Previous conversation turns for context.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<QueryRewriteResult>
A QueryRewriteResult containing the processed semantic query, optional retrieval-oriented keywords, and search gate decision.