Skip to main content
Semantic search finds the documents or records in an index with dense vectors that are most similar in meaning and context to a query. It’s also called nearest neighbor search, similarity search, or vector search. Semantic search uses dense vectors. Each number in a dense vector corresponds to a point in a multidimensional space. Vectors that are closer together in that space are semantically similar.

Search a document index

In a document index, you choose how to score each search with a clause in score_by. Use an embed clause to search with text, or a dense_vector clause to search with a dense vector you generate yourself.

Search with text

To search with text, the string field must declare embed, which enables integrated embedding. Pinecone embeds your query text with the field’s model. For example, this searches the chunk_text field of an index whose schema declares "chunk_text": {"type": "string", "embed": {}} and returns the 2 documents most semantically related to “Disease prevention”:

Search with a dense vector

To search a dense_vector field, pass a dense_vector clause in score_by with the query’s dense vector. Generate the query vector with the same embedding model you used at upsert. For example, this searches the embedding field of the articles-hybrid schema, so the query vector must have 1536 dimensions:

Search a vector index

In a vector index, the query is either a dense vector or the ID of a record whose vector Pinecone uses as the query.

Search with a dense vector

To search with a dense vector representation of a query, use the Search with a vector operation with the following parameters:
  • The namespace to query. To use the default namespace, set the namespace to "__default__".
  • The vector parameter with the dense vector values representing your query.
  • The top_k parameter with the number of results to return.
  • Optionally, set include_values, include_metadata, or both to true to include the vector values, metadata, or both for the matching records in the response. For better performance, especially with higher top_k values, avoid including vector values unless you need them. See Decrease latency for more details.
For example, the following code uses a dense vector representation of the query “Disease prevention” to search for the 3 most semantically similar records in the example-namespace namespace:
In the response, each record has a similarity score that represents its distance to the query vector, calculated according to the index’s similarity metric:

Search with a record ID

When you search with a record ID, Pinecone uses the dense vector associated with the record as the query. Because search is approximate, the results aren’t guaranteed to include that record, even with a high top_k. To retrieve a specific record, fetch it by ID. To search with a record ID, use the Search with a vector operation with the following parameters:
  • The namespace to query. To use the default namespace, set the namespace to "__default__".
  • The id parameter with the unique record ID containing the vector to use as the query.
  • The top_k parameter with the number of results to return.
  • Optionally, set include_values, include_metadata, or both to true to include the vector values, metadata, or both for the matching records in the response. For better performance, especially with higher top_k values, avoid including vector values unless you need them. See Decrease latency for more details.
For example, the following code uses an ID to search for the 3 records in the example-namespace namespace that are most semantically similar to the dense vector in the record:

Search a legacy integrated index

Legacy integrated indexes are created with create_index_for_model and searched through the legacy Records API. For new indexes, declare embed on a string field in a document index instead. See Integrated embedding.
To search a legacy integrated index with query text, use the Search with text operation with the following parameters:
  • The namespace to query. To use the default namespace, set the namespace to "__default__".
  • The query.inputs.text parameter with the query text. Pinecone uses the embedding model integrated with the index to convert the text to a dense vector automatically.
  • The query.top_k parameter with the number of similar records to return.
  • Optionally, the fields to return in the response. If you don’t specify any, the response includes all fields.
For example, the following code searches for the 2 records most semantically related to the query text “Disease prevention”:
In the response, each record has a similarity score that represents its distance to the query vector, calculated according to the index’s similarity metric: