Skip to main content
Pinecone is a vector database with broad functionality.
This notebook shows how to use functionality related to the Pinecone vector database.

Setup

To use the PineconeSparseVectorStore you first need to install the partner package, as well as the other packages used throughout this notebook.

Credentials

Create a new Pinecone account, or sign into your existing one, and create an API key to use in this notebook.

Initialization

Before initializing our vector store, let’s connect to a Pinecone index. If one named index_name doesn’t exist, it will be created.
For our sparse embedding model we use pinecone-sparse-english-v0, we initialize it like so:
Now that our Pinecone index and embedding model are both ready, we can initialize our sparse vector store in LangChain:

Manage vector store

Once you have created your vector store, we can interact with it by adding and deleting different items.

Add items to vector store

We can add items to our vector store by using the add_documents function.

Delete items from vector store

We can delete records from our vector store using the delete method, providing it with a list of document IDs to delete.

Query vector store

Once we have loaded our documents into the vector store we’re most likely ready to begin querying. There are various method for doing this in LangChain. First, we’ll see how to perform a simple vector search by querying our vector_store directly via the similarity_search method:
We can also add metadata filtering to our query to limit our search based on various criteria. Let’s try a simple filter to limit our search to include only records with source=="social":
When comparing these results, we can see that our first query returned a different record from the "website" source. In our latter, filtered, query—this is no longer the case.

Similarity search and scores

We can also search while returning the similarity score in a list of (document, score) tuples. Where the document is a LangChain Document object containing our text content and metadata.

As a retriever

In our chains and agents we’ll often use the vector store as a VectorStoreRetriever. To create that, we use the as_retriever method:
We can now query our retriever using the invoke method:

Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:

API reference

For detailed documentation of all features and configurations head to the API reference: