操作符¶
将数据摄取到 Pinecone 索引中¶
使用 PineconeIngestOperator
与 Pinecone API 交互以摄取向量。
使用操作符¶
PineconeIngestOperator 需要将 vectors
作为输入摄取到 Pinecone 中。使用 conn_id
参数指定用于连接到您的帐户的 Pinecone 连接。向量还可以包含引用与可摄取到数据库中的向量对应的原始文本的元数据。
以这种方式使用操作符的示例
tests/system/pinecone/example_dag_pinecone.py
PineconeIngestOperator(
task_id="pinecone_vector_ingest",
index_name=index_name,
input_vectors=[
("id1", [1.0, 2.0, 3.0], {"key": "value"}),
("id2", [1.0, 2.0, 3.0]),
],
namespace=namespace,
batch_size=1,
)
创建基于 Pod 的索引¶
使用 CreatePodIndexOperator
与 Pinecone API 交互以创建基于 Pod 的索引。
使用操作符¶
CreatePodIndexOperator 需要索引详情以及 Pod 配置详情。api_key
、environment
可以通过参数传递给操作符或通过连接传递。
以这种方式使用操作符的示例
tests/system/pinecone/example_create_pod_index.py
# reference: https://docs.pinecone.io/reference/api/control-plane/create_index
create_index = CreatePodIndexOperator(
task_id="pinecone_create_pod_index",
index_name=index_name,
dimension=3,
replicas=1,
shards=1,
pods=1,
pod_type="p1.x1",
)
创建 Serverless 索引¶
使用 CreateServerlessIndexOperator
与 Pinecone API 交互以创建基于 Pod 的索引。(注:原文此处可能有误,应为创建 Serverless 索引)
使用操作符¶
CreateServerlessIndexOperator 需要索引详情以及 Serverless 配置详情。api_key
、environment
可以通过参数传递给操作符或通过连接传递。
以这种方式使用操作符的示例
tests/system/pinecone/example_create_serverless_index.py
# reference: https://docs.pinecone.io/reference/api/control-plane/create_index
create_index = CreateServerlessIndexOperator(
task_id="pinecone_create_serverless_index",
index_name=index_name,
dimension=128,
cloud="aws",
region="us-west-2",
metric="cosine",
)