Table of Contents

Method FindMatchingPartitionsAsync

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

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

Asynchronously searches for similar partitions across all registered data sources using text similarity.

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 query text to find similar entries for.

topK int

Maximum number of results to return. Default is 3.

minScore float

Minimum similarity score threshold (0.0 to 1.0). Default is 0.5.

forceUniqueDataSource bool

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

forceUniqueSection bool

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

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<List<PartitionSimilarity>>

A task that resolves to a list of PartitionSimilarity objects meeting the criteria.

Examples

LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
RagEngine ragEngine = new RagEngine(embeddingModel);

// Import some documents first...
await ragEngine.ImportTextAsync("Document content here", "docs", "section1");

// Search for similar partitions
var matches = await ragEngine.FindMatchingPartitionsAsync(
    text: "Latest developments in quantum computing",
    topK: 5,
    minScore: 0.3f);

Console.WriteLine($"Found {matches.Count} matching partitions.");

Remarks

This method computes embeddings for the input text and performs a vector similarity search against all partitions in the registered data sources.

If a Reranker is configured, results are reranked using the reranking model before the final top-K selection.

Exceptions

ArgumentNullException

Thrown if no data sources are registered.

OperationCanceledException

Thrown if the operation is canceled.

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

Asynchronously searches for similar partitions across all registered data sources using attachment content.

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 search for.

topK int

Maximum number of results to return. Default is 3.

minScore float

Minimum similarity score threshold (0.0 to 1.0). Default is 0.5.

forceUniqueDataSource bool

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

forceUniqueSection bool

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

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<List<PartitionSimilarity>>

A task that resolves to a list of PartitionSimilarity objects meeting the criteria.

Remarks

The attachment's content is converted to embeddings (text or vision, depending on the content type) and a similarity search is performed against all registered data sources.

For vision-enabled attachments, a vision embedding model must be registered with the engine.

Exceptions

ArgumentNullException

Thrown if no data sources are registered.

ArgumentException

Thrown if the required embedding model is not available.

OperationCanceledException

Thrown if the operation is canceled.