haystack/haystack/errors.py
James Briggs 9b1b03002f
update to PineconeDocumentStore to remove dependency on SQL db (#2749)
* update to PineconeDocumentStore to remove dependency on SQL db

* Update Documentation & Code Style

* typing fixes

* Update Documentation & Code Style

* fixed embedding generator to yield Documents

* Update Documentation & Code Style

* fixes for final typing issues

* fixes for pylint

* Update Documentation & Code Style

* uncomment pinecone tests

* added new params to docstrings

* Update Documentation & Code Style

* Update Documentation & Code Style

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* Update Documentation & Code Style

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* Update haystack/document_stores/pinecone.py

Co-authored-by: Sara Zan <sarazanzo94@gmail.com>

* changes based on comments, updated errors and install

* Update Documentation & Code Style

* mypy

* implement simple filtering in pinecone mock

* typo

* typo in reverse

* account for missing meta key in filtering

* typo

* added metadata filtering to describe index

* added handling for users switching indexes in same doc store, and handling duplicate docs in write

* syntax tweaks

* added index option to document/embedding count calls

* labels implementation in progress

* added metadata fields to be indexed for pinecone tests

* further changes to mock

* WIP implementation of labels+multilabels

* switched to rely on labels namespace rather than filter

* simpler delete_labels

* label fixes, remove debug code

* Apply dostring fixes

Co-authored-by: Agnieszka Marzec <97166305+agnieszka-m@users.noreply.github.com>

* mypy

* pylint

* docs

* temporarily un-mock Pinecone

* Small Pinecone test suite

* pylint

* Add fake test key to pass the None check

* Add again fake test key to pass the None check

* Add Pinecone to default docstores and fix filters

* Fix field name

* Change field name

* Change field value

* Remove comments

* forgot to upgrade pyproject.toml

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sara Zan <sara.zanzottera@deepset.ai>
Co-authored-by: Sara Zan <sarazanzo94@gmail.com>
Co-authored-by: Agnieszka Marzec <97166305+agnieszka-m@users.noreply.github.com>
2022-08-24 13:27:15 +02:00

119 lines
3.6 KiB
Python

"""Custom Errors for Haystack"""
from typing import Optional
from haystack.telemetry import send_custom_event
class HaystackError(Exception):
"""
Any error generated by Haystack.
This error wraps its source transparently in such a way that its attributes
can be accessed directly: for example, if the original error has a `message` attribute,
`HaystackError.message` will exist and have the expected content.
"""
def __init__(self, message: Optional[str] = None, docs_link: Optional[str] = None):
send_custom_event(event=f"{type(self).__name__} raised")
super().__init__()
if message:
self.message = message
self.docs_link = None
def __getattr__(self, attr):
# If self.__cause__ is None, it will raise the expected AttributeError
getattr(self.__cause__, attr)
def __str__(self):
if self.docs_link:
docs_message = f"\n\nCheck out the documentation at {self.docs_link}"
return self.message + docs_message
return self.message
def __repr__(self):
return str(self)
class ModelingError(HaystackError):
"""Exception for issues raised by the modeling module"""
def __init__(self, message: Optional[str] = None, docs_link: Optional[str] = "https://haystack.deepset.ai/"):
super().__init__(message=message, docs_link=docs_link)
class PipelineError(HaystackError):
"""Exception for issues raised within a pipeline"""
def __init__(
self, message: Optional[str] = None, docs_link: Optional[str] = "https://haystack.deepset.ai/pipelines"
):
super().__init__(message=message, docs_link=docs_link)
class PipelineSchemaError(PipelineError):
"""Exception for issues arising when reading/building the JSON schema of pipelines"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class PipelineConfigError(PipelineError):
"""Exception for issues raised within a pipeline's config file"""
def __init__(
self,
message: Optional[str] = None,
docs_link: Optional[str] = "https://haystack.deepset.ai/pipelines#yaml-file-definitions",
):
super().__init__(message=message, docs_link=docs_link)
class DocumentStoreError(HaystackError):
"""Exception for issues that occur in a document store"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class FilterError(DocumentStoreError):
"""Exception for issues that occur building complex filters"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class PineconeDocumentStoreError(DocumentStoreError):
"""Exception for issues that occur in a Pinecone document store"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class DuplicateDocumentError(DocumentStoreError, ValueError):
"""Exception for Duplicate document"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class NodeError(HaystackError):
"""Exception for issues that occur in a node"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class AudioNodeError(NodeError):
"""Exception for issues that occur in a node of the audio module"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)
class OpenAIError(NodeError):
"""Exception for issues that occur in the OpenAI Answer Generator node"""
def __init__(self, message: Optional[str] = None):
super().__init__(message=message)