Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when number of filtered items in index is less than requested K #444

Open
wskish opened this issue Mar 8, 2023 · 6 comments
Open

Comments

@wskish
Copy link

wskish commented Mar 8, 2023

When using filters and requesting a K larger than the number of filtered items in the index, hnswlib will raise the following exception:
"RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small"

Would it be possible to just return however many items are available in this case instead of raising the exception.

@yurymalkov
Copy link
Member

Hi @wskish,
I guess it is possible to change the behavior, but it should be clearly defined what to do in what situation and how to alert the user that something is wrong (usually that is a sign of bad hyperparameters, like ef or M or a broken index).

@wskish
Copy link
Author

wskish commented Mar 19, 2023

In the case I am seeing the ef/M/index are fine it is just that there are actually fewer than K items in the index that meet the filter criteria. So the base assumption that K nearest neighbors actually exist (after filtering) is the issue.

@yurymalkov
Copy link
Member

Oh. Got it. Yeah, that needs to be fixed.
One issue is that the batch search returns a numpy matrix. In case there are routinely not enough candidates, the matrix would not be filled. Maybe can add something like -1 to indicate the lack of result to keep the api intact. Will think about that.

@jeffchuber
Copy link

@yurymalkov +1! eg chroma-core/chroma#225

@yurymalkov
Copy link
Member

Yeah, we are gonna work on it.

@danishshaikh556
Copy link

Circling back to see if we indeed fixed this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants