sqlite-vec icon indicating copy to clipboard operation
sqlite-vec copied to clipboard

The WHERE clause does not support LIKE

Open springrain opened this issue 10 months ago • 3 comments

CREATE VIRTUAL TABLE IF NOT EXISTS vec_document_chunk USING vec0(
     id TEXT,
    documentID TEXT,
    knowledgeBaseID TEXT,
    embedding float[1024],
    sortNo INT,
    status INT
);

SELECT rowid,distance as score,* FROM vec_document_chunk WHERE embedding MATCH ? and knowledgeBaseID like ? ORDER BY score LIMIT 5

An illegal WHERE constraint was provided on a vec0 metadata column in a KNN query. Only one of EQUALS, GREATER_THAN, LESS_THAN_OR_EQUAL, LESS_THAN, GREATER_THAN_OR_EQUAL, NOT_EQUALS is allowed.

springrain avatar Feb 07 '25 03:02 springrain

Thanks for filing - yes LIKE isn't supported yet. Can I ask what pattern you're using in your example? If you're comparing exact IDs, you could also use knowledgeBaseID = ? if you're using an exact match.

Nonetheless, LIKE support requires some special handling, because the internal representation of text metadata stores the first 12 bytes of a string in an easy-to-access cache and the rest in a separate buffer. Would could easily support LIKE patterns that end with a wildcard, ex `name LIKE 'Ale%', but more complex patterns may be more difficult.

asg017 avatar Feb 07 '25 17:02 asg017

It can support LIKE patterns that end with a wildcard. Thank you very much.

Thanks for filing - yes LIKE isn't supported yet. Can I ask what pattern you're using in your example? If you're comparing exact IDs, you could also use knowledgeBaseID = ? if you're using an exact match.

Nonetheless, LIKE support requires some special handling, because the internal representation of text metadata stores the first 12 bytes of a string in an easy-to-access cache and the rest in a separate buffer. Would could easily support LIKE patterns that end with a wildcard, ex `name LIKE 'Ale%', but more complex patterns may be more difficult.

springrain avatar Feb 08 '25 03:02 springrain

@asg017 Do you have a plan to implement like 'abc%' ?

springrain avatar Feb 11 '25 16:02 springrain