pinecone-io / pinecone-python-client

The Pinecone Python client
https://www.pinecone.io/docs
Apache License 2.0
309 stars 81 forks source link

[Refactor] Extract GrpcRunner from GRPCIndexBase class #395

Closed jhamon closed 1 month ago

jhamon commented 1 month ago

Problem

This is another extractive refactoring in preparation for grpc with asyncio.

Solution

The generated stub class, VectorServiceStub, is what knows how to call the Pinecone grpc service, but our wrapper code needs to do some work to make sure we have a consistent approach to "metadata" (grpc-speak for request headers) and handling other request params like timeout. Previously this work was accomplished in a private method of the GRPCIndexBase base class called _wrap_grpc_call().

Since we will need to perform almost identical marshaling of metadata for requests with asyncio, I pulled this logic out into a separate class GrpcRunner and renamed _wrap_grpc_call to run. You can see there is also a parallel method implementation called run_asyncio; currently this is unused and untested, but kind of illustrates why this refactor is useful.

Type of Change

Test Plan

Tests should still be green