From 0e8e2c28990b27ce3c433d47ce37cde450e02b8b Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Tue, 26 Dec 2023 16:03:50 -0600 Subject: [PATCH 1/3] Wire up pool_threads config --- pinecone/control/pinecone.py | 11 +++++++---- pinecone/grpc/pinecone.py | 8 +++++--- tests/unit/test_config.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 56ee1c513..1f28732bb 100644 --- a/pinecone/control/pinecone.py +++ b/pinecone/control/pinecone.py @@ -24,6 +24,7 @@ def __init__( host: Optional[str] = None, config: Optional[Config] = None, additional_headers: Optional[Dict[str, str]] = {}, + pool_threads: Optional[int] = 1, index_api: Optional[IndexOperationsApi] = None, **kwargs, ): @@ -39,7 +40,8 @@ def __init__( if index_api: self.index_api = index_api else: - api_client = ApiClient(configuration=self.config.openapi_config) + self.pool_threads = pool_threads + api_client = ApiClient(configuration=self.config.openapi_config, pool_threads=pool_threads) api_client.user_agent = get_user_agent() extra_headers = self.config.additional_headers or {} for key, value in extra_headers.items(): @@ -222,6 +224,7 @@ def _get_status(self, name: str): response = api_instance.describe_index(name) return response["status"] - def Index(self, name: str): - index_host = self.index_host_store.get_host(self.index_api, self.config, name) - return Index(api_key=self.config.api_key, host=index_host) + def Index(self, name: str, host: Optional[str] = None): + if host is None: + host = self.index_host_store.get_host(self.index_api, self.config, name) + return Index(api_key=self.config.api_key, host=host, pool_threads=self.pool_threads) diff --git a/pinecone/grpc/pinecone.py b/pinecone/grpc/pinecone.py index 87ecf871d..4eda1503d 100644 --- a/pinecone/grpc/pinecone.py +++ b/pinecone/grpc/pinecone.py @@ -1,9 +1,11 @@ from ..control.pinecone import Pinecone from ..config.config import ConfigBuilder from .index_grpc import GRPCIndex +from typing import Optional class PineconeGRPC(Pinecone): - def Index(self, name: str): - index_host = self.index_host_store.get_host(self.index_api, self.config, name) - config = ConfigBuilder.build(api_key=self.config.api_key, host=index_host) + def Index(self, name: str, host: Optional[str] = None): + if host is None: + host = self.index_host_store.get_host(self.index_api, self.config, name) + config = ConfigBuilder.build(api_key=self.config.api_key, host=host, pool_threads=self.pool_threads) return GRPCIndex(index_name=name, config=config) diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index cc08dd2b9..058e6091d 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -1,5 +1,5 @@ -import pinecone -from pinecone.exceptions import PineconeApiKeyError, PineconeConfigurationError +from pinecone import Pinecone +from pinecone.exceptions import PineconeConfigurationError from pinecone.config import PineconeConfig from pinecone.core.client.configuration import Configuration as OpenApiConfiguration @@ -73,4 +73,11 @@ def test_resolution_order_kwargs_over_env_vars(self): def test_errors_when_no_api_key_is_present(self): with pytest.raises(PineconeConfigurationError): - PineconeConfig.build() \ No newline at end of file + PineconeConfig.build() + + def test_config_pool_threads(self): + pc = Pinecone(api_key="test-api-key", host="test-controller-host", pool_threads=10) + assert pc.index_api.api_client.pool_threads == 10 + idx = pc.Index(host='my-index-host', name='my-index-name') + assert idx._api_client.pool_threads == 10 + From 774b80261374f92475dc6c7ee2be581f88531d03 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Tue, 26 Dec 2023 16:09:24 -0600 Subject: [PATCH 2/3] Remove pool threads in GRPC use case --- pinecone/grpc/pinecone.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pinecone/grpc/pinecone.py b/pinecone/grpc/pinecone.py index 4eda1503d..378c07631 100644 --- a/pinecone/grpc/pinecone.py +++ b/pinecone/grpc/pinecone.py @@ -7,5 +7,5 @@ class PineconeGRPC(Pinecone): def Index(self, name: str, host: Optional[str] = None): if host is None: host = self.index_host_store.get_host(self.index_api, self.config, name) - config = ConfigBuilder.build(api_key=self.config.api_key, host=host, pool_threads=self.pool_threads) + config = ConfigBuilder.build(api_key=self.config.api_key, host=host) return GRPCIndex(index_name=name, config=config) From 6da01009fd1eae5e5edd85444680f00ceed66ea9 Mon Sep 17 00:00:00 2001 From: Jennifer Hamon Date: Wed, 27 Dec 2023 08:12:56 -0600 Subject: [PATCH 3/3] Update pinecone/control/pinecone.py Co-authored-by: Austin DeNoble --- pinecone/control/pinecone.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 1f28732bb..000709607 100644 --- a/pinecone/control/pinecone.py +++ b/pinecone/control/pinecone.py @@ -41,7 +41,7 @@ def __init__( self.index_api = index_api else: self.pool_threads = pool_threads - api_client = ApiClient(configuration=self.config.openapi_config, pool_threads=pool_threads) + api_client = ApiClient(configuration=self.config.openapi_config, pool_threads=self.pool_threads) api_client.user_agent = get_user_agent() extra_headers = self.config.additional_headers or {} for key, value in extra_headers.items():