-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) ## Problem This PR addresses a few configuration-related issues: - We moved `pool_threads` configuration up to the `Pinecone` client instance, but for backwards compatibility it would be nice to also allow it to be passed in the call to `pc.Index(host='your-host', pool_threads=5)` - We need to expose `grpc_config` as a keyword param when targeting indexes via the grpc-flavored client. ## Solution - Pass through kwargs from `.Index()` to underlying Index class implementation - Add unit tests making sure `pool_threads` and `grpc_config` handled correctly. ### Before (pool_threads) ```python from pinecone import Pinecone pc = Pinecone(api_key='key', pool_threads=5) pc.Index(host='host') pc.upsert(...) ``` ### After (pool_threads, add backwards compatibility with old way) You can use syntax as before, or alternatively can do this: ```python from pinecone import Pinecone pc = Pinecone(api_key='key') index = pc.Index(host='host', pool_threads=5) index.upsert(...) ``` ### After (grpc, allow grpc_config to be passed) ```python from pinecone.grpc import PineconeGRPC, GRPCClientConfig pc = PineconeGRPC(api_key='YOUR_API_KEY') grpc_config = GRPCClientConfig( timeout=10, secure=True, reuse_channel=True ) index = pc.Index(name='my-index', host='host', grpc_config=grpc_config) ``` ## Type of Change - [x] New feature (non-breaking change which adds functionality) - [x] None of the above: Add backwards compatibility on pool_threads config ## Test Plan New tests should be green in CI.
- Loading branch information
Showing
6 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from pinecone.grpc import PineconeGRPC, GRPCClientConfig | ||
|
||
class TestGRPCIndexInitialization: | ||
def test_init_with_default_config(self): | ||
pc = PineconeGRPC(api_key='YOUR_API_KEY') | ||
index = pc.Index(name='my-index', host='host') | ||
|
||
assert index.grpc_client_config.secure == True | ||
assert index.grpc_client_config.timeout == 20 | ||
assert index.grpc_client_config.conn_timeout == 1 | ||
assert index.grpc_client_config.reuse_channel == True | ||
assert index.grpc_client_config.retry_config == None | ||
assert index.grpc_client_config.grpc_channel_options == None | ||
|
||
def test_init_with_grpc_config_from_dict(self): | ||
pc = PineconeGRPC(api_key='YOUR_API_KEY') | ||
config = GRPCClientConfig._from_dict({'timeout': 10}) | ||
index = pc.Index(name='my-index', host='host', grpc_config=config) | ||
|
||
assert index.grpc_client_config.timeout == 10 | ||
|
||
# Unset fields still get default values | ||
assert index.grpc_client_config.reuse_channel == True | ||
assert index.grpc_client_config.secure == True | ||
|
||
|
||
def test_init_with_grpc_config_non_dict(self): | ||
pc = PineconeGRPC(api_key='YOUR_API_KEY') | ||
config = GRPCClientConfig(timeout=10, secure=False) | ||
index = pc.Index(name='my-index', host='host', grpc_config=config) | ||
|
||
assert index.grpc_client_config.timeout == 10 | ||
assert index.grpc_client_config.secure == False | ||
|
||
# Unset fields still get default values | ||
assert index.grpc_client_config.reuse_channel == True | ||
assert index.grpc_client_config.conn_timeout == 1 | ||
|
||
def test_config_passed_when_target_by_name(self): | ||
pc = PineconeGRPC(api_key='YOUR_API_KEY') | ||
|
||
# Set this state in the host store to skip network call | ||
# to find host for name | ||
pc.index_host_store.set_host(pc.config, 'my-index', 'myhost') | ||
|
||
config = GRPCClientConfig(timeout=10, secure=False) | ||
index = pc.Index(name='my-index', grpc_config=config) | ||
|
||
assert index.grpc_client_config.timeout == 10 | ||
assert index.grpc_client_config.secure == False | ||
|
||
# Unset fields still get default values | ||
assert index.grpc_client_config.reuse_channel == True | ||
assert index.grpc_client_config.conn_timeout == 1 | ||
|
||
def test_config_passed_when_target_by_host(self): | ||
pc = PineconeGRPC(api_key='YOUR_API_KEY') | ||
config = GRPCClientConfig(timeout=5, secure=True) | ||
index = pc.Index(host='myhost', grpc_config=config) | ||
|
||
assert index.grpc_client_config.timeout == 5 | ||
assert index.grpc_client_config.secure == True | ||
|
||
# Unset fields still get default values | ||
assert index.grpc_client_config.reuse_channel == True | ||
assert index.grpc_client_config.conn_timeout == 1 |