supabase / vecs

Postgres/pgvector Python Client

Home Page:https://supabase.github.io/vecs/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`$in` operator doesn't seem to work

jeanmaried opened this issue · comments

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:

  • PostgreSQL: 15.1
  • vecs version: 0.4.2

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