cognee 0.2.2.dev1__py3-none-any.whl → 0.2.3.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognee/api/v1/add/add.py +0 -5
- cognee/api/v1/cognify/cognify.py +0 -8
- cognee/api/v1/config/config.py +5 -13
- cognee/api/v1/datasets/routers/get_datasets_router.py +1 -1
- cognee/api/v1/delete/delete.py +1 -1
- cognee/api/v1/exceptions/__init__.py +13 -0
- cognee/api/v1/{delete → exceptions}/exceptions.py +15 -12
- cognee/api/v1/search/search.py +0 -7
- cognee/exceptions/__init__.py +5 -5
- cognee/exceptions/exceptions.py +37 -17
- cognee/infrastructure/data/exceptions/__init__.py +7 -0
- cognee/infrastructure/data/exceptions/exceptions.py +22 -0
- cognee/infrastructure/data/utils/extract_keywords.py +3 -3
- cognee/infrastructure/databases/exceptions/__init__.py +3 -0
- cognee/infrastructure/databases/exceptions/exceptions.py +57 -9
- cognee/infrastructure/databases/graph/neptune_driver/exceptions.py +15 -10
- cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py +2 -2
- cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +4 -5
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -2
- cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +1 -1
- cognee/infrastructure/databases/vector/exceptions/exceptions.py +3 -3
- cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +2 -2
- cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +4 -3
- cognee/infrastructure/llm/exceptions.py +30 -2
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +2 -2
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +3 -3
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +10 -7
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +6 -4
- cognee/infrastructure/loaders/LoaderInterface.py +1 -1
- cognee/modules/data/exceptions/exceptions.py +18 -5
- cognee/modules/data/methods/delete_data.py +2 -4
- cognee/modules/data/processing/document_types/exceptions/exceptions.py +2 -2
- cognee/modules/graph/cognee_graph/CogneeGraph.py +6 -4
- cognee/modules/graph/cognee_graph/CogneeGraphElements.py +5 -10
- cognee/modules/graph/exceptions/__init__.py +2 -0
- cognee/modules/graph/exceptions/exceptions.py +25 -3
- cognee/modules/ingestion/exceptions/exceptions.py +2 -2
- cognee/modules/ontology/exceptions/exceptions.py +4 -4
- cognee/modules/pipelines/exceptions/exceptions.py +2 -2
- cognee/modules/retrieval/exceptions/exceptions.py +12 -6
- cognee/modules/search/exceptions/__init__.py +7 -0
- cognee/modules/search/exceptions/exceptions.py +15 -0
- cognee/modules/search/methods/search.py +2 -3
- cognee/modules/users/exceptions/exceptions.py +6 -6
- cognee/shared/exceptions/exceptions.py +2 -2
- cognee/tasks/completion/exceptions/exceptions.py +3 -3
- cognee/tasks/documents/classify_documents.py +4 -0
- cognee/tasks/documents/exceptions/__init__.py +11 -0
- cognee/tasks/documents/exceptions/exceptions.py +36 -0
- cognee/tasks/documents/extract_chunks_from_documents.py +8 -2
- cognee/tasks/graph/exceptions/__init__.py +12 -0
- cognee/tasks/graph/exceptions/exceptions.py +41 -0
- cognee/tasks/graph/extract_graph_from_data.py +28 -0
- cognee/tasks/ingestion/exceptions/__init__.py +8 -0
- cognee/tasks/ingestion/exceptions/exceptions.py +12 -0
- cognee/tasks/ingestion/resolve_data_directories.py +5 -0
- cognee/tasks/storage/add_data_points.py +8 -0
- cognee/tasks/storage/exceptions/__init__.py +9 -0
- cognee/tasks/storage/exceptions/exceptions.py +13 -0
- cognee/tasks/storage/index_data_points.py +1 -1
- cognee/tasks/summarization/exceptions/__init__.py +9 -0
- cognee/tasks/summarization/exceptions/exceptions.py +14 -0
- cognee/tasks/summarization/summarize_text.py +8 -1
- cognee/tests/test_delete_by_id.py +1 -1
- cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +5 -5
- cognee/tests/unit/modules/search/search_methods_test.py +2 -2
- {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/METADATA +4 -4
- {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/RECORD +88 -57
- distributed/Dockerfile +34 -0
- distributed/__init__.py +0 -0
- distributed/app.py +4 -0
- distributed/entrypoint.py +71 -0
- distributed/entrypoint.sh +5 -0
- distributed/modal_image.py +11 -0
- distributed/poetry.lock +12238 -0
- distributed/pyproject.toml +186 -0
- distributed/queues.py +5 -0
- distributed/tasks/__init__.py +0 -0
- distributed/tasks/queued_add_data_points.py +13 -0
- distributed/tasks/queued_add_edges.py +13 -0
- distributed/tasks/queued_add_nodes.py +13 -0
- distributed/test.py +28 -0
- distributed/utils.py +19 -0
- distributed/workers/data_point_saving_worker.py +93 -0
- distributed/workers/graph_saving_worker.py +104 -0
- cognee/infrastructure/databases/exceptions/EmbeddingException.py +0 -20
- {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/WHEEL +0 -0
- {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/licenses/NOTICE.md +0 -0
cognee/api/v1/add/add.py
CHANGED
|
@@ -134,11 +134,6 @@ async def add(
|
|
|
134
134
|
- VECTOR_DB_PROVIDER: "lancedb" (default), "chromadb", "pgvector"
|
|
135
135
|
- GRAPH_DATABASE_PROVIDER: "kuzu" (default), "neo4j", "networkx"
|
|
136
136
|
|
|
137
|
-
Raises:
|
|
138
|
-
FileNotFoundError: If specified file paths don't exist
|
|
139
|
-
PermissionError: If user lacks access to files or dataset
|
|
140
|
-
UnsupportedFileTypeError: If file format cannot be processed
|
|
141
|
-
InvalidValueError: If LLM_API_KEY is not set or invalid
|
|
142
137
|
"""
|
|
143
138
|
tasks = [
|
|
144
139
|
Task(resolve_data_directories, include_subdirectories=True),
|
cognee/api/v1/cognify/cognify.py
CHANGED
|
@@ -177,14 +177,6 @@ async def cognify(
|
|
|
177
177
|
- LLM_PROVIDER, LLM_MODEL, VECTOR_DB_PROVIDER, GRAPH_DATABASE_PROVIDER
|
|
178
178
|
- LLM_RATE_LIMIT_ENABLED: Enable rate limiting (default: False)
|
|
179
179
|
- LLM_RATE_LIMIT_REQUESTS: Max requests per interval (default: 60)
|
|
180
|
-
|
|
181
|
-
Raises:
|
|
182
|
-
DatasetNotFoundError: If specified datasets don't exist
|
|
183
|
-
PermissionError: If user lacks processing rights
|
|
184
|
-
InvalidValueError: If LLM_API_KEY is not set
|
|
185
|
-
OntologyParsingError: If ontology file is malformed
|
|
186
|
-
ValueError: If chunks exceed max token limits (reduce chunk_size)
|
|
187
|
-
DatabaseNotCreatedError: If databases are not properly initialized
|
|
188
180
|
"""
|
|
189
181
|
tasks = await get_default_tasks(user, graph_model, chunker, chunk_size, ontology_file_path)
|
|
190
182
|
|
cognee/api/v1/config/config.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
from cognee.base_config import get_base_config
|
|
5
|
-
from cognee.exceptions import InvalidValueError, InvalidAttributeError
|
|
6
5
|
from cognee.modules.cognify.config import get_cognify_config
|
|
7
6
|
from cognee.infrastructure.data.chunking.config import get_chunk_config
|
|
8
7
|
from cognee.infrastructure.databases.vector import get_vectordb_config
|
|
@@ -11,6 +10,7 @@ from cognee.infrastructure.llm.config import (
|
|
|
11
10
|
get_llm_config,
|
|
12
11
|
)
|
|
13
12
|
from cognee.infrastructure.databases.relational import get_relational_config, get_migration_config
|
|
13
|
+
from cognee.api.v1.exceptions.exceptions import InvalidConfigAttributeError
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class config:
|
|
@@ -92,9 +92,7 @@ class config:
|
|
|
92
92
|
if hasattr(llm_config, key):
|
|
93
93
|
object.__setattr__(llm_config, key, value)
|
|
94
94
|
else:
|
|
95
|
-
raise
|
|
96
|
-
message=f"'{key}' is not a valid attribute of the config."
|
|
97
|
-
)
|
|
95
|
+
raise InvalidConfigAttributeError(attribute=key)
|
|
98
96
|
|
|
99
97
|
@staticmethod
|
|
100
98
|
def set_chunk_strategy(chunk_strategy: object):
|
|
@@ -131,9 +129,7 @@ class config:
|
|
|
131
129
|
if hasattr(relational_db_config, key):
|
|
132
130
|
object.__setattr__(relational_db_config, key, value)
|
|
133
131
|
else:
|
|
134
|
-
raise
|
|
135
|
-
message=f"'{key}' is not a valid attribute of the config."
|
|
136
|
-
)
|
|
132
|
+
raise InvalidConfigAttributeError(attribute=key)
|
|
137
133
|
|
|
138
134
|
@staticmethod
|
|
139
135
|
def set_migration_db_config(config_dict: dict):
|
|
@@ -145,9 +141,7 @@ class config:
|
|
|
145
141
|
if hasattr(migration_db_config, key):
|
|
146
142
|
object.__setattr__(migration_db_config, key, value)
|
|
147
143
|
else:
|
|
148
|
-
raise
|
|
149
|
-
message=f"'{key}' is not a valid attribute of the config."
|
|
150
|
-
)
|
|
144
|
+
raise InvalidConfigAttributeError(attribute=key)
|
|
151
145
|
|
|
152
146
|
@staticmethod
|
|
153
147
|
def set_graph_db_config(config_dict: dict) -> None:
|
|
@@ -171,9 +165,7 @@ class config:
|
|
|
171
165
|
if hasattr(vector_db_config, key):
|
|
172
166
|
object.__setattr__(vector_db_config, key, value)
|
|
173
167
|
else:
|
|
174
|
-
|
|
175
|
-
message=f"'{key}' is not a valid attribute of the config."
|
|
176
|
-
)
|
|
168
|
+
InvalidConfigAttributeError(attribute=key)
|
|
177
169
|
|
|
178
170
|
@staticmethod
|
|
179
171
|
def set_vector_db_key(db_key: str):
|
|
@@ -13,7 +13,7 @@ from cognee.infrastructure.databases.relational import get_relational_engine
|
|
|
13
13
|
from cognee.modules.data.methods import get_authorized_existing_datasets
|
|
14
14
|
from cognee.modules.data.methods import create_dataset, get_datasets_by_name
|
|
15
15
|
from cognee.shared.logging_utils import get_logger
|
|
16
|
-
from cognee.api.v1.
|
|
16
|
+
from cognee.api.v1.exceptions import DataNotFoundError, DatasetNotFoundError
|
|
17
17
|
from cognee.modules.users.models import User
|
|
18
18
|
from cognee.modules.users.methods import get_authenticated_user
|
|
19
19
|
from cognee.modules.users.permissions.methods import (
|
cognee/api/v1/delete/delete.py
CHANGED
|
@@ -16,7 +16,7 @@ from cognee.modules.users.methods import get_default_user
|
|
|
16
16
|
from cognee.modules.data.methods import get_authorized_existing_datasets
|
|
17
17
|
from cognee.context_global_variables import set_database_global_context_variables
|
|
18
18
|
|
|
19
|
-
from cognee.api.v1.
|
|
19
|
+
from cognee.api.v1.exceptions import (
|
|
20
20
|
DocumentNotFoundError,
|
|
21
21
|
DatasetNotFoundError,
|
|
22
22
|
DocumentSubgraphNotFoundError,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom exceptions for the Cognee API.
|
|
3
|
+
|
|
4
|
+
This module defines a set of exceptions for handling various data errors
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
InvalidConfigAttributeError,
|
|
9
|
+
DocumentNotFoundError,
|
|
10
|
+
DatasetNotFoundError,
|
|
11
|
+
DataNotFoundError,
|
|
12
|
+
DocumentSubgraphNotFoundError,
|
|
13
|
+
)
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeConfigurationError, CogneeValidationError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class
|
|
6
|
-
|
|
5
|
+
class InvalidConfigAttributeError(CogneeConfigurationError):
|
|
6
|
+
def __init__(
|
|
7
|
+
self,
|
|
8
|
+
attribute: str,
|
|
9
|
+
name: str = "InvalidConfigAttributeError",
|
|
10
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
11
|
+
):
|
|
12
|
+
message = f"'{attribute}' is not a valid attribute of the configuration."
|
|
13
|
+
super().__init__(message, name, status_code)
|
|
7
14
|
|
|
15
|
+
|
|
16
|
+
class DocumentNotFoundError(CogneeValidationError):
|
|
8
17
|
def __init__(
|
|
9
18
|
self,
|
|
10
19
|
message: str = "Document not found in database.",
|
|
@@ -14,9 +23,7 @@ class DocumentNotFoundError(CogneeApiError):
|
|
|
14
23
|
super().__init__(message, name, status_code)
|
|
15
24
|
|
|
16
25
|
|
|
17
|
-
class DatasetNotFoundError(
|
|
18
|
-
"""Raised when a dataset cannot be found."""
|
|
19
|
-
|
|
26
|
+
class DatasetNotFoundError(CogneeValidationError):
|
|
20
27
|
def __init__(
|
|
21
28
|
self,
|
|
22
29
|
message: str = "Dataset not found.",
|
|
@@ -26,9 +33,7 @@ class DatasetNotFoundError(CogneeApiError):
|
|
|
26
33
|
super().__init__(message, name, status_code)
|
|
27
34
|
|
|
28
35
|
|
|
29
|
-
class DataNotFoundError(
|
|
30
|
-
"""Raised when a dataset cannot be found."""
|
|
31
|
-
|
|
36
|
+
class DataNotFoundError(CogneeValidationError):
|
|
32
37
|
def __init__(
|
|
33
38
|
self,
|
|
34
39
|
message: str = "Data not found.",
|
|
@@ -38,9 +43,7 @@ class DataNotFoundError(CogneeApiError):
|
|
|
38
43
|
super().__init__(message, name, status_code)
|
|
39
44
|
|
|
40
45
|
|
|
41
|
-
class DocumentSubgraphNotFoundError(
|
|
42
|
-
"""Raised when a document's subgraph cannot be found in the graph database."""
|
|
43
|
-
|
|
46
|
+
class DocumentSubgraphNotFoundError(CogneeValidationError):
|
|
44
47
|
def __init__(
|
|
45
48
|
self,
|
|
46
49
|
message: str = "Document subgraph not found in graph database.",
|
cognee/api/v1/search/search.py
CHANGED
|
@@ -158,13 +158,6 @@ async def search(
|
|
|
158
158
|
- VECTOR_DB_PROVIDER: Must match what was used during cognify
|
|
159
159
|
- GRAPH_DATABASE_PROVIDER: Must match what was used during cognify
|
|
160
160
|
|
|
161
|
-
Raises:
|
|
162
|
-
DatasetNotFoundError: If specified datasets don't exist or aren't accessible
|
|
163
|
-
PermissionDeniedError: If user lacks read access to requested datasets
|
|
164
|
-
NoDataError: If no relevant data found for the search query
|
|
165
|
-
InvalidValueError: If LLM_API_KEY is not set (for LLM-based search types)
|
|
166
|
-
ValueError: If query_text is empty or search parameters are invalid
|
|
167
|
-
CollectionNotFoundError: If vector collection not found (data not processed)
|
|
168
161
|
"""
|
|
169
162
|
# We use lists from now on for datasets
|
|
170
163
|
if isinstance(datasets, UUID) or isinstance(datasets, str):
|
cognee/exceptions/__init__.py
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Custom exceptions for the Cognee API.
|
|
3
3
|
|
|
4
4
|
This module defines a set of exceptions for handling various application errors,
|
|
5
|
-
such as
|
|
5
|
+
such as System, Validation, Configuration or TransientErrors
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from .exceptions import (
|
|
9
9
|
CogneeApiError,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
CogneeSystemError,
|
|
11
|
+
CogneeValidationError,
|
|
12
|
+
CogneeConfigurationError,
|
|
13
|
+
CogneeTransientError,
|
|
14
14
|
)
|
cognee/exceptions/exceptions.py
CHANGED
|
@@ -35,37 +35,57 @@ class CogneeApiError(Exception):
|
|
|
35
35
|
return f"{self.name}: {self.message} (Status code: {self.status_code})"
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
class
|
|
39
|
-
"""
|
|
38
|
+
class CogneeSystemError(CogneeApiError):
|
|
39
|
+
"""System error"""
|
|
40
40
|
|
|
41
41
|
def __init__(
|
|
42
42
|
self,
|
|
43
|
-
message: str = "
|
|
44
|
-
name: str = "
|
|
45
|
-
status_code=status.
|
|
43
|
+
message: str = "A system error occurred.",
|
|
44
|
+
name: str = "CogneeSystemError",
|
|
45
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
46
|
+
log=True,
|
|
47
|
+
log_level="ERROR",
|
|
46
48
|
):
|
|
47
|
-
super().__init__(message, name, status_code)
|
|
49
|
+
super().__init__(message, name, status_code, log, log_level)
|
|
50
|
+
|
|
48
51
|
|
|
52
|
+
class CogneeValidationError(CogneeApiError):
|
|
53
|
+
"""Validation error"""
|
|
49
54
|
|
|
50
|
-
class InvalidValueError(CogneeApiError):
|
|
51
55
|
def __init__(
|
|
52
56
|
self,
|
|
53
|
-
message: str = "
|
|
54
|
-
name: str = "
|
|
57
|
+
message: str = "A validation error occurred.",
|
|
58
|
+
name: str = "CogneeValidationError",
|
|
55
59
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
60
|
+
log=True,
|
|
61
|
+
log_level="ERROR",
|
|
56
62
|
):
|
|
57
|
-
super().__init__(message, name, status_code)
|
|
63
|
+
super().__init__(message, name, status_code, log, log_level)
|
|
58
64
|
|
|
59
65
|
|
|
60
|
-
class
|
|
66
|
+
class CogneeConfigurationError(CogneeApiError):
|
|
67
|
+
"""SystemConfigError"""
|
|
68
|
+
|
|
61
69
|
def __init__(
|
|
62
70
|
self,
|
|
63
|
-
message: str = "
|
|
64
|
-
name: str = "
|
|
65
|
-
status_code=status.
|
|
71
|
+
message: str = "A system configuration error occurred.",
|
|
72
|
+
name: str = "CogneeConfigurationError",
|
|
73
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
74
|
+
log=True,
|
|
75
|
+
log_level="ERROR",
|
|
66
76
|
):
|
|
67
|
-
super().__init__(message, name, status_code)
|
|
77
|
+
super().__init__(message, name, status_code, log, log_level)
|
|
68
78
|
|
|
69
79
|
|
|
70
|
-
class
|
|
71
|
-
|
|
80
|
+
class CogneeTransientError(CogneeApiError):
|
|
81
|
+
"""TransientError"""
|
|
82
|
+
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
message: str = "A transient error occurred.",
|
|
86
|
+
name: str = "CogneeTransientError",
|
|
87
|
+
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
88
|
+
log=True,
|
|
89
|
+
log_level="ERROR",
|
|
90
|
+
):
|
|
91
|
+
super().__init__(message, name, status_code, log, log_level)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from cognee.exceptions import (
|
|
2
|
+
CogneeValidationError,
|
|
3
|
+
)
|
|
4
|
+
from fastapi import status
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class KeywordExtractionError(CogneeValidationError):
|
|
8
|
+
"""
|
|
9
|
+
Raised when a provided value is syntactically valid but semantically unacceptable
|
|
10
|
+
for the given operation.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
- Passing an empty string to a keyword extraction function.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
message: str = "Extract_keywords cannot extract keywords from empty text.",
|
|
19
|
+
name: str = "KeywordExtractionError",
|
|
20
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
21
|
+
):
|
|
22
|
+
super().__init__(message, name, status_code)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
2
2
|
|
|
3
|
-
from cognee.exceptions import
|
|
3
|
+
from cognee.infrastructure.data.exceptions.exceptions import KeywordExtractionError
|
|
4
4
|
from cognee.shared.utils import extract_pos_tags
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ def extract_keywords(text: str) -> list[str]:
|
|
|
8
8
|
"""
|
|
9
9
|
Extract keywords from the provided text string.
|
|
10
10
|
|
|
11
|
-
This function raises an
|
|
11
|
+
This function raises an KeyWordExtractionError if the input text is empty. It processes the
|
|
12
12
|
text to extract parts of speech, focusing on nouns, and uses TF-IDF to identify the most
|
|
13
13
|
relevant keywords based on their frequency. The function returns a list of up to 15
|
|
14
14
|
keywords, each having more than 3 characters.
|
|
@@ -25,7 +25,7 @@ def extract_keywords(text: str) -> list[str]:
|
|
|
25
25
|
with more than 3 characters.
|
|
26
26
|
"""
|
|
27
27
|
if len(text) == 0:
|
|
28
|
-
raise
|
|
28
|
+
raise KeywordExtractionError()
|
|
29
29
|
|
|
30
30
|
tags = extract_pos_tags(text)
|
|
31
31
|
nouns = [word for (word, tag) in tags if tag == "NN"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
from fastapi import status
|
|
2
|
-
from cognee.exceptions import
|
|
2
|
+
from cognee.exceptions import CogneeSystemError, CogneeValidationError, CogneeConfigurationError
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class DatabaseNotCreatedError(
|
|
5
|
+
class DatabaseNotCreatedError(CogneeSystemError):
|
|
6
6
|
"""
|
|
7
7
|
Represents an error indicating that the database has not been created. This error should
|
|
8
8
|
be raised when an attempt is made to access the database before it has been initialized.
|
|
9
9
|
|
|
10
|
-
Inherits from
|
|
10
|
+
Inherits from CogneeSystemError. Overrides the constructor to include a default message and
|
|
11
11
|
status code.
|
|
12
12
|
"""
|
|
13
13
|
|
|
@@ -20,10 +20,10 @@ class DatabaseNotCreatedError(CriticalError):
|
|
|
20
20
|
super().__init__(message, name, status_code)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
class EntityNotFoundError(
|
|
23
|
+
class EntityNotFoundError(CogneeValidationError):
|
|
24
24
|
"""
|
|
25
25
|
Represents an error when a requested entity is not found in the database. This class
|
|
26
|
-
inherits from
|
|
26
|
+
inherits from CogneeValidationError.
|
|
27
27
|
|
|
28
28
|
Public methods:
|
|
29
29
|
|
|
@@ -49,11 +49,11 @@ class EntityNotFoundError(CogneeApiError):
|
|
|
49
49
|
# super().__init__(message, name, status_code) :TODO: This is not an error anymore with the dynamic exception handling therefore we shouldn't log error
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
class EntityAlreadyExistsError(
|
|
52
|
+
class EntityAlreadyExistsError(CogneeValidationError):
|
|
53
53
|
"""
|
|
54
54
|
Represents an error when an entity creation is attempted but the entity already exists.
|
|
55
55
|
|
|
56
|
-
This class is derived from
|
|
56
|
+
This class is derived from CogneeValidationError and is used to signal a conflict in operations
|
|
57
57
|
involving resource creation.
|
|
58
58
|
"""
|
|
59
59
|
|
|
@@ -66,11 +66,11 @@ class EntityAlreadyExistsError(CogneeApiError):
|
|
|
66
66
|
super().__init__(message, name, status_code)
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
class NodesetFilterNotSupportedError(
|
|
69
|
+
class NodesetFilterNotSupportedError(CogneeConfigurationError):
|
|
70
70
|
"""
|
|
71
71
|
Raise an exception when a nodeset filter is not supported by the current database.
|
|
72
72
|
|
|
73
|
-
This exception inherits from `
|
|
73
|
+
This exception inherits from `CogneeConfigurationError` and is designed to provide information
|
|
74
74
|
about the specific issue of unsupported nodeset filters in the context of graph
|
|
75
75
|
databases.
|
|
76
76
|
"""
|
|
@@ -84,3 +84,51 @@ class NodesetFilterNotSupportedError(CogneeApiError):
|
|
|
84
84
|
self.message = message
|
|
85
85
|
self.name = name
|
|
86
86
|
self.status_code = status_code
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class EmbeddingException(CogneeConfigurationError):
|
|
90
|
+
"""
|
|
91
|
+
Custom exception for handling embedding-related errors.
|
|
92
|
+
|
|
93
|
+
This exception class is designed to indicate issues specifically related to embeddings
|
|
94
|
+
within the application. It extends the base exception class CogneeConfigurationError allows
|
|
95
|
+
for customization of the error message, name, and status code.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
def __init__(
|
|
99
|
+
self,
|
|
100
|
+
message: str = "Embedding Exception.",
|
|
101
|
+
name: str = "EmbeddingException",
|
|
102
|
+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
103
|
+
):
|
|
104
|
+
super().__init__(message, name, status_code)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class MissingQueryParameterError(CogneeValidationError):
|
|
108
|
+
"""
|
|
109
|
+
Raised when neither 'query_text' nor 'query_vector' is provided,
|
|
110
|
+
and at least one is required to perform the operation.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
def __init__(
|
|
114
|
+
self,
|
|
115
|
+
name: str = "MissingQueryParameterError",
|
|
116
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
117
|
+
):
|
|
118
|
+
message = "One of query_text or query_vector must be provided!"
|
|
119
|
+
super().__init__(message, name, status_code)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class MutuallyExclusiveQueryParametersError(CogneeValidationError):
|
|
123
|
+
"""
|
|
124
|
+
Raised when both 'text' and 'embedding' are provided to the search function,
|
|
125
|
+
but only one type of input is allowed at a time.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __init__(
|
|
129
|
+
self,
|
|
130
|
+
name: str = "MutuallyExclusiveQueryParametersError",
|
|
131
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
132
|
+
):
|
|
133
|
+
message = "The search function accepts either text or embedding as input, but not both."
|
|
134
|
+
super().__init__(message, name, status_code)
|
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
This module defines custom exceptions for Neptune Analytics operations.
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from cognee.exceptions import
|
|
6
|
+
from cognee.exceptions import (
|
|
7
|
+
CogneeSystemError,
|
|
8
|
+
CogneeTransientError,
|
|
9
|
+
CogneeValidationError,
|
|
10
|
+
CogneeConfigurationError,
|
|
11
|
+
)
|
|
7
12
|
from fastapi import status
|
|
8
13
|
|
|
9
14
|
|
|
10
|
-
class NeptuneAnalyticsError(
|
|
15
|
+
class NeptuneAnalyticsError(CogneeSystemError):
|
|
11
16
|
"""Base exception for Neptune Analytics operations."""
|
|
12
17
|
|
|
13
18
|
def __init__(
|
|
@@ -19,7 +24,7 @@ class NeptuneAnalyticsError(CogneeApiError):
|
|
|
19
24
|
super().__init__(message, name, status_code)
|
|
20
25
|
|
|
21
26
|
|
|
22
|
-
class NeptuneAnalyticsConnectionError(
|
|
27
|
+
class NeptuneAnalyticsConnectionError(CogneeTransientError):
|
|
23
28
|
"""Exception raised when connection to Neptune Analytics fails."""
|
|
24
29
|
|
|
25
30
|
def __init__(
|
|
@@ -31,7 +36,7 @@ class NeptuneAnalyticsConnectionError(NeptuneAnalyticsError):
|
|
|
31
36
|
super().__init__(message, name, status_code)
|
|
32
37
|
|
|
33
38
|
|
|
34
|
-
class NeptuneAnalyticsQueryError(
|
|
39
|
+
class NeptuneAnalyticsQueryError(CogneeValidationError):
|
|
35
40
|
"""Exception raised when a query execution fails."""
|
|
36
41
|
|
|
37
42
|
def __init__(
|
|
@@ -43,7 +48,7 @@ class NeptuneAnalyticsQueryError(NeptuneAnalyticsError):
|
|
|
43
48
|
super().__init__(message, name, status_code)
|
|
44
49
|
|
|
45
50
|
|
|
46
|
-
class NeptuneAnalyticsAuthenticationError(
|
|
51
|
+
class NeptuneAnalyticsAuthenticationError(CogneeConfigurationError):
|
|
47
52
|
"""Exception raised when authentication with Neptune Analytics fails."""
|
|
48
53
|
|
|
49
54
|
def __init__(
|
|
@@ -55,7 +60,7 @@ class NeptuneAnalyticsAuthenticationError(NeptuneAnalyticsError):
|
|
|
55
60
|
super().__init__(message, name, status_code)
|
|
56
61
|
|
|
57
62
|
|
|
58
|
-
class NeptuneAnalyticsConfigurationError(
|
|
63
|
+
class NeptuneAnalyticsConfigurationError(CogneeConfigurationError):
|
|
59
64
|
"""Exception raised when Neptune Analytics configuration is invalid."""
|
|
60
65
|
|
|
61
66
|
def __init__(
|
|
@@ -67,7 +72,7 @@ class NeptuneAnalyticsConfigurationError(NeptuneAnalyticsError):
|
|
|
67
72
|
super().__init__(message, name, status_code)
|
|
68
73
|
|
|
69
74
|
|
|
70
|
-
class NeptuneAnalyticsTimeoutError(
|
|
75
|
+
class NeptuneAnalyticsTimeoutError(CogneeTransientError):
|
|
71
76
|
"""Exception raised when a Neptune Analytics operation times out."""
|
|
72
77
|
|
|
73
78
|
def __init__(
|
|
@@ -79,7 +84,7 @@ class NeptuneAnalyticsTimeoutError(NeptuneAnalyticsError):
|
|
|
79
84
|
super().__init__(message, name, status_code)
|
|
80
85
|
|
|
81
86
|
|
|
82
|
-
class NeptuneAnalyticsThrottlingError(
|
|
87
|
+
class NeptuneAnalyticsThrottlingError(CogneeTransientError):
|
|
83
88
|
"""Exception raised when requests are throttled by Neptune Analytics."""
|
|
84
89
|
|
|
85
90
|
def __init__(
|
|
@@ -91,7 +96,7 @@ class NeptuneAnalyticsThrottlingError(NeptuneAnalyticsError):
|
|
|
91
96
|
super().__init__(message, name, status_code)
|
|
92
97
|
|
|
93
98
|
|
|
94
|
-
class NeptuneAnalyticsResourceNotFoundError(
|
|
99
|
+
class NeptuneAnalyticsResourceNotFoundError(CogneeValidationError):
|
|
95
100
|
"""Exception raised when a Neptune Analytics resource is not found."""
|
|
96
101
|
|
|
97
102
|
def __init__(
|
|
@@ -103,7 +108,7 @@ class NeptuneAnalyticsResourceNotFoundError(NeptuneAnalyticsError):
|
|
|
103
108
|
super().__init__(message, name, status_code)
|
|
104
109
|
|
|
105
110
|
|
|
106
|
-
class NeptuneAnalyticsInvalidParameterError(
|
|
111
|
+
class NeptuneAnalyticsInvalidParameterError(CogneeValidationError):
|
|
107
112
|
"""Exception raised when invalid parameters are provided to Neptune Analytics."""
|
|
108
113
|
|
|
109
114
|
def __init__(
|
|
@@ -9,7 +9,7 @@ from typing import List, Dict, Any, Optional, Tuple, Type, Union
|
|
|
9
9
|
|
|
10
10
|
from falkordb import FalkorDB
|
|
11
11
|
|
|
12
|
-
from cognee.exceptions import
|
|
12
|
+
from cognee.infrastructure.databases.exceptions import MissingQueryParameterError
|
|
13
13
|
from cognee.infrastructure.databases.graph.graph_db_interface import (
|
|
14
14
|
GraphDBInterface,
|
|
15
15
|
record_graph_changes,
|
|
@@ -721,7 +721,7 @@ class FalkorDBAdapter(VectorDBInterface, GraphDBInterface):
|
|
|
721
721
|
Returns the search results as a result set from the graph database.
|
|
722
722
|
"""
|
|
723
723
|
if query_text is None and query_vector is None:
|
|
724
|
-
raise
|
|
724
|
+
raise MissingQueryParameterError()
|
|
725
725
|
|
|
726
726
|
if query_text and not query_vector:
|
|
727
727
|
query_vector = (await self.embed_data([query_text]))[0]
|
|
@@ -5,7 +5,8 @@ import json
|
|
|
5
5
|
from typing import List, Optional, Any, Dict, Type, Tuple
|
|
6
6
|
from uuid import UUID
|
|
7
7
|
|
|
8
|
-
from cognee.exceptions import
|
|
8
|
+
from cognee.infrastructure.databases.exceptions import MissingQueryParameterError
|
|
9
|
+
from cognee.infrastructure.databases.exceptions import MutuallyExclusiveQueryParametersError
|
|
9
10
|
from cognee.infrastructure.databases.graph.neptune_driver.adapter import NeptuneGraphDB
|
|
10
11
|
from cognee.infrastructure.databases.vector.vector_db_interface import VectorDBInterface
|
|
11
12
|
from cognee.infrastructure.engine import DataPoint
|
|
@@ -274,11 +275,9 @@ class NeptuneAnalyticsAdapter(NeptuneGraphDB, VectorDBInterface):
|
|
|
274
275
|
limit = self._TOPK_UPPER_BOUND
|
|
275
276
|
|
|
276
277
|
if query_vector and query_text:
|
|
277
|
-
raise
|
|
278
|
-
message="The search function accepts either text or embedding as input, but not both."
|
|
279
|
-
)
|
|
278
|
+
raise MutuallyExclusiveQueryParametersError()
|
|
280
279
|
elif query_text is None and query_vector is None:
|
|
281
|
-
raise
|
|
280
|
+
raise MissingQueryParameterError()
|
|
282
281
|
elif query_vector:
|
|
283
282
|
embedding = query_vector
|
|
284
283
|
else:
|
|
@@ -4,13 +4,13 @@ from uuid import UUID
|
|
|
4
4
|
from typing import List, Optional
|
|
5
5
|
from chromadb import AsyncHttpClient, Settings
|
|
6
6
|
|
|
7
|
-
from cognee.exceptions import InvalidValueError
|
|
8
7
|
from cognee.shared.logging_utils import get_logger
|
|
9
8
|
from cognee.modules.storage.utils import get_own_properties
|
|
10
9
|
from cognee.infrastructure.engine import DataPoint
|
|
11
10
|
from cognee.infrastructure.engine.utils import parse_id
|
|
12
11
|
from cognee.infrastructure.databases.vector.exceptions import CollectionNotFoundError
|
|
13
12
|
from cognee.infrastructure.databases.vector.models.ScoredResult import ScoredResult
|
|
13
|
+
from cognee.infrastructure.databases.exceptions import MissingQueryParameterError
|
|
14
14
|
|
|
15
15
|
from ..embeddings.EmbeddingEngine import EmbeddingEngine
|
|
16
16
|
from ..vector_db_interface import VectorDBInterface
|
|
@@ -378,7 +378,7 @@ class ChromaDBAdapter(VectorDBInterface):
|
|
|
378
378
|
Returns a list of ScoredResult instances representing the search results.
|
|
379
379
|
"""
|
|
380
380
|
if query_text is None and query_vector is None:
|
|
381
|
-
raise
|
|
381
|
+
raise MissingQueryParameterError()
|
|
382
382
|
|
|
383
383
|
if query_text and not query_vector:
|
|
384
384
|
query_vector = (await self.embedding_engine.embed_text([query_text]))[0]
|
|
@@ -6,7 +6,7 @@ import math
|
|
|
6
6
|
import litellm
|
|
7
7
|
import os
|
|
8
8
|
from cognee.infrastructure.databases.vector.embeddings.EmbeddingEngine import EmbeddingEngine
|
|
9
|
-
from cognee.infrastructure.databases.exceptions
|
|
9
|
+
from cognee.infrastructure.databases.exceptions import EmbeddingException
|
|
10
10
|
from cognee.infrastructure.llm.tokenizer.Gemini import (
|
|
11
11
|
GeminiTokenizer,
|
|
12
12
|
)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from fastapi import status
|
|
2
|
-
from cognee.exceptions import
|
|
2
|
+
from cognee.exceptions import CogneeValidationError
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class CollectionNotFoundError(
|
|
5
|
+
class CollectionNotFoundError(CogneeValidationError):
|
|
6
6
|
"""
|
|
7
7
|
Represents an error that occurs when a requested collection cannot be found.
|
|
8
8
|
|
|
9
|
-
This class extends the
|
|
9
|
+
This class extends the CogneeValidationError to handle specific cases where a requested
|
|
10
10
|
collection is unavailable. It can be initialized with a custom message and allows for
|
|
11
11
|
logging options including log level and whether to log the error.
|
|
12
12
|
"""
|