Skip to main content
Documents and records can carry metadata, key-value pairs that store related information. When you search, add a metadata filter to limit results to the documents or records that match it. Document indexes also support text-match filters on full-text fields.

Search with a metadata filter

The following code searches for the 3 documents or records that are most semantically similar to a query and that have a category 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
These filters don’t match, because the array has no "drama" value and because $ne and $nin exclude an item when any of its values matches:
JSON
A filter value can’t be an array. To match several values, use $in. These filters are invalid and return a 400 error:
JSON

Text-match filters

On a document index, three more operators match text in string 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:
Text-match operators work on documents/search and documents/fetch. A filtered documents/update or documents/delete rejects them with a 400. To update or delete by text match, first search or fetch to get the matching IDs, then update or delete by ID.