Azure / Azure/azure-search-vector-samples

KNearestNeighborsCount - odd ranking

Open
#95 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
910
Forks
377
PR merge metrics
No merged PRs in 30d

Description

I'm executing a vector search against Azure Cognitive Search, using the (currently) latest version of the Azure.Search.Documents Nuget package (11.5.0-beta4).

If I execute a search with KNearestNeighborsCount set to 3, the closest match (in my opinion) is returned 3rd in the list.

However, if I do the same search with KNearestNeighborsCount set to 10 (I want to see more search results), the match I mention above is returned 8th in the list.

This doesn't make sense to me. I would have thought the match would always appear in the same position, for any value of KNearestNeighborsCount >= 3.

Q. How do I return 10 results, but have my closest match appear at position 3?

```
var vector = new SearchQueryVector { KNearestNeighborsCount = numNearestNeighbours, Fields = { nameof(DocumentModel.vector1) }, Value = embeddings };

var searchOptions = new SearchOptions
{
Vectors = { vector },
Size = numNearestNeighbours,
Select = { idFieldName },
};

SearchResults response = searchClient.Search(null, searchOptions);

var result = new List();

foreach (SearchResult searchResult in response.GetResults())
{
var documentId = $"{searchResult.Document[idFieldName]}";
result.Add(documentId);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.