Table of Contents

Method FindMatchingPartitionsAsync

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

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 string

The text string used to find similar entries.

topK int

Max number of PartitionSimilarity 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.

forceUniqueSection bool

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

cancellationToken CancellationToken

A 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 Attachment

The Attachment containing the content to query for similar partitions.

topK int

The maximum number of PartitionSimilarity results to return. Default is 3.

minScore float

The minimum similarity score threshold (0 to 1) for returned results. Default is 0.5.

forceUniqueDataSource bool

If true, results will be constrained to a single DataSource. Default is false.

forceUniqueSection bool

If true, results will be constrained to a single Section. Default is false.

cancellationToken CancellationToken

An optional CancellationToken to cancel the operation.

Returns

Task<List<PartitionSimilarity>>

A Task<TResult> that resolves to a list of PartitionSimilarity objects meeting the criteria.