Skip to main content
For our sparse embedding model we use
Now that our Pinecone index and embedding model are both ready, we can initialize our sparse vector store in LangChain:
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
When comparing these results, we can see that our first query returned a different record from the
We can now query our retriever using the
Pinecone (Sparse) integration
Integrate with the Pinecone (Sparse) vector store using LangChain Python.
Pinecone is a vector database with broad functionality.This notebook shows how to use functionality related to the
Pinecone vector database.
Setup
To use thePineconeSparseVectorStore 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.pinecone-sparse-english-v0, we initialize it like so:
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 theadd_documents function.
Delete items from vector store
We can delete records from our vector store using thedelete 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 ourvector_store directly via the similarity_search method:
source=="social":
"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 aVectorStoreRetriever. To create that, we use the as_retriever method:
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:Connect these docs to your agent of choice via MCP for real-time answers.


