diff --git a/.github/actions/create-collection-legacy/action.yml b/.github/actions/create-collection-legacy/action.yml new file mode 100644 index 000000000..172ad677a --- /dev/null +++ b/.github/actions/create-collection-legacy/action.yml @@ -0,0 +1,49 @@ +name: 'Create Collection (Legacy / Regional Control Plane)' +description: 'Creates a collection to be used in other tests' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: false + default: '2.2.4' + collection_name_prefix: + description: 'The prefix for collection names' + required: true + index_name: + description: 'The name of the index to make the collection from' + required: true + PINECONE_ENVIRONMENT: + description: 'The environment of the collection' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +outputs: + collection_name: + description: 'The name of the collection, including randomized suffix' + value: ${{ steps.create-collection.outputs.collection_name }} + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Create collection + id: create-collection + shell: bash + run: python3 scripts/2.x/create-collection-legacy.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} + COLLECTION_NAME_PREFIX: ${{ inputs.collection_name_prefix }} + INDEX_NAME: ${{ inputs.index_name }} + diff --git a/.github/actions/create-index-from-collection/action.yml b/.github/actions/create-index-from-collection/action.yml new file mode 100644 index 000000000..0190a2a8b --- /dev/null +++ b/.github/actions/create-index-from-collection/action.yml @@ -0,0 +1,58 @@ +name: 'Create Index from Collection' +description: 'Creates a pod index from a collection' + +inputs: + index_name_prefix: + description: 'The prefix of the index name' + required: false + default: 'index-name' + collection_name: + description: 'The name of the collection to make the index from' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + PINECONE_ENVIRONMENT: + description: 'The environment of the collection' + required: true + dimension: + description: 'The dimension of the index' + required: false + default: '3' + metric: + description: 'The metric of the index' + required: false + default: 'cosine' + expected_vector_count: + description: 'The expected number of vectors in the index' + required: false + +outputs: + index_name: + description: 'The name of the index, including randomized suffix' + value: ${{ steps.create-index.outputs.index_name }} + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry + + - name: Create index + id: create-index + shell: bash + run: poetry run python3 scripts/3.x/create-pod-index-from-collection.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} + INDEX_NAME_PREFIX: ${{ inputs.index_name_prefix }} + COLLECTION_NAME: ${{ inputs.collection_name }} + DIMENSION: ${{ inputs.dimension }} + METRIC: ${{ inputs.metric }} + EXPECTED_VECTOR_COUNT: ${{ inputs.expected_vector_count }} + diff --git a/.github/actions/create-index-legacy/action.yml b/.github/actions/create-index-legacy/action.yml index 2b99094f9..587efc1b9 100644 --- a/.github/actions/create-index-legacy/action.yml +++ b/.github/actions/create-index-legacy/action.yml @@ -6,8 +6,8 @@ inputs: description: 'The version of the Pinecone client to use' required: false default: '2.2.4' - index_name: - description: 'The name of the index' + index_name_prefix: + description: 'The prefix for index names' required: true dimension: description: 'The dimension of the index' @@ -17,6 +17,10 @@ inputs: description: 'The metric of the index' required: false default: 'cosine' + vectors_to_upsert: + description: 'The number of vectors to upsert' + required: false + default: '1000' PINECONE_ENVIRONMENT: description: 'The environment of the index' required: true @@ -24,6 +28,11 @@ inputs: description: 'The Pinecone API key' required: true +outputs: + index_name: + description: 'The name of the index, including randomized suffix' + value: ${{ steps.create-index.outputs.index_name }} + runs: using: 'composite' steps: @@ -40,10 +49,12 @@ runs: - name: Create index id: create-index shell: bash - run: ./python3 scripts/create-index-legacy.py + run: python3 scripts/2.x/create-index-legacy.py env: PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} - INDEX_NAME: ${{ inputs.index_name }} + INDEX_NAME_PREFIX: ${{ inputs.index_name_prefix }} DIMENSION: ${{ inputs.dimension }} - METRIC: ${{ inputs.metric } + METRIC: ${{ inputs.metric }} + VECTORS_TO_UPSERT: ${{ inputs.vectors_to_upsert }} + diff --git a/.github/actions/create-index-pod/action.yml b/.github/actions/create-index-pod/action.yml new file mode 100644 index 000000000..97f7521cd --- /dev/null +++ b/.github/actions/create-index-pod/action.yml @@ -0,0 +1,60 @@ +name: 'Create Pod Index via GCPS' +description: 'Creates an index to be used in other tests' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: false + default: '3.0.0.dev10' + index_name_prefix: + description: 'The prefix for index names' + required: true + dimension: + description: 'The dimension of the index' + required: false + default: '1536' + metric: + description: 'The metric of the index' + required: false + default: 'cosine' + vectors_to_upsert: + description: 'The number of vectors to upsert' + required: false + default: '1000' + PINECONE_ENVIRONMENT: + description: 'The environment of the index' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +outputs: + index_name: + description: 'The name of the index, including randomized suffix' + value: ${{ steps.create-index.outputs.index_name }} + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Create index + id: create-index + shell: bash + run: python3 scripts/3.x/create-pod-index.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} + INDEX_NAME_PREFIX: ${{ inputs.index_name_prefix }} + DIMENSION: ${{ inputs.dimension }} + METRIC: ${{ inputs.metric }} + VECTORS_TO_UPSERT: ${{ inputs.vectors_to_upsert }} + diff --git a/.github/actions/delete-all-collections/action.yml b/.github/actions/delete-all-collections/action.yml new file mode 100644 index 000000000..39439feed --- /dev/null +++ b/.github/actions/delete-all-collections/action.yml @@ -0,0 +1,31 @@ +name: 'Delete all collections owned by API key' +description: 'Delete all collections owned by API key' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Delete all collections + id: delete-collections + shell: bash + run: python3 scripts/3.x/delete-all-collections.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + diff --git a/.github/actions/delete-all-indexes/action.yml b/.github/actions/delete-all-indexes/action.yml new file mode 100644 index 000000000..d2bf50e31 --- /dev/null +++ b/.github/actions/delete-all-indexes/action.yml @@ -0,0 +1,32 @@ +name: 'Delete all indexes owned by API key' +description: 'Delete all indexes owned by API key' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: false + default: '3.0.0.dev9' + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Delete all indexes + id: delete-indexes + shell: bash + run: python3 scripts/3.x/delete-all-indexes.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + diff --git a/.github/actions/delete-collection/action.yml b/.github/actions/delete-collection/action.yml new file mode 100644 index 000000000..4647639e0 --- /dev/null +++ b/.github/actions/delete-collection/action.yml @@ -0,0 +1,19 @@ +name: 'Delete Collection' +description: 'Deletes a collection' + +inputs: + collection_name: + description: 'The name of the collection to delete' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + + +runs: + using: 'composite' + steps: + - name: Delete collection + shell: bash + run: | + curl -X DELETE "https://api.pinecone.io/collections/${{ inputs.collection_name }}" -H "Api-Key: ${{ inputs.PINECONE_API_KEY }}" diff --git a/.github/actions/test-collection/action.yml b/.github/actions/test-collection/action.yml new file mode 100644 index 000000000..a8a96e408 --- /dev/null +++ b/.github/actions/test-collection/action.yml @@ -0,0 +1,39 @@ +name: 'Test legacy collection on GCPS' +description: 'Uses new client to interact with collection created via legacy client' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: true + collection_name: + description: 'The name of the collection' + required: true + PINECONE_ENVIRONMENT: + description: 'The environment of the index' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Test collection + id: test-collection + shell: bash + run: python3 scripts/3.x/test-collection.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} + COLLECTION_NAME: ${{ inputs.collection_name }} + VECTORS_TO_UPSERT: ${{ inputs.vectors_to_upsert }} diff --git a/.github/actions/test-legacy-index/action.yml b/.github/actions/test-legacy-index/action.yml new file mode 100644 index 000000000..4258d6e67 --- /dev/null +++ b/.github/actions/test-legacy-index/action.yml @@ -0,0 +1,44 @@ +name: 'Test legacy index on GCPS' +description: 'Uses new client to interact with index created via legacy client' + +inputs: + pinecone_client_version: + description: 'The version of the Pinecone client to use' + required: true + index_name: + description: 'The name of the index' + required: true + PINECONE_ENVIRONMENT: + description: 'The environment of the index' + required: true + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + vectors_to_upsert: + description: 'The number of vectors to upsert' + required: false + default: '1000' + + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install pinecone-client + shell: bash + run: | + pip install pinecone-client==${{ inputs.pinecone_client_version }} + + - name: Create index + id: create-index + shell: bash + run: python3 scripts/3.x/test-index.py + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + PINECONE_ENVIRONMENT: ${{ inputs.PINECONE_ENVIRONMENT }} + INDEX_NAME: ${{ inputs.index_name }} + VECTORS_TO_UPSERT: ${{ inputs.vectors_to_upsert }} diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml index 394ed3154..4e7953043 100644 --- a/.github/workflows/merge.yaml +++ b/.github/workflows/merge.yaml @@ -18,15 +18,15 @@ jobs: with: python-version: 3.11 - - name: Push documentation artifacts to sdk-docs - uses: cpina/github-action-push-to-another-repository@main - env: - SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} - with: - source-directory: docs - destination-github-username: pinecone-io - destination-repository-name: sdk-docs - user-email: clients@pinecone.io - target-branch: main - target-directory: python - commit-message: 'Python: automated documentation build - pinecone-python-client merge SHA: ${{ github.sha }}' + # - name: Push documentation artifacts to sdk-docs + # uses: cpina/github-action-push-to-another-repository@main + # env: + # SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} + # with: + # source-directory: docs + # destination-github-username: pinecone-io + # destination-repository-name: sdk-docs + # user-email: clients@pinecone.io + # target-branch: main + # target-directory: python + # commit-message: 'Python: automated documentation build - pinecone-python-client merge SHA: ${{ github.sha }}' diff --git a/.github/workflows/migration-paths.yaml b/.github/workflows/migration-paths.yaml deleted file mode 100644 index 34def16d3..000000000 --- a/.github/workflows/migration-paths.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: 'Migration testing' - -on: - workflow_dispatch: {} - - -jobs: - create-index-legacy-paid: - name: Create index - runs-on: ubuntu-latest - strategy: - max-parallel: 1 - matrix: - env: - - asia-southeast1-gcp - # - asia-northeast1-gcp - # - eu-west1-gcp - # - eu-west4-gcp - # - northamerica-northeast1-gcp - # - us-central1-gcp - # - us-east1-gcp - # - us-east4-gcp - # - us-west1-gcp - # - us-west4-gcp - # - eastus-azure - # - us-east-1-aws - - # - gcp-starter - # - asia-southeast1-gcp-free - # - us-west1-gcp-free - # - us-west4-gcp-free - - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Create on legacy control plane - id: create-legacy - uses: ./.github/actions/create-index-legacy - with: - PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} - PINECONE_ENVIRONMENT: ${{ matrix.env }} - pinecone_client_version: 2.2.4 - index_name: migration-testing-index - dimension: 1536 - metric: cosine \ No newline at end of file diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 8742622d5..828f12542 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -8,31 +8,86 @@ on: workflow_dispatch: {} jobs: - unit-tests: - uses: './.github/workflows/testing-unit.yaml' - secrets: inherit - integration-tests: - uses: './.github/workflows/testing-integration.yaml' - secrets: inherit - dependency-tests: - uses: './.github/workflows/testing-dependency.yaml' - secrets: inherit - package: - name: Check packaging - runs-on: ubuntu-latest + migration-tests: strategy: + fail-fast: false matrix: - python-version: [3.8, 3.9, '3.10', 3.11] + test-env: + - asia-southeast1-gcp + - asia-northeast1-gcp + - eu-west1-gcp + - eu-west4-gcp + - northamerica-northeast1-gcp + - us-central1-gcp + - us-east1-gcp + - us-east4-gcp + - us-west1-gcp + - us-west4-gcp + # - eastus-azure + - us-east-1-aws + + # - gcp-starter + # - asia-southeast1-gcp-free + # - us-west1-gcp-free + # - us-west4-gcp-free + + + uses: './.github/workflows/testing-migration.yaml' + secrets: inherit + with: + environment: ${{ matrix.test-env }} + + cleanup-indexes: + if: always() + needs: [migration-tests] + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + - name: Checkout + uses: actions/checkout@v4 + - name: Delete all indexes + uses: ./.github/actions/delete-all-indexes with: - python-version: ${{ matrix.python-version }} - - name: Setup Poetry - uses: ./.github/actions/setup-poetry - - name: Package - run: poetry build + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + pinecone_client_version: 3.0.0.dev10 + + # cleanup-collections: + # if: always() + # needs: [migration-tests] + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - name: Delete all collections + # uses: ./.github/actions/delete-all-collections + # with: + # PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + # pinecone_client_version: 3.0.0.dev10 + + # unit-tests: + # uses: './.github/workflows/testing-unit.yaml' + # secrets: inherit + # integration-tests: + # uses: './.github/workflows/testing-integration.yaml' + # secrets: inherit + # dependency-tests: + # uses: './.github/workflows/testing-dependency.yaml' + # secrets: inherit + # package: + # name: Check packaging + # runs-on: ubuntu-latest + # strategy: + # matrix: + # python-version: [3.8, 3.9, '3.10', 3.11] + # steps: + # - uses: actions/checkout@v4 + # - name: Set up Python ${{ matrix.python-version }} + # uses: actions/setup-python@v4 + # with: + # python-version: ${{ matrix.python-version }} + # - name: Setup Poetry + # uses: ./.github/actions/setup-poetry + # - name: Package + # run: poetry build build-docs: name: Build docs with pdoc diff --git a/.github/workflows/testing-dependency.yaml b/.github/workflows/testing-dependency.yaml index 05ccd7423..ba5a248c9 100644 --- a/.github/workflows/testing-dependency.yaml +++ b/.github/workflows/testing-dependency.yaml @@ -1,4 +1,4 @@ -name: Dependency Testing +name: 'Dependency Tests' on: workflow_call: {} diff --git a/.github/workflows/testing-integration.yaml b/.github/workflows/testing-integration.yaml index e2b0631d3..4119e3bb3 100644 --- a/.github/workflows/testing-integration.yaml +++ b/.github/workflows/testing-integration.yaml @@ -1,4 +1,4 @@ -name: "Integration Tests" +name: 'Integration Tests' 'on': workflow_call: {} diff --git a/.github/workflows/testing-migration.yaml b/.github/workflows/testing-migration.yaml new file mode 100644 index 000000000..af922db4e --- /dev/null +++ b/.github/workflows/testing-migration.yaml @@ -0,0 +1,144 @@ +name: 'Migration Tests' + +on: + workflow_dispatch: {} + workflow_call: + inputs: + environment: + description: 'Environment to test' + required: true + type: string + +env: + NUM_VECTORS: 1000 + DIMENSION: 1536 + METRIC: cosine + LEGACY_CLIENT_VERSION: 2.2.4 + NEW_CLIENT_VERSION: 3.0.0.dev10 + +jobs: + create-index: + name: Create index + runs-on: ubuntu-latest + outputs: + index_name: ${{ steps.create-legacy.outputs.index_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create index and upsert (legacy) + id: create-legacy + uses: ./.github/actions/create-index-legacy + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.LEGACY_CLIENT_VERSION }} + index_name_prefix: py-migration + dimension: ${{ env.DIMENSION }} + metric: ${{ env.METRIC }} + vectors_to_upsert: ${{ ENV.NUM_VECTORS }} + + test-index-gcps: + needs: [create-index] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test index (GCPS) + id: inspect-gcps + uses: ./.github/actions/test-legacy-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + index_name: ${{ needs.create-index.outputs.index_name }} + + create-collection: + needs: [create-index] + runs-on: ubuntu-latest + outputs: + collection_name: ${{ steps.create-collection-legacy.outputs.collection_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create collection (legacy) + id: create-collection-legacy + uses: ./.github/actions/create-collection-legacy + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.LEGACY_CLIENT_VERSION }} + collection_name_prefix: py-coll + index_name: ${{ needs.create-index.outputs.index_name }} + + test-collection-new: + needs: [create-collection] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Inspect collection (new) + id: inspect-collection-new + uses: ./.github/actions/test-collection + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + collection_name: ${{ needs.create-collection.outputs.collection_name }} + + cleanup-first-index: + if: always() + needs: [test-index-gcps, create-index, create-collection] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Delete all indexes + uses: ./.github/actions/delete-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + index_name: ${{ needs.create-index.outputs.index_name }} + + create-index-from-collection-new: + needs: [create-collection] + runs-on: ubuntu-latest + outputs: + index_name: ${{ steps.create-index-from-collection.outputs.index_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create index from collection + id: create-index-from-collection + uses: ./.github/actions/create-index-from-collection + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + index_name_prefix: py-migration + collection_name: ${{ needs.create-collection.outputs.collection_name }} + expected_vector_count: ${{ env.NUM_VECTORS }} + + cleanup-second-index: + if: always() + needs: [create-index-from-collection-new] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Delete all indexes + uses: ./.github/actions/delete-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + index_name: ${{ needs.create-index-from-collection-new.outputs.index_name }} + + # cleanup-collection: + # if: always() + # needs: [test-collection-new, create-collection, create-index-from-collection-new] + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - name: Delete collection + # uses: ./.github/actions/delete-collection + # with: + # PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + # collection_name: ${{ needs.create-collection.outputs.collection_name }} diff --git a/.github/workflows/testing-reverse-migration.yml b/.github/workflows/testing-reverse-migration.yml new file mode 100644 index 000000000..d00b8c440 --- /dev/null +++ b/.github/workflows/testing-reverse-migration.yml @@ -0,0 +1,144 @@ +name: 'Migration Tests' + +on: + workflow_dispatch: {} + workflow_call: + inputs: + environment: + description: 'Environment to test' + required: true + type: string + +env: + NUM_VECTORS: 1000 + DIMENSION: 1536 + METRIC: cosine + LEGACY_CLIENT_VERSION: 2.2.4 + NEW_CLIENT_VERSION: 3.0.0.dev10 + +jobs: + create-index: + name: Create index + runs-on: ubuntu-latest + outputs: + index_name: ${{ steps.create-legacy.outputs.index_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create index and upsert (legacy) + id: create-legacy + uses: ./.github/actions/create-index-legacy + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.LEGACY_CLIENT_VERSION }} + index_name_prefix: py-migration + dimension: ${{ env.DIMENSION }} + metric: ${{ env.METRIC }} + vectors_to_upsert: ${{ ENV.NUM_VECTORS }} + + test-index-gcps: + needs: [create-index] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test index (GCPS) + id: inspect-gcps + uses: ./.github/actions/test-legacy-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + index_name: ${{ needs.create-index.outputs.index_name }} + + create-collection: + needs: [create-index] + runs-on: ubuntu-latest + outputs: + collection_name: ${{ steps.create-collection-legacy.outputs.collection_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create collection (legacy) + id: create-collection-legacy + uses: ./.github/actions/create-collection-legacy + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.LEGACY_CLIENT_VERSION }} + collection_name_prefix: py-coll + index_name: ${{ needs.create-index.outputs.index_name }} + + test-collection-new: + needs: [create-collection] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Inspect collection (new) + id: inspect-collection-new + uses: ./.github/actions/test-collection + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + collection_name: ${{ needs.create-collection.outputs.collection_name }} + + cleanup-first-index: + if: always() + needs: [test-index-gcps, create-index, create-collection] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Delete all indexes + uses: ./.github/actions/delete-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + index_name: ${{ needs.create-index.outputs.index_name }} + + create-index-from-collection-new: + needs: [create-collection] + runs-on: ubuntu-latest + outputs: + index_name: ${{ steps.create-index-from-collection.outputs.index_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create index from collection + id: create-index-from-collection + uses: ./.github/actions/create-index-from-collection + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + PINECONE_ENVIRONMENT: ${{ inputs.environment }} + pinecone_client_version: ${{ env.NEW_CLIENT_VERSION }} + index_name_prefix: py-migration + collection_name: ${{ needs.create-collection.outputs.collection_name }} + expected_vector_count: ${{ env.NUM_VECTORS }} + + cleanup-second-index: + if: always() + needs: [create-index-from-collection-new] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Delete all indexes + uses: ./.github/actions/delete-index + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + index_name: ${{ needs.create-index-from-collection-new.outputs.index_name }} + + cleanup-collection: + if: always() + needs: [test-collection-new, create-collection, create-index-from-collection-new] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Delete collection + uses: ./.github/actions/delete-collection + with: + PINECONE_API_KEY: ${{ secrets.V3MIGRATION_API_KEY__ONE_KEY_MANY_ENVS }} + collection_name: ${{ needs.create-collection.outputs.collection_name }} diff --git a/.github/workflows/testing-unit.yaml b/.github/workflows/testing-unit.yaml index f8026409c..7ea420016 100644 --- a/.github/workflows/testing-unit.yaml +++ b/.github/workflows/testing-unit.yaml @@ -1,4 +1,4 @@ -name: "Unit Tests" +name: 'Unit Tests' 'on': workflow_call: {} diff --git a/README.md b/README.md index 01e4bbb1a..bc9d90710 100644 --- a/README.md +++ b/README.md @@ -28,36 +28,20 @@ pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git@e pip3 install git+https://git@github.com/pinecone-io/pinecone-python-client.git@259deff ``` -## Create a client -The following example creates an authenticated client. - -```python -import os -from pinecone import Pinecone - -pc = Pinecone(api_key=os.environ.get('PINECONE_API_KEY')) -``` -To use gRPC for interacting with an index, instantiate with `PineconeGRPC` -```python -import os -from pinecone.grpc import PineconeGRPC - -pc = PineconeGRPC(api_key=os.environ.get('PINECONE_API_KEY')) -# Functionality matches non-gRPC client -index = pc.Index('index-name') -``` - -## Create an index +## Creating an index The following example creates an index without a metadata configuration. By default, Pinecone indexes all metadata. ```python -from pinecone import Pinecone, PodSpec -pc = Pinecone(api_key='<>') -pc.create_index("example-index", dimension=1536, metric="cosine", spec=PodSpec(environment='us-west-2', pod_type='p1.x1')) +import pinecone + +pinecone.init(api_key="YOUR_API_KEY", + environment="us-west1-gcp") + +pinecone.create_index("example-index", dimension=1024) ``` The following example creates an index that only indexes @@ -65,18 +49,12 @@ the "color" metadata field. Queries against this index cannot filter based on any other metadata field. ```python -from pinecone import Pinecone, PodSpec -pc = Pinecone(api_key='<>') - metadata_config = { "indexed": ["color"] } -pc.create_index( - "example-index-2", - dimension=1536, - spec=PodSpec(environment='us-west-2', pod_type='p1.x1', metadata_config=metadata_config) -) +pinecone.create_index("example-index-2", dimension=1024, + metadata_config=metadata_config) ``` ## List indexes @@ -84,11 +62,11 @@ pc.create_index( The following example returns all indexes in your project. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -for index in pc.list_indexes(): - print(index['name']) +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") + +active_indexes = pinecone.list_indexes() ``` ## Describe index @@ -96,11 +74,12 @@ for index in pc.list_indexes(): The following example returns information about the index `example-index`. ```python -from pinecone import Pinecone +import pinecone + +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") -pc = Pinecone(api_key='<>') +index_description = pinecone.describe_index("example-index") -index_description = pc.describe_index("example-index") ``` ## Delete an index @@ -108,11 +87,11 @@ index_description = pc.describe_index("example-index") The following example deletes `example-index`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") -pc.delete_index("example-index") +pinecone.delete_index("example-index") ``` ## Scale replicas @@ -120,12 +99,12 @@ pc.delete_index("example-index") The following example changes the number of replicas for `example-index`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") new_number_of_replicas = 4 -pc.configure_index("example-index", replicas=new_number_of_replicas) +pinecone.configure_index("example-index", replicas=new_number_of_replicas) ``` ## Describe index statistics @@ -133,10 +112,10 @@ pc.configure_index("example-index", replicas=new_number_of_replicas) The following example returns statistics about the index `example-index`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") index_stats_response = index.describe_index_stats() ``` @@ -147,10 +126,10 @@ index_stats_response = index.describe_index_stats() The following example upserts vectors to `example-index`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") upsert_response = index.upsert( vectors=[ @@ -167,10 +146,10 @@ The following example queries the index `example-index` with metadata filtering. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") query_response = index.query( namespace="example-namespace", @@ -189,10 +168,10 @@ query_response = index.query( The following example deletes vectors by ID. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") delete_response = index.delete(ids=["vec1", "vec2"], namespace="example-namespace") ``` @@ -202,23 +181,24 @@ delete_response = index.delete(ids=["vec1", "vec2"], namespace="example-namespac The following example fetches vectors by ID. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") fetch_response = index.fetch(ids=["vec1", "vec2"], namespace="example-namespace") ``` + ## Update vectors The following example updates vectors by ID. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') -index = pc.Index("example-index") +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") +index = pinecone.Index("example-index") update_response = index.update( id="vec1", @@ -234,11 +214,12 @@ The following example creates the collection `example-collection` from `example-index`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", + environment="us-west1-gcp") -pc.create_collection("example-collection", "example-index") +pinecone.create_collection("example-collection", "example-index") ``` ## List collections @@ -246,11 +227,11 @@ pc.create_collection("example-collection", "example-index") The following example returns a list of the collections in the current project. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") -active_collections = pc.list_collections() +active_collections = pinecone.list_collections() ``` ## Describe a collection @@ -259,11 +240,11 @@ The following example returns a description of the collection `example-collection`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") -collection_description = pc.describe_collection("example-collection") +collection_description = pinecone.describe_collection("example-collection") ``` ## Delete a collection @@ -271,11 +252,11 @@ collection_description = pc.describe_collection("example-collection") The following example deletes the collection `example-collection`. ```python -from pinecone import Pinecone +import pinecone -pc = Pinecone(api_key='<>') +pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp") -pc.delete_collection("example-collection") +pinecone.delete_collection("example-collection") ``` # Contributing diff --git a/pinecone/core/client/model/collection_model.py b/pinecone/core/client/model/collection_model.py index 4e9d54280..42992a404 100644 --- a/pinecone/core/client/model/collection_model.py +++ b/pinecone/core/client/model/collection_model.py @@ -91,10 +91,10 @@ def openapi_types(): """ return { 'name': (str,), # noqa: E501 - 'size': (int,), # noqa: E501 'status': (str,), # noqa: E501 + 'size': (int,), # noqa: E501 'dimension': (int,), # noqa: E501 - 'record_count': (int,), # noqa: E501 + 'vector_count': (int,), # noqa: E501 'environment': (str,), # noqa: E501 } @@ -105,10 +105,10 @@ def discriminator(): attribute_map = { 'name': 'name', # noqa: E501 - 'size': 'size', # noqa: E501 'status': 'status', # noqa: E501 + 'size': 'size', # noqa: E501 'dimension': 'dimension', # noqa: E501 - 'record_count': 'record_count', # noqa: E501 + 'vector_count': 'vector_count', # noqa: E501 'environment': 'environment', # noqa: E501 } @@ -119,15 +119,12 @@ def discriminator(): @classmethod @convert_js_args_to_python_args - def _from_openapi_data(cls, name, size, status, dimension, record_count, *args, **kwargs): # noqa: E501 + def _from_openapi_data(cls, name, status, *args, **kwargs): # noqa: E501 """CollectionModel - a model defined in OpenAPI Args: name (str): - size (int): The size of the collection in bytes. status (str): The status of the collection. - dimension (int): The dimension of the vectors stored in each record held in the collection - record_count (int): The number of records stored in the collection Keyword Args: _check_type (bool): if True, values for parameters in openapi_types @@ -160,6 +157,9 @@ def _from_openapi_data(cls, name, size, status, dimension, record_count, *args, Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) + size (int): The size of the collection in bytes.. [optional] # noqa: E501 + dimension (int): The dimension of the vectors stored in each record held in the collection. [optional] # noqa: E501 + vector_count (int): The number of records stored in the collection. [optional] # noqa: E501 environment (str): The environment where the collection is hosted.. [optional] # noqa: E501 """ @@ -189,10 +189,7 @@ def _from_openapi_data(cls, name, size, status, dimension, record_count, *args, self._visited_composed_classes = _visited_composed_classes + (self.__class__,) self.name = name - self.size = size self.status = status - self.dimension = dimension - self.record_count = record_count for var_name, var_value in kwargs.items(): if var_name not in self.attribute_map and \ self._configuration is not None and \ @@ -213,15 +210,12 @@ def _from_openapi_data(cls, name, size, status, dimension, record_count, *args, ]) @convert_js_args_to_python_args - def __init__(self, name, size, status, dimension, record_count, *args, **kwargs): # noqa: E501 + def __init__(self, name, status, *args, **kwargs): # noqa: E501 """CollectionModel - a model defined in OpenAPI Args: name (str): - size (int): The size of the collection in bytes. status (str): The status of the collection. - dimension (int): The dimension of the vectors stored in each record held in the collection - record_count (int): The number of records stored in the collection Keyword Args: _check_type (bool): if True, values for parameters in openapi_types @@ -254,6 +248,9 @@ def __init__(self, name, size, status, dimension, record_count, *args, **kwargs) Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) + size (int): The size of the collection in bytes.. [optional] # noqa: E501 + dimension (int): The dimension of the vectors stored in each record held in the collection. [optional] # noqa: E501 + vector_count (int): The number of records stored in the collection. [optional] # noqa: E501 environment (str): The environment where the collection is hosted.. [optional] # noqa: E501 """ @@ -281,10 +278,7 @@ def __init__(self, name, size, status, dimension, record_count, *args, **kwargs) self._visited_composed_classes = _visited_composed_classes + (self.__class__,) self.name = name - self.size = size self.status = status - self.dimension = dimension - self.record_count = record_count for var_name, var_value in kwargs.items(): if var_name not in self.attribute_map and \ self._configuration is not None and \ diff --git a/pinecone/models/collection_list.py b/pinecone/models/collection_list.py index 64df1e57a..40fd88156 100644 --- a/pinecone/models/collection_list.py +++ b/pinecone/models/collection_list.py @@ -5,6 +5,9 @@ def __init__(self, collection_list: OpenAPICollectionList): self.collection_list = collection_list self.current = 0 + def names(self): + return [i['name'] for i in self.collection_list.collections] + def __getitem__(self, key): return self.collection_list.collections[key] diff --git a/poetry.lock b/poetry.lock index 86aabad9c..23efb4e9e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -35,13 +35,13 @@ tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pyte [[package]] name = "certifi" -version = "2023.7.22" +version = "2023.11.17" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2023.7.22-py3-none-any.whl", hash = "sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"}, - {file = "certifi-2023.7.22.tar.gz", hash = "sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082"}, + {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, + {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, ] [[package]] @@ -1198,4 +1198,4 @@ grpc = ["googleapis-common-protos", "grpc-gateway-protoc-gen-openapiv2", "grpcio [metadata] lock-version = "2.0" python-versions = ">=3.8,<3.13" -content-hash = "9b463283ead14a000789fdc1d8ef0797759103b326dea21a2ae07083011ba2ad" +content-hash = "8c61e1d38e8f8a0e1bc3f770033707f04ccccbc5af91d6ec4972ab7b27127987" diff --git a/pyproject.toml b/pyproject.toml index d78660adb..06dcbc602 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,10 @@ python = ">=3.8,<3.13" typing-extensions = ">=3.7.4" urllib3 = ">=1.26.0" tqdm = ">=4.64.1" +# certifi does not follow semver. Should always be +# on latest but setting a broad range to have maximum +# compatibility with libraries that may pin version. +certifi = ">=2019.11.17" grpcio = { version = ">=1.44.0", optional = true } grpc-gateway-protoc-gen-openapiv2 = { version = "0.1.0", optional = true } googleapis-common-protos = { version = ">=1.53.0", optional = true } diff --git a/scripts/2.x/create-collection-legacy.py b/scripts/2.x/create-collection-legacy.py new file mode 100644 index 000000000..6b5af5984 --- /dev/null +++ b/scripts/2.x/create-collection-legacy.py @@ -0,0 +1,69 @@ +import random +import string +import os +import pinecone +import time +import math + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise Exception('Environment variable {} is not set'.format(name)) + return value + +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + +def write_gh_output(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: + print(f'{name}={value}', file=fh) + +def main(): + api_key = read_env_var('PINECONE_API_KEY') + environment = read_env_var('PINECONE_ENVIRONMENT') + collection_name_prefix = read_env_var('COLLECTION_NAME_PREFIX') + index_name = read_env_var('INDEX_NAME') + + print(f'Beginning test with environment {environment} and index {index_name}') + + pinecone.init( + api_key=api_key, + environment=environment + ) + + if index_name not in pinecone.list_indexes(): + raise Exception(f'Index {index_name} does not exist. Cannot create collection.') + + collection_name = collection_name_prefix + '-' + random_string(10) + write_gh_output('collection_name', collection_name) + print(f'Creating collection {collection_name}...') + + pinecone.create_collection( + name=collection_name, + source=index_name + ) + + print(f'Waiting for collection {collection_name} to be ready...') + collection_ready = False + max_wait = 10*60 + waited = 0 + while not collection_ready and waited <= max_wait: + try: + waited += 10 + collection_description = pinecone.describe_collection(collection_name) + print(f'Collection description: {collection_description}') + if collection_description.status == 'Ready': + collection_ready = True + else: + print(f'Collection {collection_name} not after {waited} seconds. Waiting...') + except Exception as e: + print(f'Error while polling for collection {collection_name} status: {e}') + time.sleep(10) + + if not collection_ready: + raise Exception(f'Collection {collection_name} not ready after waiting for {max_wait} seconds.') + else: + print(f'Collection {collection_name} ready after waiting for {waited} seconds.') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/create-index-legacy.py b/scripts/2.x/create-index-legacy.py similarity index 50% rename from scripts/create-index-legacy.py rename to scripts/2.x/create-index-legacy.py index 2a98025e7..25c3eab64 100644 --- a/scripts/create-index-legacy.py +++ b/scripts/2.x/create-index-legacy.py @@ -3,6 +3,7 @@ import os import pinecone import time +import math def read_env_var(name): value = os.environ.get(name) @@ -10,18 +11,26 @@ def read_env_var(name): raise Exception('Environment variable {} is not set'.format(name)) return value +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + def random_embedding_values(dimension=2): return [random.random() for _ in range(dimension)] -def random_string(length): - return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) +def write_gh_output(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: + print(f'{name}={value}', file=fh) def main(): api_key = read_env_var('PINECONE_API_KEY') environment = read_env_var('PINECONE_ENVIRONMENT') - index_name = read_env_var('INDEX_NAME') + index_name_prefix = read_env_var('INDEX_NAME_PREFIX') dimension = int(read_env_var('DIMENSION')) metric = read_env_var('METRIC') + vectors_to_upsert = int(read_env_var('VECTORS_TO_UPSERT')) + + index_name = index_name_prefix + '-' + random_string(10) + write_gh_output('index_name', index_name) print(f'Beginning test with environment {environment} and index {index_name}') @@ -30,33 +39,34 @@ def main(): environment=environment ) - if index_name in pinecone.list_indexes(): - print(f'Index {index_name} already exists') - pinecone.delete_index(index_name) - - pinecone.create_index( - name=index_name, - dimension=dimension, - metric=metric - ) - - print(f'Waiting for index {index_name} to be ready...') - time.sleep(60) - print(f'Done waiting.') + if index_name not in pinecone.list_indexes(): + print(f'Creating index {index_name}...') + pinecone.create_index( + name=index_name, + dimension=dimension, + metric=metric + ) + print(f'Waiting for index {index_name} to be ready...') + time.sleep(60) + print(f'Done waiting.') + else: + print(f'Index {index_name} already exists. Skipping create.') description = pinecone.describe_index(index_name) print(f'Index description: {description}') - print(f'Beginning upsert of 1000 vectors to index {index_name}...') - index = pinecone.Index(name=index_name) - for _ in range(100): + print(f'Beginning upsert of {vectors_to_upsert} vectors to index {index_name}...') + batch_size = 10 + num_batches = math.floor(vectors_to_upsert / batch_size) + index = pinecone.Index(index_name) + for _ in range(num_batches): vector = random_embedding_values(dimension) - vecs = [{'id': random_string(10), 'values': vector} for i in range(10)] - index.upsert(vectors=[vecs]) + vecs = [{'id': random_string(10), 'values': vector} for i in range(batch_size)] + index.upsert(vectors=vecs) print(f'Done upserting.') print(f'Beginning query of index {index_name}...') - index.query(vector=random_embedding_values(dimension)) + index.query(vector=random_embedding_values(dimension), top_k=10) print(f'Done querying.') if __name__ == '__main__': diff --git a/scripts/3.x/create-pod-index-from-collection.py b/scripts/3.x/create-pod-index-from-collection.py new file mode 100644 index 000000000..d1fa6b15c --- /dev/null +++ b/scripts/3.x/create-pod-index-from-collection.py @@ -0,0 +1,60 @@ +import os +import random +import string +import time +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise 'Environment variable {} is not set'.format(name) + return value + +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + +def write_gh_output(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: + print(f'{name}={value}', file=fh) + +def main(): + environment = read_env_var('PINECONE_ENVIRONMENT') + pc = Pinecone(api_key=read_env_var('PINECONE_API_KEY')) + environment = read_env_var('PINECONE_ENVIRONMENT') + collection_name = read_env_var('COLLECTION_NAME_PREFIX') + + index_name = read_env_var('INDEX_NAME_PREFIX') + '-from-' + collection_name + + pc.create_index( + name=index_name, + metric=read_env_var('METRIC'), + dimension=int(read_env_var('DIMENSION')), + spec={ + 'pod': { + 'environment': environment, + 'source_collection': collection_name, + 'pod_type': 'p1' + } + } + ) + write_gh_output('index_name', index_name) + time.sleep(60) + + description = pc.describe_index(index_name) + print(f'Index description: {description}') + assert description.name == index_name + + assert description.status.state == 'Ready' + assert description.status.ready == True + + idx = pc.Index(name=index_name) + stats = idx.describe_index_stats() + print(f'Index stats: {stats}') + + assert stats.dimension == int(read_env_var('DIMENSION')) + assert stats.metric == read_env_var('METRIC') + assert stats.total_vector_count == read_env_var('TOTAL_VECTOR_COUNT') + +if __name__ == '__main__': + main() + diff --git a/scripts/3.x/create-pod-index.py b/scripts/3.x/create-pod-index.py new file mode 100644 index 000000000..56dacbc09 --- /dev/null +++ b/scripts/3.x/create-pod-index.py @@ -0,0 +1,71 @@ +import os +import random +import string +import time +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise 'Environment variable {} is not set'.format(name) + return value + +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + +def random_embedding_values(dimension=2): + return [random.random() for _ in range(dimension)] + +def write_gh_output(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: + print(f'{name}={value}', file=fh) + +def main(): + environment = read_env_var('PINECONE_ENVIRONMENT') + pc = Pinecone(api_key=read_env_var('PINECONE_API_KEY')) + environment = read_env_var('PINECONE_ENVIRONMENT') + vectors_to_upsert = int(read_env_var('VECTORS_TO_UPSERT')) + + index_name = read_env_var('INDEX_NAME_PREFIX') + random_string(10) + pc.create_index( + name=index_name, + metric=read_env_var('METRIC'), + dimension=int(read_env_var('DIMENSION')), + spec={ + 'pod': { + 'environment': environment, + 'source_collection': collection_name, + 'pod_type': 'p1' + } + } + ) + write_gh_output('index_name', index_name) + time.sleep(60) # More waiting, just in case + + description = pc.describe_index(index_name) + print(f'Index description: {description}') + assert description.name == index_name + + assert description.status.state == 'Ready' + assert description.status.ready == True + + idx = pc.Index(name=index_name) + stats = idx.describe_index_stats() + print(f'Index stats: {stats}') + + print(f'Beginning upsert of {vectors_to_upsert} vectors to index {index_name}...') + batch_size = 10 + num_batches = math.floor(vectors_to_upsert / batch_size) + for _ in range(num_batches): + vector = random_embedding_values(dimension) + vecs = [{'id': random_string(10), 'values': vector} for i in range(batch_size)] + idx.upsert(vectors=vecs) + print(f'Done upserting.') + + assert stats.dimension == int(read_env_var('DIMENSION')) + assert stats.metric == read_env_var('METRIC') + assert stats.total_vector_count == vectors_to_upsert + +if __name__ == '__main__': + main() + diff --git a/scripts/3.x/delete-all-collections.py b/scripts/3.x/delete-all-collections.py new file mode 100644 index 000000000..065323742 --- /dev/null +++ b/scripts/3.x/delete-all-collections.py @@ -0,0 +1,25 @@ +import os +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise Exception('Environment variable {} is not set'.format(name)) + return value + +def main(): + api_key = read_env_var('PINECONE_API_KEY') + + pc = Pinecone(api_key=api_key) + + collections = pc.list_collections() + print(f'Found {len(collections)} collections.') + print(f'Collections: {collections}') + + for collection in collections: + print(f'Deleting collection {collection.name}...') + pc.delete_collection(collection.name) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/3.x/delete-all-indexes.py b/scripts/3.x/delete-all-indexes.py new file mode 100644 index 000000000..f1abd604a --- /dev/null +++ b/scripts/3.x/delete-all-indexes.py @@ -0,0 +1,25 @@ +import os +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise Exception('Environment variable {} is not set'.format(name)) + return value + +def main(): + api_key = read_env_var('PINECONE_API_KEY') + + pc = Pinecone(api_key=api_key) + + indexes = pc.list_indexes() + print(f'Found {len(indexes)} indexes.') + print(f'Indexes: {indexes}') + + for index in indexes: + print(f'Deleting index {index.name}...') + pc.delete_index(index.name) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/3.x/test-collection.py b/scripts/3.x/test-collection.py new file mode 100644 index 000000000..bfc2da119 --- /dev/null +++ b/scripts/3.x/test-collection.py @@ -0,0 +1,35 @@ +import random +import string +import os +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise Exception('Environment variable {} is not set'.format(name)) + return value + +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + +def main(): + api_key = read_env_var('PINECONE_API_KEY') + environment = read_env_var('PINECONE_ENVIRONMENT') + collection_name = read_env_var('COLLECTION_NAME') + + print(f'Beginning test with environment {environment} and collection {collection_name}') + + pc = Pinecone(api_key=api_key) + + print(f'Checking collection description...') + description = pc.describe_collection(collection_name) + print(f'Collection description: {description}') + + assert description['name'] == collection_name + assert description['status']['state'] == 'Ready' + assert description['status']['ready'] == True + + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/3.x/test-index.py b/scripts/3.x/test-index.py new file mode 100644 index 000000000..44679d9b9 --- /dev/null +++ b/scripts/3.x/test-index.py @@ -0,0 +1,62 @@ +import random +import string +import os +from pinecone import Pinecone + +def read_env_var(name): + value = os.environ.get(name) + if value is None: + raise Exception('Environment variable {} is not set'.format(name)) + return value + +def random_embedding_values(dimension=2): + return [random.random() for _ in range(dimension)] + +def random_string(length): + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) + +def main(): + api_key = read_env_var('PINECONE_API_KEY') + environment = read_env_var('PINECONE_ENVIRONMENT') + index_name = read_env_var('INDEX_NAME') + vectors_to_upsert = int(read_env_var('VECTORS_TO_UPSERT')) + + print(f'Beginning test with index {index_name}') + + pc = Pinecone(api_key=api_key) + + print(f'Checking if index {index_name} exists...') + if index_name not in pc.list_indexes().names(): + print(f'Index {index_name} does not exist. Creating...') + raise Exception('Index does not exist. Found indexes: {}'.format(pc.list_indexes().names())) + + print(f'Checking index description...') + description = pc.describe_index(index_name) + print(f'Index description: {description}') + + assert description.name == index_name + assert description.dimension > 0 + assert description.metric != None + assert description.spec.serverless == None + assert description.spec.pod != None + assert description.spec.pod.environment == environment + assert description.host != None + assert len(description.host) > 0 + assert description.status != None + assert description.status.state == 'Ready' + assert description.status.ready == True + + print(f'Index description looks correct.') + + host_url = description.host + + idx = pc.Index(name=index_name) + + stats = idx.describe_index_stats() + print(f'Index stats: {stats}') + + + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/tests/unit/models/test_collection_list.py b/tests/unit/models/test_collection_list.py index 3b26690f1..fea78f2b4 100644 --- a/tests/unit/models/test_collection_list.py +++ b/tests/unit/models/test_collection_list.py @@ -27,4 +27,11 @@ def test_collection_list_getitem(self, collection_list_response): def test_collection_list_proxies_methods(self, collection_list_response): # Forward compatibility, in case we add more attributes to IndexList for pagination - assert CollectionList(collection_list_response).collection_list.collections == collection_list_response.collections \ No newline at end of file + assert CollectionList(collection_list_response).collection_list.collections == collection_list_response.collections + + def test_when_results_are_empty(self): + assert len(CollectionList(OpenApiCollectionList(collections=[]))) == 0 + + def test_collection_list_names_syntactic_sugar(self, collection_list_response): + icl = CollectionList(collection_list_response) + assert icl.names() == ['collection1', 'collection2'] \ No newline at end of file