Method GetScore
- Namespace
- LMKit.Embeddings
- Assembly
- LM-Kit.NET.dll
GetScore(string, string, CancellationToken)
Computes a similarity score for a single document synchronously.
public float GetScore(string query, string document, CancellationToken cancellationToken = default)
Parameters
querystringThe input text query. Must not be
null.documentstringThe document text to compare against the query. Must not be
null.cancellationTokenCancellationTokenA token to cancel the operation if needed.
Returns
Examples
using LMKit.Model;
using LMKit.Embeddings;
using System;
LM model = LM.LoadFromModelID("embeddinggemma-300m");
Reranker reranker = new Reranker(model);
// Compare multiple documents to find the most relevant
string query = "machine learning algorithms";
string[] documents =
{
"Neural networks are used for pattern recognition.",
"The weather forecast predicts rain tomorrow.",
"Deep learning models require large datasets."
};
for (int i = 0; i < documents.Length; i++)
{
float score = reranker.GetScore(query, documents[i]);
Console.WriteLine($"Doc {i}: {score:F4} - {documents[i]}");
}
Exceptions
- ArgumentNullException
Thrown if
queryordocumentisnull.
GetScore(string, IEnumerable<string>, CancellationToken)
Computes similarity scores for a collection of documents synchronously.
public float[] GetScore(string query, IEnumerable<string> documents, CancellationToken cancellationToken = default)
Parameters
querystringThe input text query. Must not be
null.documentsIEnumerable<string>An enumerable of document texts. Must not be
nullor empty.cancellationTokenCancellationTokenA token to cancel the operation if needed.
Returns
Exceptions
- ArgumentNullException
Thrown if
queryisnullordocumentsisnullor empty.
GetScore(string, TextPartition, CancellationToken)
Computes a similarity score for a single text partition synchronously.
public float GetScore(string query, TextPartition partition, CancellationToken cancellationToken = default)
Parameters
querystringThe input text query. Must not be
null.partitionTextPartitionThe text partition to compare against the query. Must not be
null.cancellationTokenCancellationTokenA token to cancel the operation if needed.
Returns
Exceptions
- ArgumentNullException
Thrown if
queryisnullorpartitionisnull.
GetScore(string, IEnumerable<TextPartition>, CancellationToken)
Computes similarity scores for a collection of text partitions synchronously.
public float[] GetScore(string query, IEnumerable<TextPartition> partitions, CancellationToken cancellationToken = default)
Parameters
querystringThe input text query. Must not be
null.partitionsIEnumerable<TextPartition>An enumerable of text partitions. Must not be
nullor empty.cancellationTokenCancellationTokenA token to cancel the operation if needed.
Returns
Exceptions
- ArgumentNullException
Thrown if
queryisnullorpartitionsisnullor empty.