Table of Contents

Method FindMatchingPartitionsAsync

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

FindMatchingPartitionsAsync(string, int, float, bool, CancellationToken)

Asynchronously initiates a search operation to find similarities within the text entries in all registered DataSource objects.

public Task<List<RagEngine.TextPartitionSimilarity>> FindMatchingPartitionsAsync(string text, int topK = 3, float minScore = 0.5, bool forceUniqueDataSource = false, CancellationToken cancellationToken = default)

Parameters

text string

The text string used to find similar entries.

topK int

Max number of RagEngine.TextPartitionSimilarity instances. Default 3.

minScore float

Minimum similarity score required ([0 - 1]). Default is 0.5.

forceUniqueDataSource bool

If true, returned results must come from the same DataSource. Default false.

cancellationToken CancellationToken

A CancellationToken for canceling the operation.

Returns

Task<List<RagEngine.TextPartitionSimilarity>>

A list of RagEngine.TextPartitionSimilarity 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<TextPartitionSimilarity> 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.