Table of Contents

Method SubmitAsync

Namespace
LMKit.Retrieval
Assembly
LM-Kit.NET.dll

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

question string

The question to ask.

cancellationToken CancellationToken

Token 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:

  1. If QueryGenerationMode is not Original and conversation history exists, the question is reformulated into a self-contained retrieval query using conversation context.
  2. Partitions are retrieved from the Engine using the selected retrieval strategy (original, contextual, multi-query, or HyDE).
  3. The RetrievalCompleted event is fired with retrieval results.
  4. 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 question is null or empty.

InvalidOperationException

Thrown if the engine has no data sources.

Share