Skip to main content
Pinecone is a vector database with broad functionality.
本笔记展示如何使用与 Pinecone 向量数据库相关的功能。

设置

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

凭证

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

初始化

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:

管理向量存储

创建向量存储后,我们可以通过添加和删除不同的项目来与其交互。

向向量存储添加项目

我们可以使用 add_documents 函数向向量存储添加项目。

从向量存储删除项目

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

查询向量存储

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:

用于检索增强生成

有关如何将此向量存储用于检索增强生成 (RAG) 的指南,请参阅以下部分:

API 参考

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