-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config / init refactor for state encapsulation #220
Changes from 8 commits
7dda40c
c5c41d4
b645c22
8b5acb0
16c6432
18cf313
aaf71fc
38dfb14
91b5728
5a83568
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,10 @@ | |
""" | ||
from .config import * | ||
from .exceptions import * | ||
from .manage import * | ||
from .index import * | ||
from .control.pinecone import Pinecone | ||
from .data.index import * | ||
|
||
try: | ||
from .grpc.index_grpc import * | ||
from .data.grpc.index_grpc import * | ||
except ImportError: | ||
pass # ignore for non-[grpc] installations | ||
|
||
# Kept for backwards-compatibility | ||
UpsertResult = None | ||
"""@private""" | ||
DeleteResult = None | ||
"""@private""" | ||
QueryResult = None | ||
"""@private""" | ||
FetchResult = None | ||
"""@private""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have context on these, but I can't imagine any scenario where returning a bunch of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'm not really sure what this was for. I think it's probably fine to pull them out. Otherwise it would just be someone defining behavior themselves for these things anyways. |
||
InfoResult = None | ||
"""@private""" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .config import Config | ||
from .pinecone_config import PineconeConfig |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from typing import NamedTuple | ||
import os | ||
|
||
from pinecone.utils import check_kwargs | ||
from pinecone.exceptions import PineconeConfigurationError | ||
from pinecone.core.client.exceptions import ApiKeyError | ||
from pinecone.config.openapi import OpenApiConfigFactory | ||
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration | ||
|
||
|
||
class ConfigBase(NamedTuple): | ||
api_key: str = "" | ||
host: str = "" | ||
openapi_config: OpenApiConfiguration = None | ||
|
||
|
||
class Config: | ||
""" | ||
|
||
Configurations are resolved in the following order: | ||
|
||
- configs passed as keyword parameters | ||
- configs specified in environment variables | ||
- default values (if applicable) | ||
""" | ||
|
||
"""Initializes the Pinecone client. | ||
|
||
:param api_key: Required if not set in config file or by environment variable ``PINECONE_API_KEY``. | ||
:param host: Optional. Controller host. | ||
:param openapi_config: Optional. Set OpenAPI client configuration. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
api_key: str = None, | ||
host: str = None, | ||
openapi_config: OpenApiConfiguration = None, | ||
**kwargs, | ||
): | ||
api_key = api_key or kwargs.pop("api_key", None) or os.getenv("PINECONE_API_KEY") | ||
host = host or kwargs.pop("host", None) | ||
openapi_config = ( | ||
openapi_config | ||
or kwargs.pop("openapi_config", None) | ||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that |
||
or OpenApiConfigFactory.build(api_key=api_key, host=host) | ||
) | ||
|
||
check_kwargs(self.__init__, kwargs) | ||
self._config = ConfigBase(api_key, host, openapi_config) | ||
self.validate() | ||
|
||
def validate(self): | ||
if not self._config.api_key: | ||
raise PineconeConfigurationError("You haven't specified an Api-Key.") | ||
if not self._config.host: | ||
raise PineconeConfigurationError("You haven't specified a host.") | ||
|
||
@property | ||
def API_KEY(self): | ||
return self._config.api_key | ||
|
||
@property | ||
def HOST(self): | ||
return self._config.host | ||
|
||
@property | ||
def OPENAPI_CONFIG(self): | ||
return self._config.openapi_config |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved these constants out of old The rest of this I pulled out of We need a whole ticket to revisit and overhaul the logging approach in a holistic way. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import logging | ||
|
||
PARENT_LOGGER_NAME = "pinecone" | ||
DEFAULT_PARENT_LOGGER_LEVEL = "ERROR" | ||
|
||
_logger = logging.getLogger(__name__) | ||
_parent_logger = logging.getLogger(PARENT_LOGGER_NAME) | ||
_parent_logger.setLevel(DEFAULT_PARENT_LOGGER_LEVEL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
try
import statements led to some pretty confusing debug situations when stuff started failing due to me moving packages from one location to another since the intention is really only to ignore failures caused by people installing without grpc extras. We should revisit this pattern and make sure we're testing stuff both with and without grpc deps loaded.