Method QueryPartitionsAsync
QueryPartitionsAsync(string, IEnumerable<TextPartitionSimilarity>, IConversation, CancellationToken)
Asynchronously generates a text result by querying specified text partitions within the provided chat context.
public Task<TextGenerationResult> QueryPartitionsAsync(string query, IEnumerable<RagEngine.TextPartitionSimilarity> partitionSimilarities, IConversation chat, CancellationToken cancellationToken = default)
Parameters
query
stringThe query text.
partitionSimilarities
IEnumerable<RagEngine.TextPartitionSimilarity>A collection of RagEngine.TextPartitionSimilarity instances.
chat
IConversationAn IConversation representing the chat context.
cancellationToken
CancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<TextGenerationResult>
A task that returns a TextGenerationResult upon completion.
Examples
using LMKit.Data;
using LMKit.Model;
using LMKit.Retrieval;
using LMKit.TextGeneration;
using LMKit.TextGeneration.Chat;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
class Example
{
static async Task Main()
{
LM embeddingModel = new LM(new Uri("https://example-embedding-uri.com"));
RagEngine ragEngine = new RagEngine(embeddingModel);
// Suppose we have a chat model
LM chatModel = new LM(new Uri("https://example-chat-model.com"));
IConversation chat = new SingleTurnConversation(chatModel);
// Assume we've already imported text, and found some similar partitions
List<TextPartitionSimilarity> partitions = new List<TextPartitionSimilarity> {
// ...some placeholder similarities...
};
string userQuery = "Summarize the main idea.";
TextGenerationResult asyncResult = await ragEngine.QueryPartitionsAsync(userQuery, partitions, chat);
Console.WriteLine("Generated Answer (Async):");
Console.WriteLine(asyncResult.Text);
}
}