-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathexceptions.py
More file actions
162 lines (92 loc) · 4.3 KB
/
exceptions.py
File metadata and controls
162 lines (92 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Copyright (c) "Neo4j"
# Neo4j Sweden AB [https://neo4j.com]
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from pydantic_core import ErrorDetails
class Neo4jGraphRagError(Exception):
"""Global exception used for the neo4j-graphrag package."""
pass
class RetrieverInitializationError(Neo4jGraphRagError):
"""Exception raised when initialization of a retriever fails."""
def __init__(self, errors: list[ErrorDetails]) -> None:
super().__init__(f"Initialization failed: {errors}")
self.errors = errors
class RagInitializationError(Neo4jGraphRagError):
def __init__(self, errors: list[ErrorDetails]):
super().__init__(f"Initialization failed: {errors}")
self.errors = errors
class PromptMissingInputError(Neo4jGraphRagError):
"""Exception raised when a prompt required input is missing."""
pass
class LLMGenerationError(Neo4jGraphRagError):
"""Exception raised when answer generation from LLM fails."""
pass
class EmbeddingsGenerationError(Neo4jGraphRagError):
"""Exception raised when generation of embeddings fails"""
class SearchValidationError(Neo4jGraphRagError):
"""Exception raised for validation errors during search."""
def __init__(self, errors: list[ErrorDetails]) -> None:
super().__init__(f"Search validation failed: {errors}")
self.errors = errors
class FilterValidationError(Neo4jGraphRagError):
"""Exception raised when input validation for metadata filtering fails."""
pass
class EmbeddingRequiredError(Neo4jGraphRagError):
"""Exception raised when an embedding method is required but not provided."""
pass
class InvalidRetrieverResultError(Neo4jGraphRagError):
"""Exception raised when the Retriever fails to return a result."""
pass
class Neo4jIndexError(Neo4jGraphRagError):
"""Exception raised when handling Neo4j index fails."""
pass
class Neo4jInsertionError(Neo4jGraphRagError):
"""Exception raised when inserting data into the Neo4j database fails."""
pass
class Neo4jVersionError(Neo4jGraphRagError):
"""Exception raised when Neo4j version does not meet minimum requirements."""
def __init__(self) -> None:
super().__init__("This package only supports Neo4j version 5.18.1 or greater")
class Text2CypherRetrievalError(Neo4jGraphRagError):
"""Exception raised when text-to-cypher retrieval fails."""
pass
class SchemaFetchError(Neo4jGraphRagError):
"""Exception raised when a Neo4jSchema cannot be fetched."""
pass
class SchemaValidationError(Neo4jGraphRagError):
"""Custom exception for errors in schema configuration."""
pass
class SchemaExtractionError(Neo4jGraphRagError):
"""Exception raised for errors in automatic schema extraction."""
pass
class PdfLoaderError(Neo4jGraphRagError):
"""Custom exception for errors in PDF loader."""
pass
class MarkdownLoadError(Neo4jGraphRagError):
"""Custom exception for errors in Markdown loader."""
pass
class UnsupportedDocumentFormatError(Neo4jGraphRagError):
"""Raised when a file extension is not supported by the document file loader."""
pass
class PromptMissingPlaceholderError(Neo4jGraphRagError):
"""Exception raised when a prompt is missing an expected placeholder."""
class InvalidHybridSearchRankerError(Neo4jGraphRagError):
"""Exception raised when an invalid ranker type for Hybrid Search is provided."""
class SearchQueryParseError(Neo4jGraphRagError):
"""Exception raised when there is a query parse error in the text search string."""
class RetryableError(LLMGenerationError):
"""Exception raised for transient errors that may succeed on retry (e.g. rate limits)."""
pass
class RateLimitError(RetryableError):
"""Exception raised when API rate limit is exceeded."""