diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 56ee1c513..000709607 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=self.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..378c07631 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) 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 +