Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the argument type of input_vectors in pinecone upsert #39688

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions airflow/providers/pinecone/hooks/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from functools import cached_property
from typing import TYPE_CHECKING, Any

from pinecone import Pinecone, PodSpec, ServerlessSpec
from pinecone import Pinecone, PodSpec, ServerlessSpec, Vector
sunank200 marked this conversation as resolved.
Show resolved Hide resolved

from airflow.hooks.base import BaseHook

Expand Down Expand Up @@ -137,7 +137,7 @@ def list_indexes(self) -> Any:
def upsert(
self,
index_name: str,
vectors: list[Any],
vectors: list[Vector] | list[tuple] | list[dict],
namespace: str = "",
batch_size: int | None = None,
show_progress: bool = True,
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/pinecone/operators/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import TYPE_CHECKING, Any, Sequence

from airflow.models import BaseOperator
from airflow.providers.pinecone.hooks.pinecone import PineconeHook
from airflow.providers.pinecone.hooks.pinecone import PineconeHook, Vector
sunank200 marked this conversation as resolved.
Show resolved Hide resolved
from airflow.utils.context import Context

if TYPE_CHECKING:
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(
*,
conn_id: str = PineconeHook.default_conn_name,
index_name: str,
input_vectors: list[tuple],
input_vectors: list[Vector] | list[tuple] | list[dict],
sunank200 marked this conversation as resolved.
Show resolved Hide resolved
namespace: str = "",
batch_size: int | None = None,
upsert_kwargs: dict | None = None,
Expand Down
15 changes: 9 additions & 6 deletions tests/system/providers/pinecone/example_pinecone_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import os
import time
from datetime import datetime

from airflow import DAG
Expand Down Expand Up @@ -46,19 +45,23 @@ def create_index():
hook = PineconeHook()
pod_spec = hook.get_pod_spec_obj()
hook.create_index(index_name=index_name, dimension=768, spec=pod_spec)
time.sleep(60)

embed_task = CohereEmbeddingOperator(
task_id="embed_task",
input_text=data,
)

@task
def transform_output(embedding_output) -> list[dict]:
# Convert each embedding to a map with an ID and the embedding vector
return [dict(id=str(i), values=embedding) for i, embedding in enumerate(embedding_output)]

transformed_output = transform_output(embed_task.output)

perform_ingestion = PineconeIngestOperator(
task_id="perform_ingestion",
index_name=index_name,
input_vectors=[
("id1", embed_task.output),
],
input_vectors=transformed_output,
namespace=namespace,
batch_size=1,
)
Expand All @@ -71,7 +74,7 @@ def delete_index():
hook = PineconeHook()
hook.delete_index(index_name=index_name)

create_index() >> embed_task >> perform_ingestion >> delete_index()
create_index() >> embed_task >> transformed_output >> perform_ingestion >> delete_index()

from tests.system.utils import get_test_run # noqa: E402

Expand Down