Method SubmitAsync
SubmitAsync(string, CancellationToken)
Asynchronously submits a question and returns the generated response grounded in retrieved context.
public Task<RagQueryResult> SubmitAsync(string question, CancellationToken cancellationToken = default)
Parameters
questionstringThe question to ask.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<RagQueryResult>
A task containing a RagQueryResult with the generated response and the partitions used as context.
Examples
using var chat = new RagChat(ragEngine, chatModel);
var result = await chat.SubmitAsync("What is retrieval-augmented generation?");
Console.WriteLine(result.Response.Completion);
// Follow-up with automatic context tracking
result = await chat.SubmitAsync("How does it improve accuracy?");
Remarks
The method orchestrates the following steps:
- If QueryGenerationMode is not Original and conversation history exists, the question is reformulated into a self-contained retrieval query using conversation context.
- Partitions are retrieved from the Engine using the selected retrieval strategy (original, contextual, multi-query, or HyDE).
- The RetrievalCompleted event is fired with retrieval results.
- A prompt is constructed from the retrieved context and submitted to the internal conversation for response generation.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
- ArgumentNullException
Thrown if
questionisnullor empty.- InvalidOperationException
Thrown if the engine has no data sources.