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

Update generated client code #215

Merged
merged 1 commit into from
Oct 16, 2023
Merged

Update generated client code #215

merged 1 commit into from
Oct 16, 2023

Conversation

jhamon
Copy link
Collaborator

@jhamon jhamon commented Oct 11, 2023

Problem

We need to update the generated core module to reflect upcoming API changes

Solution

  • Migrate from v5 to v7 openapi generator to avoid generating code with deprecated urllib3 usage.
  • Regenerate contents of pinecone.core using pinecone-protos (private) repo.
  • Refactor to move all non-generated items out from under pinecone.core. These never should have been under pinecone.core in the first place.
    • Added pinecone.utils
    • Added pinecone.grpc to hold GRPCIndex and related code.
  • Add new dependencies required by updated generated code (pydantic for typechecking, aenum for enums)
  • Disable legacy integ tests which won't work until we refactor configuration.

Type of Change

  • New feature (non-breaking change which adds functionality)

@jhamon jhamon requested a review from austin-denoble October 11, 2023 15:13
@jhamon jhamon force-pushed the jhamon/spruce-codegen branch 2 times, most recently from 54bd898 to b758766 Compare October 11, 2023 20:48
pyproject.toml Outdated
Comment on lines 60 to 73
loguru = "0.5.3"
typing-extensions = ">=3.7.4"
dnspython = ">=2.0.0"
python-dateutil = ">=2.5.3"
urllib3 = ">=1.21.1"
urllib3 = "1.25.3"
tqdm = ">=4.64.1"
numpy = ">=1.22.0"
grpcio = ">=1.44.0"
grpc-gateway-protoc-gen-openapiv2 = "0.1.0"
googleapis-common-protos = ">=1.53.0"
lz4 = ">=3.1.3"
protobuf = "~=3.20.0"
aenum = "3.1.11"
pydantic = "1.10.12"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and added dependencies to satisfy the requirements of the generated openapi code. Both have permissive open source licenses, so no issue there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially use pydantic in a similar way to typebox in the TS client if we wanted to add better runtime validation and error handling, if I'm understanding things correctly.


@pytest.mark.skip()
Copy link
Collaborator Author

@jhamon jhamon Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of black changes in this file, but all the tests are currently marked skip because they can't pass until we overhaul configuration.

The urllib3_mock we are depending on throws a lot of deprecation warnings and appears to be abandoned so we should figure out some other tool there if we need to do request mocking in the future. But in reality I don't think we need to mock requests at that level if we refactor our tests into either pure unit tests or real integration tests against a live environment.

@@ -6,210 +6,204 @@
import tempfile
import os


