Table of Contents

Class LlmQueryRewriter

Namespace
Mythosia.AI.Rag
Assembly
Mythosia.AI.Rag.dll

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

aiService IAIService

The AIService to use for query rewriting.

maxTokens uint

Maximum tokens for the rewriter LLM response. Default is 250.

extractKeywords bool

When 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

query string

The current user query (e.g., "Tell me more about that").

conversationHistory IReadOnlyList<ConversationTurn>

Previous conversation turns for context.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<QueryRewriteResult>

A QueryRewriteResult containing the processed semantic query, optional retrieval-oriented keywords, and search gate decision.