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 pinecone system test #39365

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion airflow/providers/pinecone/hooks/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def create_index(
:param dimension: The dimension of the vectors to be indexed.
:param spec: Pass a `ServerlessSpec` object to create a serverless index or a `PodSpec` object to create a pod index.
``get_serverless_spec_obj`` and ``get_pod_spec_obj`` can be used to create the Spec objects.
:param metric: The metric to use.
:param metric: The metric to use. Defaults to cosine.
:param timeout: The timeout to use.
"""
self.pinecone_client.create_index(
Expand Down
8 changes: 4 additions & 4 deletions airflow/providers/pinecone/operators/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class CreatePodIndexOperator(BaseOperator):
:param replicas: The number of replicas to use.
:param shards: The number of shards to use.
:param pods: The number of pods to use.
:param pod_type: The type of pod to use.
:param pod_type: The type of pod to use. Defaults to p1.x1
:param metadata_config: The metadata configuration to use.
:param source_collection: The source collection to use.
:param metric: The metric to use.
:param metric: The metric to use. Defaults to cosine.
:param timeout: The timeout to use.
"""

Expand All @@ -116,10 +116,10 @@ def __init__(
replicas: int | None = None,
shards: int | None = None,
pods: int | None = None,
pod_type: str | None = None,
pod_type: str = "p1.x1",
metadata_config: dict | None = None,
source_collection: str | None = None,
metric: str | None = None,
metric: str = "cosine",
timeout: int | None = None,
**kwargs: Any,
):
Expand Down
3 changes: 2 additions & 1 deletion tests/system/providers/pinecone/example_pinecone_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def create_index():
from airflow.providers.pinecone.hooks.pinecone import PineconeHook

hook = PineconeHook()
hook.create_index(index_name=index_name, dimension=768)
pod_spec = hook.get_pod_spec_obj()
hook.create_index(index_name=index_name, dimension=768, spec=pod_spec)
time.sleep(60)
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved

embed_task = CohereEmbeddingOperator(
Expand Down
21 changes: 8 additions & 13 deletions tests/system/providers/pinecone/example_pinecone_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
from __future__ import annotations

import os
import time
from datetime import datetime

from airflow import DAG
from airflow.decorators import setup, task, teardown
from airflow.decorators import task, teardown
from airflow.providers.openai.operators.openai import OpenAIEmbeddingOperator
from airflow.providers.pinecone.operators.pinecone import PineconeIngestOperator
from airflow.providers.pinecone.operators.pinecone import CreatePodIndexOperator, PineconeIngestOperator

index_name = os.getenv("INDEX_NAME", "example-pinecone-index")
namespace = os.getenv("NAMESPACE", "example-pinecone-index")
Expand Down Expand Up @@ -75,15 +74,11 @@
start_date=datetime(2023, 1, 1),
catchup=False,
) as dag:

@setup
@task
def create_index():
from airflow.providers.pinecone.hooks.pinecone import PineconeHook

hook = PineconeHook()
hook.create_index(index_name=index_name, dimension=1536)
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
time.sleep(60)
create_index = CreatePodIndexOperator(
task_id="create_index",
index_name=index_name,
dimension=1536,
)

embed_task = OpenAIEmbeddingOperator(
task_id="embed_task",
Expand All @@ -110,7 +105,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 >> perform_ingestion >> delete_index()

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

Expand Down