Skip to content

KNN search accepts negative k #3788

@PavelShilin89

Description

@PavelShilin89

Bug Description:

KNN search accepts negative k values without validation and returns all documents instead of throwing an error.
MRE

CREATE TABLE test (vec FLOAT_VECTOR KNN_TYPE='hnsw' KNN_DIMS='2' HNSW_SIMILARITY='l2');
INSERT INTO test VALUES (1,(1,2)), (2,(3,4));
SELECT COUNT(*) FROM test WHERE KNN(vec, -1, (0,0));

Expected behavior
Should return an error, for example:

ERROR: k parameter must be positive 

Manticore Search Version:

Manticore 13.11.7 bf5b72e3f@25092618 dev (columnar 8.0.6 9a3b45b@25092117) (secondary 8.0.6 9a3b45b@25092117) (knn 8.0.6 9a3b45b@25092117) (embeddings 1.0.1)

Operating System Version:

Ubuntu 24.04.3 LTS

Have you tried the latest development version?

Yes

Internal Checklist:

To be completed by the assignee. Check off tasks that have been completed or are not applicable.

  • Implementation completed
  • Tests developed
  • Documentation updated
  • Documentation reviewed

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions