Method FindMatchingPartitionsAsync
FindMatchingPartitionsAsync(string, int, float, bool, bool, CancellationToken)
Asynchronously initiates a search operation to find similarities within the text entries in all registered DataSource objects.
public Task<List<PartitionSimilarity>> FindMatchingPartitionsAsync(string text, int topK = 3, float minScore = 0.5, bool forceUniqueDataSource = false, bool forceUniqueSection = false, CancellationToken cancellationToken = default)
Parameters
textstringThe text string used to find similar entries.
topKintMax number of PartitionSimilarity instances. Default 3.
minScorefloatMinimum similarity score required ([0 - 1]). Default is 0.5.
forceUniqueDataSourceboolIf true, returned results must come from the same DataSource. Default false.
forceUniqueSectionboolIf true, returned results must come from the same Section. Default false.
cancellationTokenCancellationTokenA CancellationToken for canceling the operation.
Returns
- Task<List<PartitionSimilarity>>
A list of PartitionSimilarity objects meeting the criteria.
Examples
using LMKit.Data;
using LMKit.Model;
using LMKit.Retrieval;
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 some DataSources have been added...
List<PartitionSimilarity> similarities = await ragEngine.FindMatchingPartitionsAsync(
text: "Latest developments in quantum computing",
topK: 5,
minScore: 0.3f
);
Console.WriteLine("Asynchronous search found: " + similarities.Count + " partitions.");
}
}
Exceptions
- ArgumentNullException
Thrown if there are no data sources.
- OperationCanceledException
Thrown if canceled.
FindMatchingPartitionsAsync(Attachment, int, float, bool, bool, CancellationToken)
Asynchronously finds the top topK PartitionSimilarity instances matching the content of the given Attachment.
The attachment's content is converted to embeddings (text or vision), and a similarity search is performed against all registered data sources.
public Task<List<PartitionSimilarity>> FindMatchingPartitionsAsync(Attachment attachment, int topK = 3, float minScore = 0.5, bool forceUniqueDataSource = false, bool forceUniqueSection = false, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe Attachment containing the content to query for similar partitions.
topKintThe maximum number of PartitionSimilarity results to return. Default is 3.
minScorefloatThe minimum similarity score threshold (0 to 1) for returned results. Default is 0.5.
forceUniqueDataSourceboolIf true, results will be constrained to a single DataSource. Default is false.
forceUniqueSectionboolIf true, results will be constrained to a single Section. Default is false.
cancellationTokenCancellationTokenAn optional CancellationToken to cancel the operation.
Returns
- Task<List<PartitionSimilarity>>
A Task<TResult> that resolves to a list of PartitionSimilarity objects meeting the criteria.