Summary
DocumentCollection<TId,T>.VectorSearchAsync silently discards the cosine similarity score returned by the underlying HNSW index, making it impossible to filter or rank results by relevance from the typed API.
Current behaviour
csharp public async IAsyncEnumerable<T> VectorSearchAsync( string indexName, float[] query, int k, int efSearch = 100, ...) { foreach (var result in index.VectorSearch(query, k, efSearch, null)) { var doc = await FindByLocationAsync(result.Location, 0UL, ct); if (doc != null) yield return doc; // result.Distance is thrown away } }
The internal VectorSearchResult struct already carries the distance:
csharp public record struct VectorSearchResult(DocumentLocation Location, float Distance);
Expected behaviour
A companion overload (or a separate method) that surfaces the score alongside the document, for example:
csharp IAsyncEnumerable<(T Document, float Distance)> VectorSearchWithScoreAsync( string indexName, float[] query, int k, int efSearch = 100, CancellationToken ct = default);
This would allow callers to:
- Apply a minimum-similarity threshold (e.g. distance < 0.35 for cosine) to avoid returning irrelevant results.
- Rank results or expose confidence in RAG / semantic-search pipelines.
Workaround
Currently the only workaround is to bypass DocumentDbContext entirely and re-open the file with the schema-less BLiteEngine, which defeats the purpose of the typed API.
Context
Discovered while building a RAG help-search layer on top of BLite using the DocumentDbContext / source-generator pattern with �ll-MiniLM-L6-v2 (384-dim, cosine metric).
Summary
DocumentCollection<TId,T>.VectorSearchAsync silently discards the cosine similarity score returned by the underlying HNSW index, making it impossible to filter or rank results by relevance from the typed API.
Current behaviour
csharp public async IAsyncEnumerable<T> VectorSearchAsync( string indexName, float[] query, int k, int efSearch = 100, ...) { foreach (var result in index.VectorSearch(query, k, efSearch, null)) { var doc = await FindByLocationAsync(result.Location, 0UL, ct); if (doc != null) yield return doc; // result.Distance is thrown away } }The internal VectorSearchResult struct already carries the distance:
csharp public record struct VectorSearchResult(DocumentLocation Location, float Distance);Expected behaviour
A companion overload (or a separate method) that surfaces the score alongside the document, for example:
csharp IAsyncEnumerable<(T Document, float Distance)> VectorSearchWithScoreAsync( string indexName, float[] query, int k, int efSearch = 100, CancellationToken ct = default);This would allow callers to:
Workaround
Currently the only workaround is to bypass DocumentDbContext entirely and re-open the file with the schema-less BLiteEngine, which defeats the purpose of the typed API.
Context
Discovered while building a RAG help-search layer on top of BLite using the DocumentDbContext / source-generator pattern with �ll-MiniLM-L6-v2 (384-dim, cosine metric).