-
Notifications
You must be signed in to change notification settings - Fork 89
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
Move all grpc stuff into pinecone.grpc subpackage #238
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, all of this makes a lot of sense. Thanks for taking this through the finish line after helping out with all the dependency problems that cropped up due to this setup. 🚢
- name: Build docs | ||
run: make docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pulling this out of here, this was a mistake on my part I think.
We cover this step in the pr
workflow already so it may have been running twice.
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 } | ||
lz4 = { version = ">=3.1.3", optional = true } | ||
protobuf = { version = "~=3.20.0", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know you could explicitly set optional
like this. 👍
Problem
In the past this package attempted to import extra grpc deps in the root
__init__.py
inside a try/catch that caughtImportError
when deps were missing. This is error prone because people may be attempting to use thepinecone
module alongside other packages that depend on incompatible versions of these dependencies, so we shouldn't interpret successful import as a sign that a user has installed thepinecone-client[grpc]
extras (with the versions we expect). When these incompatible versions are present, theImportError
doesn't happen but other runtime errors can occur even when the person is not attempting to useGRPCIndex
.Solution
The gist of this PR is to better isolate everything GRPC-related into a subpackage to minimize the changes of a grpc-related dependency clash getting in the way of using Pinecone. By doing this, issues with grpc dependencies should never impact people using the non-grpc client.
Summary of changes:
pinecone/data/grpc
moved up and over topinecone/grpc
tests/unit/test_index_grpc.py
intotests/unit_grpc/test_index_grpc.py
. This is to make it easier to split grpc and non-grpc test runs.pinecone/deprecated/legacy_utils.py
because they were unused and loading grpc deps.from pinecone import Pinecone
independent of GRPCpinecone/__init__.py
pinecone/pinecone.py
to removeIndexGRPC()
method.from pinecone.grpc import Pinecone
pinecone/grpc/pinecone.yaml
that extends the other Pinecone class, modifying only theIndex()
method to useGRPCIndex
.pinecone/grpc/__init__.py
with entries for grpc-flavoredPinecone
andIndexGRPC
exports.pyproject.toml
adjusted to properly indicate grpc deps asoptional = true
; I discovered in testing that grpc dependencies were always being installed in CI.setup-poetry
action so that we can toggle on grpc dependencies when needed..github/workflows/testing.yaml
refactored to break GRPC and non-GRPC into separate jobs, since they have different install requirements.Usage evolution
Legacy implementation
Unreleased spruce branch (before this PR)
This was an improvement over the legacy approach because we no longer relied on global state for configuration. Instead, we wrap configuration state into a class instance. However, the
Pinecone
class had a dependency on GRPC stuff to implement theGRPCIndex()
method. The imports of these extra deps was intended to noop when they were not installed, but as I described above there are situations where you could still have runtime errors if other dependencies in your notebook / app have installed incompatible GRPC dependencies that prevent you from using the REST version of the client.After this PR, import from different subpackage when GRPC desired
Now the usage is exactly the same for REST vs GRPC except for the import coming from
pinecone.grpc
instead ofpinecone
when you want data operations to use grpc. GRPC deps are not loaded at all unless you specifically import frompinecone.grpc
.To use REST, import from
pinecone
To use GRPC, import from
pinecone.grpc
subpackageIf you ever wanted to use these side by side for some reason (no real reason to ever do this unless you are writing tests for this package) you would have to alias one of the imports to avoid a name collision.
Type of Change
Test Plan
Describe specific steps for validating this change.