Skip to main content
Store dense and sparse vectors in two separate Pinecone indexes linked by a shared record ID, query each index, and merge the results client-side (for example, with reciprocal rank fusion). This is the Vectors API separate-index hybrid pattern. It is more flexible than a single index (it supports sparse-only queries, integrated embedding, and per-index reranking) but requires managing two indexes. To perform hybrid search with separate indexes, follow these steps:
1

Create the indexes

Create one index for dense vectors and another for sparse vectors, either with integrated embedding or for vectors created with external models.For example, the following code creates indexes with integrated embedding models.
Python
2

Upsert dense and sparse vectors

Upsert dense vectors and upsert sparse vectors into their respective indexes.Make sure to establish a linkage between the dense and sparse vectors so you can merge and deduplicate search results later. For example, the following uses _id as the linkage, but you can use any other custom field as well. Because the indexes are integrated with embedding models, you provide the source texts and Pinecone converts them to vectors automatically.
Python
Python
3

Search by dense vectors

Perform a semantic search against the index that stores dense vectors.For example, the following code searches that index for 40 records most semantically related to the query “Q3 2024 us economic data”. Because the index is integrated with an embedding model, you provide the query as text and Pinecone converts the text to a dense vector automatically.
Python
Response
4

Search by sparse vectors

Perform a sparse-vector search against the index that stores sparse vectors.For example, the following code searches that index for 40 records that most exactly match the words in the query. Again, because the index is integrated with an embedding model, you provide the query as text and Pinecone converts the text to a sparse vector automatically.
Python
Response
5

Merge and deduplicate the results

Merge the 40 dense and 40 sparse results and deduplicate them based on the field you used to link sparse and dense vectors.For example, the following code merges and deduplicates the results based on the _id field, resulting in 52 unique results.
Python
Response
6

Rerank the results

Use one of Pinecone’s hosted reranking models to rerank the merged and deduplicated results based on a unified relevance score and then return a smaller set of the most highly relevant results.For example, the following code sends the 52 unique results from the last step to the bge-reranker-v2-m3 reranking model and returns the top 10 most relevant results.
Python
Response