Method QueryPartitions
QueryPartitions(string, IEnumerable<TextPartitionSimilarity>, IConversation, CancellationToken)
Generates a text result by querying specified text partitions and initiating a conversation within the provided chat context.
public TextGenerationResult QueryPartitions(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 that can cancel the operation.
Returns
- TextGenerationResult
A TextGenerationResult containing the generated result.
Examples
using LMKit.Data;
using LMKit.Model;
using LMKit.Retrieval;
using LMKit.TextGeneration;
using LMKit.TextGeneration.Chat;
using System;
using System.Collections.Generic;
class Example
{
static void 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 similar partitions
List<TextPartitionSimilarity> partitions = new List<TextPartitionSimilarity> {
// ...some placeholder similarities...
};
string userQuery = "What is RAG?";
TextGenerationResult result = ragEngine.QueryPartitions(userQuery, partitions, chat);
Console.WriteLine("Generated Answer:");
Console.WriteLine(result.Text);
}
}