SingleResult
The search results for a single query vector: its top-K hits with scores, primary keys and output fields.
public sealed class SingleResult
{
public string PrimaryKeyName { get; }
public Ids Ids { get; }
public IReadOnlyList<float> Scores { get; }
public IReadOnlyList<FieldData> OutputFields { get; }
public IReadOnlyDictionary<string, object?> GetRow(int rowIndex);
}
PARAMETERS:
PrimaryKeyName(string) -The primary key field name of the searched collection, as reported by the server.
Ids(Ids) -The primary keys of the top-K hits, in score order. See Ids.
Scores(IReadOnlyList) - The scores (distances) of the top-K hits, in descending similarity order.
OutputFields(IReadOnlyList) - The output fields of this query’s hits, one column per requested output field (column-oriented, one element per hit). See FieldData.
METHODS:
GetRow(int rowIndex)(IReadOnlyDictionary) - Materializes the hit at the given zero-based index into a row dictionary mapping field name to value (plus the
"score"entry), the same shape the row-based insert/upsert accepts.
Example
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Responses.Dql;
using Milvus.Client.V2.Types;
using var client = new MilvusClientV2(new ConnectConfig
{
Uri = "localhost:19530",
Username = "root",
Password = "Milvus"
});
SearchResp results = await client.SearchAsync(new SearchReq
{
CollectionName = "my_collection",
VectorFieldName = "embedding",
Vectors = [new[] { 0.1f, 0.2f, 0.3f, 0.4f }],
Limit = 5
});
foreach (SingleResult singleResult in results.SingleResults ?? [])
{
Console.WriteLine($"Top score: {singleResult.Scores[0]}");
foreach (long id in singleResult.Ids.LongIds ?? Array.Empty<long>())
{
Console.WriteLine(id);
}
}