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
text
stringThe text string used to find similar entries.
topK
intMax number of PartitionSimilarity instances. Default 3.
minScore
floatMinimum similarity score required ([0 - 1]). Default is 0.5.
forceUniqueDataSource
boolIf true, returned results must come from the same DataSource. Default false.
forceUniqueSection
boolIf true, returned results must come from the same Section. Default false.
cancellationToken
CancellationTokenA 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
attachment
AttachmentThe Attachment containing the content to query for similar partitions.
topK
intThe maximum number of PartitionSimilarity results to return. Default is 3.
minScore
floatThe minimum similarity score threshold (0 to 1) for returned results. Default is 0.5.
forceUniqueDataSource
boolIf true, results will be constrained to a single DataSource. Default is false.
forceUniqueSection
boolIf true, results will be constrained to a single Section. Default is false.
cancellationToken
CancellationTokenAn optional CancellationToken to cancel the operation.
Returns
- Task<List<PartitionSimilarity>>
A Task<TResult> that resolves to a list of PartitionSimilarity objects meeting the criteria.