Search with a metadata filter
The following code searches for the 3 documents that are most semantically similar to a query and that have acategory metadata field with the value digestive system.
On a document index with integrated embedding, you search with query text, and Pinecone embeds it with the model declared on the field. This example assumes a chunk_text field declared with embed.
Metadata filter expressions
Pinecone’s filtering language supports the following operators:
At the top level, list one or more fields (combined with implicit AND) or combine clauses with the logical operators
$and and $or. Use $not to negate a clause, as shown in the table. A bare comparison operator (like $gt) can’t appear at the top level. Nest it under a field.
A metadata field can hold an array of strings, such as {"genre": ["comedy", "documentary"]}. A filter on that field matches when any value in the array satisfies it, so each of these filters matches:
JSON
"drama" value and because $ne and $nin exclude an item when any of its values matches:
JSON
$in. These filters are invalid and return a 400 error:
JSON
Text-match filters
On a document index, three more operators match text instring fields that have full_text_search enabled, or that declare embed or sparse_embed without setting store_text: false. Like metadata operators, they narrow the candidates before scoring.
Text-match operators use the field’s tokenizer and stemmer, so a token that matches in BM25 scoring also matches in a filter. Filter values are literal text. Lucene syntax such as phrase slop (
"phrase"~N), term boosting (^N), and phrase prefix ("phrase pre"*) isn’t parsed. To use it, score with query_string instead.
You can combine text-match operators with metadata operators under $and, $or, and $not, at any nesting level: