Skip to content

Vector search should return similarity score or distance as well #2723

@hez2010

Description

@hez2010

Is your feature request related to a problem? Please describe.

The new Vector search is really easy to use, but to integrate it with Microsoft.Extensions.AI or other RAG frameworks, usually the similarity score is also required.
Currently neither WhereNear nor TopK returns the score.

Describe the solution you'd like

Make the WhereNear and TopK return both the record and score (or distance), allowing users to select on it.

// Find all documents in this collection where the COS Sim distance is <= 0.3
// based on the values in the object's Embedding property (float[])
var matches = col.Query()
    .WhereNear(x => x.Embedding, queryVec, maxDistance: 0.3f)
    .Select(x => new VectorSearchResult(x.Record, x.Score))
    .ToList();

// Find all documents in the same collection by KNN, returning closest 5
var top5 = col.Query()
    .TopK(x => x.Embedding, queryVec, k: 5)
    .Select(x => new VectorSearchResult(x.Record, x.Score))
    .ToList();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions