運算子

將資料攝取到 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_keyenvironment 可以透過引數傳遞給運算子或透過連線傳遞。

以這種方式使用運算子的示例

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_keyenvironment 可以透過引數傳遞給運算子或透過連線傳遞。

以這種方式使用運算子的示例

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",
)

此條目有幫助嗎?