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: