Skip to main content
Pinecone is a vector database with broad functionality.
This notebook goes over how to use a retriever that under the hood uses Pinecone and Hybrid Search. The logic of this retriever is taken from this documentation To use Pinecone, you must have an API key and an Environment. Here are the installation instructions.
We want to use OpenAIEmbeddings so we have to get the OpenAI API Key.

Setup pinecone

You should only have to do this part once.
Now that the index is created, we can use it.

Get embeddings and sparse encoders

Embeddings are used for the dense vectors, tokenizer is used for the sparse vector
To encode the text to sparse values you can either choose SPLADE or BM25. For out of domain tasks we recommend using BM25. For more information about the sparse encoders you can checkout pinecone-text library docs.
The above code is using default tfids values. It’s highly recommended to fit the tf-idf values to your own corpus. You can do it as follow:

Load retriever

We can now construct the retriever!

Add texts (if necessary)

We can optionally add texts to the retriever (if they aren’t already in there)

Use retriever

We can now use the retriever!