Table of Contents

Method FindMatchingPartitions

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

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

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

public List<RagEngine.TextPartitionSimilarity> FindMatchingPartitions(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

Maximum number of RagEngine.TextPartitionSimilarity instances to return. Default is 3.

minScore float

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

forceUniqueDataSource bool

If true, all returned candidates must come from the same DataSource. Default is false.

cancellationToken CancellationToken

A CancellationToken to cancel the operation.

Returns

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;

class Example
{
    static void Main()
    {
        LM embeddingModel = new LM(new Uri("https://example-embedding-uri.com"));
        RagEngine ragEngine = new RagEngine(embeddingModel);

        // Suppose we've already added data sources via ragEngine.AddDataSource(...)

        // We want to find the top 2 partitions matching a query
        List<TextPartitionSimilarity> similarities = ragEngine.FindMatchingPartitions(
            text: "AI research advancements",
            topK: 2,
            minScore: 0.4f
        );

        Console.WriteLine("Similar partitions found: " + similarities.Count);
    }
}

Exceptions

ArgumentNullException

Thrown if there are no data sources registered.

OperationCanceledException

Thrown if the operation is canceled.