π§ Using Metadata Filters
Supported metadata types
You can associate a metadata payload with each vector in an index, as key-value pairs in a JSON object where keys are strings and values are one of:
String
Number (integer or floating point, gets converted to a 64 bit floating point)
Booleans (true, false)
List of String
The metadata filters can be combined with AND and OR:
$eq- Equal to (number, string, boolean)$ne- Not equal to (number, string, boolean)$gt- Greater than (number)$gte- Greater than or equal to (number)$lt- Less than (number)$lte- Less than or equal to (number)$in- In array (string or number)$nin- Not in array (string or number)
Using arrays of strings as metadata values or as metadata filters
A vector with metadata payload...
{ "genre": ["comedy", "documentary"] }...means the "genre" takes on both values.
For example, queries with the following filters will match the vector:
{"genre":"comedy"}
{"genre": {"$in":["documentary","action"]}}
{"$and": [{"genre": "comedy"}, {"genre":"documentary"}]}Queries with the following filter will not match the vector:
{ "$and": [{ "genre": "comedy" }, { "genre": "drama" }] }And queries with the following filters will not match the vector because they are invalid. They will result in a query compilation error:
# INVALID QUERY:
{"genre": ["comedy", "documentary"]}# INVALID QUERY:
{"genre": {"$eq": ["comedy", "documentary"]}}More example filter expressions
A comedy, documentary, or drama:
{
"genre": { "$in": ["comedy", "documentary", "drama"] }
}A drama from 2020:
{
"genre": { "$eq": "drama" },
"year": { "$gte": 2020 }
}A drama from 2020 (equivalent to the previous example):
{
"$and": [{ "genre": { "$eq": "drama" } }, { "year": { "$gte": 2020 } }]
}A drama or a movie from 2020:
{
"$or": [{ "genre": { "$eq": "drama" } }, { "year": { "$gte": 2020 } }]
}Last updated