PineconeDocumentStore
使用 Haystack 的 Pinecone 向量数据库。
Pinecone 是一个基于云的向量数据库。它快速易用。
与其他解决方案(如 Qdrant 和 Weaviate)不同,它不能在用户的机器上本地运行,但它提供了慷慨的免费套餐。
安装
您可以通过以下方式安装 Pinecone Haystack 集成:
pip install pinecone-haystack
初始化
- 要将 Pinecone 用作 Haystack 中的 Document Store,请注册一个免费的 Pinecone 账户并获取您的 API 密钥。
Pinecone API 密钥可以显式提供,也可以从环境变量自动读取PINECONE_API_KEY(推荐)。 - 在 Haystack 中,每个
PineconeDocumentStore都在索引的特定命名空间中运行。如果未提供,则索引和命名空间均为默认.
如果索引已存在,Document Store 将连接到它。否则,它将创建一个新索引。 - 创建新索引时,您可以提供一个
spec,其形式为一个字典。这允许在无服务器和 pod 部署选项之间进行选择,并设置其他参数。有关更多详细信息,请参阅 Pinecone 文档。如果未提供,将使用无服务器部署在us-east-1区域的默认 spec(与免费套餐兼容)。 - 您可以提供
dimension和metric,但仅当 Pinecone 索引尚不存在时才会考虑它们。
然后,您可以使用 Document Store,如下所示:
from haystack import Document
from haystack_integrations.document_stores.pinecone import PineconeDocumentStore
# Make sure you have the PINECONE_API_KEY environment variable set
document_store = PineconeDocumentStore(
index="default",
namespace="default",
dimension=5,
metric="cosine",
spec={"serverless": {"region": "us-east-1", "cloud": "aws"}}
)
document_store.write_documents([
Document(content="This is first", embedding=[0.0]*5),
Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5])
])
print(document_store.count_documents())
支持的 Retrievers
PineconeEmbeddingRetriever:根据其密集嵌入(向量)从PineconeDocumentStore 中检索文档。
更新于 大约 1 年前
