diff --git a/pinecone/__init__.py b/pinecone/__init__.py index d4f29bfa..da726366 100644 --- a/pinecone/__init__.py +++ b/pinecone/__init__.py @@ -6,7 +6,21 @@ from .deprecation_warnings import * from .pinecone import Pinecone from .pinecone_asyncio import PineconeAsyncio -from .exceptions import * +from .exceptions import ( + PineconeException, + PineconeApiTypeError, + PineconeApiValueError, + PineconeApiAttributeError, + PineconeApiKeyError, + PineconeApiException, + NotFoundException, + UnauthorizedException, + ForbiddenException, + ServiceException, + PineconeProtocolError, + PineconeConfigurationError, + ListConversionException, +) from .utils import __version__ diff --git a/pinecone/__init__.pyi b/pinecone/__init__.pyi index c900e420..da6cc5ae 100644 --- a/pinecone/__init__.pyi +++ b/pinecone/__init__.pyi @@ -1,7 +1,24 @@ from pinecone.config import Config from pinecone.config import ConfigBuilder from pinecone.config import PineconeConfig +from .exceptions import ( + PineconeException, + PineconeApiTypeError, + PineconeApiValueError, + PineconeApiAttributeError, + PineconeApiKeyError, + PineconeApiException, + NotFoundException, + UnauthorizedException, + ForbiddenException, + ServiceException, + PineconeProtocolError, + PineconeConfigurationError, + ListConversionException, +) from pinecone.inference import ( + Inference, + AsyncioInference, RerankModel, EmbedModel, ModelInfo, @@ -72,7 +89,23 @@ __all__ = [ "Config", "ConfigBuilder", "PineconeConfig", + # Exceptions + "PineconeException", + "PineconeApiTypeError", + "PineconeApiValueError", + "PineconeApiAttributeError", + "PineconeApiKeyError", + "PineconeApiException", + "NotFoundException", + "UnauthorizedException", + "ForbiddenException", + "ServiceException", + "PineconeProtocolError", + "PineconeConfigurationError", + "ListConversionException", # Inference classes + "Inference", + "AsyncioInference", "RerankModel", "EmbedModel", "ModelInfo", diff --git a/pinecone/exceptions/__init__.py b/pinecone/exceptions/__init__.py index f437e90b..c7b2b1cd 100644 --- a/pinecone/exceptions/__init__.py +++ b/pinecone/exceptions/__init__.py @@ -15,17 +15,17 @@ ) __all__ = [ - "PineconeConfigurationError", - "PineconeProtocolError", "PineconeException", - "PineconeApiAttributeError", "PineconeApiTypeError", "PineconeApiValueError", + "PineconeApiAttributeError", "PineconeApiKeyError", "PineconeApiException", "NotFoundException", "UnauthorizedException", "ForbiddenException", "ServiceException", + "PineconeProtocolError", + "PineconeConfigurationError", "ListConversionException", ] diff --git a/pinecone/exceptions/exceptions.py b/pinecone/exceptions/exceptions.py index 32eed99f..3601a7db 100644 --- a/pinecone/exceptions/exceptions.py +++ b/pinecone/exceptions/exceptions.py @@ -49,10 +49,10 @@ def __init__(self, msg, path_to_item=None) -> None: class PineconeApiAttributeError(PineconeException, AttributeError): + """Raised when an attribute reference or assignment fails.""" + def __init__(self, msg, path_to_item=None) -> None: """ - Raised when an attribute reference or assignment fails. - Args: msg (str): the exception message @@ -85,6 +85,8 @@ def __init__(self, msg, path_to_item=None) -> None: class PineconeApiException(PineconeException): + """Raised when an API exception occurs.""" + def __init__(self, status=None, reason=None, http_resp=None) -> None: if http_resp: self.status = http_resp.status @@ -110,21 +112,29 @@ def __str__(self): class NotFoundException(PineconeApiException): + """Raised when a resource is not found.""" + def __init__(self, status=None, reason=None, http_resp=None) -> None: super(NotFoundException, self).__init__(status, reason, http_resp) class UnauthorizedException(PineconeApiException): + """Raised when access to a resource is not authorized.""" + def __init__(self, status=None, reason=None, http_resp=None) -> None: super(UnauthorizedException, self).__init__(status, reason, http_resp) class ForbiddenException(PineconeApiException): + """Raised when access to a resource is forbidden.""" + def __init__(self, status=None, reason=None, http_resp=None) -> None: super(ForbiddenException, self).__init__(status, reason, http_resp) class ServiceException(PineconeApiException): + """Raised when a service error occurs.""" + def __init__(self, status=None, reason=None, http_resp=None) -> None: super(ServiceException, self).__init__(status, reason, http_resp) @@ -151,3 +161,20 @@ class PineconeConfigurationError(PineconeException): class ListConversionException(PineconeException, TypeError): def __init__(self, message): super().__init__(message) + + +__all__ = [ + "PineconeException", + "PineconeApiTypeError", + "PineconeApiValueError", + "PineconeApiAttributeError", + "PineconeApiKeyError", + "PineconeApiException", + "NotFoundException", + "UnauthorizedException", + "ForbiddenException", + "ServiceException", + "PineconeProtocolError", + "PineconeConfigurationError", + "ListConversionException", +] diff --git a/pinecone/pinecone.py b/pinecone/pinecone.py index 60f02e9b..792190e3 100644 --- a/pinecone/pinecone.py +++ b/pinecone/pinecone.py @@ -15,12 +15,7 @@ if TYPE_CHECKING: from pinecone.config import Config, OpenApiConfiguration - from pinecone.db_data import ( - _Index as Index, - _Inference as Inference, - _IndexAsyncio as IndexAsyncio, - ) - from pinecone.db_control import DBControl + from pinecone.db_data import _Index as Index, _IndexAsyncio as IndexAsyncio from pinecone.db_control.index_host_store import IndexHostStore from pinecone.core.openapi.db_control.api.manage_indexes_api import ManageIndexesApi from pinecone.db_control.types import CreateIndexForModelEmbedTypedDict @@ -94,18 +89,18 @@ def __init__( self._pool_threads = pool_threads """ @private """ - self._inference: Optional["Inference"] = None # Lazy initialization + self._inference = None # Lazy initialization """ @private """ - self._db_control: Optional["DBControl"] = None # Lazy initialization + self._db_control = None # Lazy initialization """ @private """ super().__init__() # Initialize PluginAware @property - def inference(self) -> "Inference": + def inference(self): """ - Inference is a namespace where an instance of the `pinecone.data.features.inference.inference.Inference` class is lazily created and cached. + Inference is a namespace where an instance of the `pinecone.inference.Inference` class is lazily created and cached. """ if self._inference is None: from pinecone.inference import Inference @@ -118,9 +113,9 @@ def inference(self) -> "Inference": return self._inference @property - def db(self) -> "DBControl": + def db(self): """ - DBControl is a namespace where an instance of the `pinecone.control.db_control.DBControl` class is lazily created and cached. + DBControl is a namespace where an instance of the `pinecone.db_control.DBControl` class is lazily created and cached. """ if self._db_control is None: from pinecone.db_control import DBControl