From 371465855750df534c2f675337973992cd4210a0 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Sun, 2 Feb 2025 15:12:57 -0500 Subject: [PATCH] Add aiohttp dependency test --- .../test-dependency-asyncio-rest/action.yaml | 45 +++++++++++++++ .github/workflows/testing-dependency.yaml | 28 +++++++++ tests/dependency/asyncio-rest/test_sanity.py | 57 +++++++++++++++++++ tests/dependency/rest/test_sanity.py | 12 ++++ 4 files changed, 142 insertions(+) create mode 100644 .github/actions/test-dependency-asyncio-rest/action.yaml create mode 100644 tests/dependency/asyncio-rest/test_sanity.py diff --git a/.github/actions/test-dependency-asyncio-rest/action.yaml b/.github/actions/test-dependency-asyncio-rest/action.yaml new file mode 100644 index 00000000..312ec67a --- /dev/null +++ b/.github/actions/test-dependency-asyncio-rest/action.yaml @@ -0,0 +1,45 @@ +name: 'Test aiohttp dependencies' +description: 'Runs asyncio sanity test with specific aiohttp dependencies' + +inputs: + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + index_name: + description: 'The name of the index' + required: true + python_version: + description: 'The version of Python to use' + required: false + default: '3.9' + aiohttp_version: + description: 'The version of aiohttp to install' + required: true + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python_version }} + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry + with: + include_grpc: false + include_types: false + + - name: 'Install aiohttp ${{ matrix.aiohttp-version }}' + run: 'poetry add aiohttp==${{ matrix.aiohttp-version }}' + shell: bash + + - uses: nick-fields/retry@v3 + with: + timeout_minutes: 5 + max_attempts: 3 + retry_on: error + command: poetry run pytest tests/dependency/asyncio-rest -s -v + env: + PINECONE_API_KEY: '${{ inputs.PINECONE_API_KEY }}' + INDEX_NAME: '${{ inputs.index_name }}' diff --git a/.github/workflows/testing-dependency.yaml b/.github/workflows/testing-dependency.yaml index 9174fdca..7501993d 100644 --- a/.github/workflows/testing-dependency.yaml +++ b/.github/workflows/testing-dependency.yaml @@ -167,6 +167,33 @@ jobs: # PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' # urllib3_version: '${{ matrix.urllib3_version }}' + + dependency-matrix-asyncio-rest: + name: Deps (Asyncio REST) + runs-on: ubuntu-latest + needs: dependency-matrix-setup + strategy: + max-parallel: 10 + fail-fast: false + matrix: + python_version: + - 3.9 + - 3.10 + - 3.11 + - 3.12 + aiohttp_version: + - ^3.9.0 + - ^3.10.0 + - ^3.11.5 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/test-dependency-rest + with: + python_version: '${{ matrix.python_version }}' + index_name: '${{ needs.dependency-matrix-setup.outputs.index_name }}' + PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' + aiohttp_version: '${{ matrix.aiohttp_version }}' + # dependency-matrix-rest-312: # name: Deps (REST) # runs-on: ubuntu-latest @@ -227,6 +254,7 @@ jobs: # - dependency-matrix-rest # - dependency-matrix-rest-312 - dependency-matrix-rest-313 + - dependency-matrix-asyncio-rest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/delete-index diff --git a/tests/dependency/asyncio-rest/test_sanity.py b/tests/dependency/asyncio-rest/test_sanity.py new file mode 100644 index 00000000..b456ebaa --- /dev/null +++ b/tests/dependency/asyncio-rest/test_sanity.py @@ -0,0 +1,57 @@ +import pytest +import os +import asyncio +from pinecone import PineconeAsyncio + + +@pytest.fixture +def index_name(): + name = os.environ.get("INDEX_NAME", None) + if name is None or name == "": + raise "INDEX_NAME environment variable is not set" + return name + + +@pytest.mark.asyncio +class TestSanityRest: + async def test_sanity(self, index_name, client): + async with PineconeAsyncio() as pc: + print("Testing with index name: " + index_name) + assert index_name != "" + + # Verify index exists with expected properties + available_indexes = await pc.list_indexes() + assert index_name in available_indexes.names() + + description = await pc.describe_index(name=index_name) + assert description.dimension == 2 + + idx = pc.Index(index_name) + await idx.upsert(vectors=[("1", [1.0, 2.0]), ("2", [3.0, 4.0]), ("3", [5.0, 6.0])]) + + # Wait for index freshness + await asyncio.sleep(30) + + # Check the vector count reflects some data has been upserted + description = await idx.describe_index_stats() + assert description.dimension == 2 + assert description.total_vector_count >= 3 + + # Query for results + query_results = await idx.query(id="1", top_k=10, include_values=True) + assert query_results.matches[0].id == "1" + assert len(query_results.matches) == 3 + + # Call a bulk import api method, should not raise an exception + await idx.list_imports() + + # Call an inference method, should not raise an exception + from pinecone import EmbedModel + + await pc.inference.embed( + model=EmbedModel.Multilingual_E5_Large, + inputs=["Hello, how are you?", "I am doing well, thank you for asking."], + parameters={"input_type": "passage", "truncate": "END"}, + ) + + await idx.close() diff --git a/tests/dependency/rest/test_sanity.py b/tests/dependency/rest/test_sanity.py index e3e31bd6..dcd4ad5f 100644 --- a/tests/dependency/rest/test_sanity.py +++ b/tests/dependency/rest/test_sanity.py @@ -42,3 +42,15 @@ def test_sanity(self, index_name, client): query_results = idx.query(id="1", top_k=10, include_values=True) assert query_results.matches[0].id == "1" assert len(query_results.matches) == 3 + + # Call a bulk import api method, should not raise an exception + idx.list_imports() + + # Call an inference method, should not raise an exception + from pinecone import EmbedModel + + client.inference.embed( + model=EmbedModel.Multilingual_E5_Large, + inputs=["Hello, how are you?", "I am doing well, thank you for asking."], + parameters={"input_type": "passage", "truncate": "END"}, + )