Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pinecone/control/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand All @@ -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():
Expand Down Expand Up @@ -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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny tweak for supporting custom host in grpc, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this change is unrelated to pool_threads since that only applies to async REST calls, but I wanted to keep these method signatures aligned across both GRPC and non-GRPC usage. I made this change for the REST case so I wouldn't have to figure out how to stub out the call to fetch the host in the test that I added, and in general having more ways to avoid making that network call is a good thing.

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)
8 changes: 5 additions & 3 deletions pinecone/grpc/pinecone.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 10 additions & 3 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
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