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

kNN Query Limit Error: "k value in knn query too large, provided X and the limit is 4096" #157

Open
LukasKriesch opened this issue Dec 18, 2024 · 2 comments

Comments

@LukasKriesch
Copy link

When performing k-Nearest Neighbors (kNN) queries using the sqlite-vec extension, queries with a LIMIT or k value greater than the configured maximum (vec_max_k) result in an OperationalError. The default maximum k value is 4096, which can cause issues when trying to retrieve a larger number of results.
Is there a possibility to extend the limit?

@yusufsyaifudin
Copy link

I also encounter this issues in latest version (Python 0.1.6), and surprised why a kNN query must have harder limit.. I think the maximum limit must the length of row, so we can get all possibilities regardless the score returned..

@asg017
Copy link
Owner

asg017 commented Dec 19, 2024

Hello! So that 4096 limit was attacked to mitigate any possible denial of service attacks, because the results of KNN queries are stored in memory.

I wanted to avoid an attacker adding a k = 99999999 clause to a query and exhausting all the memory of an application.

That being said, making this a configurable settings makes a lot of sense, so I'll take a look at including one. Probably one that can either 1) increase the limit to a new N value, or 2) removing the limit entirely. But this would be an opt-in per-table flag, since I want the default to always be safe.

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

3 participants