Skip to content

Commit

Permalink
Add aiohttp dependency test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Feb 2, 2025
1 parent 86c1d15 commit 3714658
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/actions/test-dependency-asyncio-rest/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}'
28 changes: 28 additions & 0 deletions .github/workflows/testing-dependency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions tests/dependency/asyncio-rest/test_sanity.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions tests/dependency/rest/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)

0 comments on commit 3714658

Please sign in to comment.