Stevenic / vectra

Vectra is a local vector database for Node.js with features similar to pinecone but built using local files.
MIT License
321 stars 29 forks source link

$in filter not working as expected #35

Closed Seyronh closed 2 months ago

Seyronh commented 6 months ago

When using the metadata filter in queryItems as described in https://docs.pinecone.io/docs/metadata-filtering, I am making the following request:

let data = await vectordb.queryItems(embedding, 1, { categories: { "$in": ["one", "two"] } });

The index I'm searching for has the metadata categories set to ["one"], but it is returning 0 matches.

Perhaps using filter[key].some(val => val.includes(value)) when the value is an array could make it work properly?

Seyronh commented 6 months ago

I modified the code and it worked properly maybe its the solution?

                case '$in':
                    if (typeof value == 'boolean') {
                        return false;
                    } else if(typeof value == 'string' && !filter[key].includes(value)){
                        return false
                    } else if(!filter[key].some(val => val.includes(value))){
                        return false
                    }
                    break;
Stevenic commented 6 months ago

@Seyronh mind submitting your fix as a PR?

Stevenic commented 6 months ago

I need to create more rigorous unit tests around the filtering bits...