Skip to main content
Every record in an index must contain an ID and a dense or sparse vector. In addition, you can include metadata key-value pairs to store related information or context. When you search the index, you can then include a metadata filter to limit the search to records matching the filter expression. Metadata filtering works the same way on indexes with a document schema, which also support text-match filters on full-text fields.

Search with a metadata filter

The following code searches for the 3 records that are most semantically similar to a query and that have a category metadata field with the value digestive system.
Searching with text is supported only for indexes with integrated embedding.

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.
Each $in or $nin operator accepts a maximum of 10,000 values. Exceeding this limit will cause the request to fail. For more information, see Metadata filter limits.
For example, the following has a "genre" metadata field with a list of strings:
JSON
This means "genre" takes on both values, and requests with the following filters will match:
JSON
However, requests with the following filter will not match:
JSON
Additionally, requests with the following filters will not match because they are invalid. They will result in a compilation error:
JSON
JSON

Text-match filters

On indexes with a document schema, three additional operators match text on string fields that have full_text_search enabled. They narrow the candidate set before scoring, the same way metadata operators do. These operators share a few rules:
  • Where they apply. Fields declared with a full_text_search config object.
  • Tokenization. They reuse the field’s configured tokenizer and stemmer, so a token that matches in BM25 scoring will match in a text-match filter.
  • Lucene-style operators. Phrase slop ("phrase"~N), term boosting (^N), and phrase prefix ("phrase pre"*) are not parsed. Values are literal text and match semantics come from the operator name. To use those operators, score with query_string instead.
  • Composition. They compose freely with metadata operators under $and, $or, and $not at any nesting level:
Text-match operators ($match_phrase, $match_all, $match_any) are only valid on POST /namespaces/{namespace}/documents/search. Plain metadata filters, though, are also accepted by documents/fetch, documents/update, and documents/delete, so you can fetch, update, or delete documents matching a metadata expression directly. To act on text-match results elsewhere, search to retrieve matching IDs first.