supabase / vecs

Postgres/pgvector Python Client
https://supabase.github.io/vecs/latest
Apache License 2.0
219 stars 33 forks source link

`$in` operator doesn't seem to work #78

Closed jeanmaried closed 7 months ago

jeanmaried commented 7 months ago

I am trying to use the $in operator to query metadata which contains a list of integers: "tags": [20]. Using the filter always returns an empty list even though their is a match.

Steps to reproduce the behavior:

  1. have a vecs entry with metadata like so: {"tags": [20]}
  2. query with that filter:
collection.query(
            data=[...],
            include_metadata=True,
            include_value=True,
            filters={"tags": {"$in": [20]}})

I tried with:

collection.query(
            data=[...],
            include_metadata=True,
            include_value=True,
            filters={"tags": {"$eq": [20]}})

Which works so it seems specific to $in.

Expected behavior Should return matching entry

Versions:

olirice commented 7 months ago

The behavior you're describing is correct behavior for $in. The $in operator validates if a value is contained within an array of metadata.

Converting those expressions to python, we'd have

# {"tags": {"$in": [20]}})
[20] in [20] # False

and

# {"tags": {"$eq": [20]}}
[20] == [20] # True

There are some examples of each available in the docs here

I think you might be looking for something like a $contains operator, which we don't currently support. If so, please open an issue for it

Closing this for now but please follow up if that didn't answer your question