@pytest.fixture(autouse=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed references to project name from these config tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think much changed inhere besides formatting.

import pinecone
from pinecone import UpsertRequest, Vector
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these imports to make the tests a bit less verbose.

Comment on lines +120 to 164
chunks = [
[Vector(id="vec1", values=self.vals1, metadata=self.md1)],
[Vector(id="vec2", values=self.vals2, metadata=self.md2)],
]
with pinecone.Index("example-index", pool_threads=30) as index:
mocker.patch.object(index._vector_api, "upsert", autospec=True)

# Send requests in parallel
async_results = [
index.upsert(vectors=ids_vectors_chunk, namespace="ns", async_req=True)
for ids_vectors_chunk in chunks
index.upsert(vectors=ids_vectors_chunk, namespace="ns", async_req=True) for ids_vectors_chunk in chunks
]
# Wait for and retrieve responses (this raises in case of error)
[async_result.get() for async_result in async_results]

Endpoint.__call__.assert_any_call(
index._vector_api.upsert,
pinecone.UpsertRequest(vectors=[
pinecone.Vector(id='vec1', values=self.vals1, metadata=self.md1),
],
namespace='ns'),
async_req=True
index._vector_api.upsert.assert_any_call(
UpsertRequest(
vectors=[
Vector(id="vec1", values=self.vals1, metadata=self.md1),
],
namespace="ns",
),
async_req=True,
)

Endpoint.__call__.assert_any_call(
index._vector_api.upsert,
pinecone.UpsertRequest(vectors=[
pinecone.Vector(id='vec2', values=self.vals2, metadata=self.md2),
],
namespace='ns'),
async_req=True
index._vector_api.upsert.assert_any_call(
UpsertRequest(
vectors=[
Vector(id="vec2", values=self.vals2, metadata=self.md2),
],
namespace="ns",
),
async_req=True,
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was pretty heavily refactored to mock out at the vector_api level instead of reaching in to touch the Endpoint internals, which got changed between v5 and v7 openapi versions.

import pytest
import warnings

from pinecone.core.client.api_client import Endpoint
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This export is not available, and most substantive changes in this test file are to refactor away from depending on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thank you.

@@ -6,10 +6,10 @@ function bumpVersion(currentVersion, bumpType, prerelease) {
if (prerelease) {
newVersion = `${newVersion}.${prerelease}`;
}
core.setOutput('previous_version', currentVersion)
core.setOutput('previous_version_tag', `v${currentVersion}`)
core.setOutput('previous_version', currentVersion);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe black did this? Not really my intention, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I think it was prettier / lint since it's a .js file. I had the same thing happen when I was working on workflows: https://github.com/pinecone-io/pinecone-python-client/pull/216/files

Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the work that went into getting the core regenerated and updated. Overall this looks good, it seems like we'll need a few tickets for follow-up here around re-enabling integration tests, and replacing urllib3 if needed for mocking.

It looks like the pdoc build is also failing due to a couple import related issues. I think this is due to it using dynamic analysis when extracting docstrings, so Python modules are executed/imported when it runs:

  • ModuleNotFoundError: No module named 'pinecone.core.client.model'
  • ImportError: cannot import name 'Endpoint' from 'pinecone.core.client.api_client' (/home/runner/work/pinecone-python-client/pinecone-python-client/pinecone/core/client/api_client.py)

I can pull things down and maybe take a look, we could also skip / disable for now since we're in a feature branch. I think this also still may need a rebase against origin/spruce to pull in the workflow changes.

@@ -6,10 +6,10 @@ function bumpVersion(currentVersion, bumpType, prerelease) {
if (prerelease) {
newVersion = `${newVersion}.${prerelease}`;
}
core.setOutput('previous_version', currentVersion)
core.setOutput('previous_version_tag', `v${currentVersion}`)
core.setOutput('previous_version', currentVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I think it was prettier / lint since it's a .js file. I had the same thing happen when I was working on workflows: https://github.com/pinecone-io/pinecone-python-client/pull/216/files

Makefile Outdated
Comment on lines 26 to 27

upload-spruce:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add upload-spruce to the .PHONY: ... line at the top so it's callable.

from .config import *
from .exceptions import *
from .info import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for pulling these out. I had stripped them out of the docs as well because they're all internal and I don't think we expect external users to have access to these.

pyproject.toml Outdated
Comment on lines 60 to 73
loguru = "0.5.3"
typing-extensions = ">=3.7.4"
dnspython = ">=2.0.0"
python-dateutil = ">=2.5.3"
urllib3 = ">=1.21.1"
urllib3 = "1.25.3"
tqdm = ">=4.64.1"
numpy = ">=1.22.0"
grpcio = ">=1.44.0"
grpc-gateway-protoc-gen-openapiv2 = "0.1.0"
googleapis-common-protos = ">=1.53.0"
lz4 = ">=3.1.3"
protobuf = "~=3.20.0"
aenum = "3.1.11"
pydantic = "1.10.12"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially use pydantic in a similar way to typebox in the TS client if we wanted to add better runtime validation and error handling, if I'm understanding things correctly.

import pytest
import warnings

from pinecone.core.client.api_client import Endpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thank you.

pinecone.init(api_key='example-key')
self.index = pinecone.Index('example-name')

def test_upsert_numpy_deprecation_warning(self, mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Are we still planning on deprecating numpy? I've seen references to that in the codebase and this seems to confirm that.

If so we can probably add a ticket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should remove it before releasing spruce. I'll add a ticket.

@@ -15,8 +15,8 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be good for actually adding some documentation around the GRPC bits, thank you. 👍

@jhamon jhamon force-pushed the jhamon/spruce-codegen branch from 0e79c67 to 199c7f4 Compare October 16, 2023 21:59
@jhamon jhamon merged commit 17e0566 into spruce Oct 16, 2023
5 checks passed
@jhamon jhamon deleted the jhamon/spruce-codegen branch October 16, 2023 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants