Skip to main content
This page shows you how to search an index of dense vectors for records that are most similar in meaning and context to a query. This is often called semantic search, nearest neighbor search, similarity search, or just 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 with text

Searching with text is supported only for indexes with integrated embedding.
To search an index of dense vectors with a query text, use the search_records 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, you can specify the fields to return in the response. If not specified, the response will include all fields.
For example, the following code searches for the 2 records most semantically related to a query text:
The response will look as follows. Each record is returned with a similarity score that represents its distance to the query vector, calculated according to the similarity metric for the index.

Search with a dense vector

To search an index of dense vectors with a dense vector representation of a query, use the query 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, you can set include_values and/or include_metadata to true to include the vector values and/or metadata of 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-namespaces namespace:
The response will look as follows. Each record is returned with a similarity score that represents its distance to the query vector, calculated according to the similarity metric for the index.

Search with a record ID

When you search with a record ID, Pinecone uses the dense vector associated with the record as the query. To search an index of dense vectors with a record ID, use the query 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, you can set include_values and/or include_metadata to true to include the vector values and/or metadata of 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:

Parallel queries

Python SDK v6.0.0 and later provide async methods for use with asyncio. Async support makes it possible to use Pinecone with modern async web frameworks such as FastAPI, Quart, and Sanic, and can significantly increase the efficiency of running queries in parallel. For more details, see the Async requests. Alternatively, you can run multi-threaded, synchronous queries in parallel. For example, the following code uses a thread pool to run multiple queries concurrently. This example assumes that you have a 1536-dimension serverless index called docs-example and the Pinecone Python SDK and concurrent.futures and numpy packages installed.