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
|
@@ -5,7 +5,7 @@ from pydantic import BaseModel
|
|
|
5
5
|
from lancedb.pydantic import LanceModel, Vector
|
|
6
6
|
from typing import Generic, List, Optional, TypeVar, Union, get_args, get_origin, get_type_hints
|
|
7
7
|
|
|
8
|
-
from cognee.exceptions import
|
|
8
|
+
from cognee.infrastructure.databases.exceptions import MissingQueryParameterError
|
|
9
9
|
from cognee.infrastructure.engine import DataPoint
|
|
10
10
|
from cognee.infrastructure.engine.utils import parse_id
|
|
11
11
|
from cognee.infrastructure.files.storage import get_file_storage
|
|
@@ -228,7 +228,7 @@ class LanceDBAdapter(VectorDBInterface):
|
|
|
228
228
|
normalized: bool = True,
|
|
229
229
|
):
|
|
230
230
|
if query_text is None and query_vector is None:
|
|
231
|
-
raise
|
|
231
|
+
raise MissingQueryParameterError()
|
|
232
232
|
|
|
233
233
|
if query_text and not query_vector:
|
|
234
234
|
query_vector = (await self.embedding_engine.embed_text([query_text]))[0]
|
|
@@ -9,7 +9,7 @@ from sqlalchemy.exc import ProgrammingError
|
|
|
9
9
|
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
|
|
10
10
|
from asyncpg import DeadlockDetectedError, DuplicateTableError, UniqueViolationError
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
from cognee.shared.logging_utils import get_logger
|
|
14
14
|
from cognee.infrastructure.engine import DataPoint
|
|
15
15
|
from cognee.infrastructure.engine.utils import parse_id
|
|
@@ -17,6 +17,7 @@ from cognee.infrastructure.databases.relational import get_relational_engine
|
|
|
17
17
|
|
|
18
18
|
from distributed.utils import override_distributed
|
|
19
19
|
from distributed.tasks.queued_add_data_points import queued_add_data_points
|
|
20
|
+
from cognee.infrastructure.databases.exceptions import MissingQueryParameterError
|
|
20
21
|
|
|
21
22
|
from ...relational.ModelBase import Base
|
|
22
23
|
from ...relational.sqlalchemy.SqlAlchemyAdapter import SQLAlchemyAdapter
|
|
@@ -275,7 +276,7 @@ class PGVectorAdapter(SQLAlchemyAdapter, VectorDBInterface):
|
|
|
275
276
|
return metadata.tables[collection_name]
|
|
276
277
|
else:
|
|
277
278
|
raise CollectionNotFoundError(
|
|
278
|
-
f"Collection '{collection_name}' not found!",
|
|
279
|
+
f"Collection '{collection_name}' not found!",
|
|
279
280
|
)
|
|
280
281
|
|
|
281
282
|
async def retrieve(self, collection_name: str, data_point_ids: List[str]):
|
|
@@ -302,7 +303,7 @@ class PGVectorAdapter(SQLAlchemyAdapter, VectorDBInterface):
|
|
|
302
303
|
with_vector: bool = False,
|
|
303
304
|
) -> List[ScoredResult]:
|
|
304
305
|
if query_text is None and query_vector is None:
|
|
305
|
-
raise
|
|
306
|
+
raise MissingQueryParameterError()
|
|
306
307
|
|
|
307
308
|
if query_text and not query_vector:
|
|
308
309
|
query_vector = (await self.embedding_engine.embed_text([query_text]))[0]
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
from cognee.exceptions.exceptions import
|
|
1
|
+
from cognee.exceptions.exceptions import CogneeValidationError
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
class ContentPolicyFilterError(
|
|
4
|
+
class ContentPolicyFilterError(CogneeValidationError):
|
|
5
5
|
pass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LLMAPIKeyNotSetError(CogneeValidationError):
|
|
9
|
+
"""
|
|
10
|
+
Raised when the LLM API key is not set in the configuration.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, message: str = "LLM API key is not set."):
|
|
14
|
+
super().__init__(message=message, name="LLMAPIKeyNotSetError")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class UnsupportedLLMProviderError(CogneeValidationError):
|
|
18
|
+
"""
|
|
19
|
+
Raised when an unsupported LLM provider is specified in the configuration.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, provider: str):
|
|
23
|
+
message = f"Unsupported LLM provider: {provider}"
|
|
24
|
+
super().__init__(message=message, name="UnsupportedLLMProviderError")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class MissingSystemPromptPathError(CogneeValidationError):
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
name: str = "MissingSystemPromptPathError",
|
|
31
|
+
):
|
|
32
|
+
message = "No system prompt path provided."
|
|
33
|
+
super().__init__(message, name)
|
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py
CHANGED
|
@@ -2,7 +2,7 @@ from typing import Type
|
|
|
2
2
|
from pydantic import BaseModel
|
|
3
3
|
import instructor
|
|
4
4
|
|
|
5
|
-
from cognee.exceptions import
|
|
5
|
+
from cognee.infrastructure.llm.exceptions import MissingSystemPromptPathError
|
|
6
6
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import (
|
|
7
7
|
LLMInterface,
|
|
8
8
|
)
|
|
@@ -89,7 +89,7 @@ class AnthropicAdapter(LLMInterface):
|
|
|
89
89
|
if not text_input:
|
|
90
90
|
text_input = "No user input provided."
|
|
91
91
|
if not system_prompt:
|
|
92
|
-
raise
|
|
92
|
+
raise MissingSystemPromptPathError()
|
|
93
93
|
|
|
94
94
|
system_prompt = LLMGateway.read_query_prompt(system_prompt)
|
|
95
95
|
|
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py
CHANGED
|
@@ -5,7 +5,7 @@ from litellm import acompletion, JSONSchemaValidationError
|
|
|
5
5
|
|
|
6
6
|
from cognee.shared.logging_utils import get_logger
|
|
7
7
|
from cognee.modules.observability.get_observe import get_observe
|
|
8
|
-
from cognee.exceptions import
|
|
8
|
+
from cognee.infrastructure.llm.exceptions import MissingSystemPromptPathError
|
|
9
9
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import (
|
|
10
10
|
LLMInterface,
|
|
11
11
|
)
|
|
@@ -118,7 +118,7 @@ class GeminiAdapter(LLMInterface):
|
|
|
118
118
|
"""
|
|
119
119
|
Format and display the prompt for a user query.
|
|
120
120
|
|
|
121
|
-
Raises an
|
|
121
|
+
Raises an MissingQueryParameterError if no system prompt is provided.
|
|
122
122
|
|
|
123
123
|
Parameters:
|
|
124
124
|
-----------
|
|
@@ -135,7 +135,7 @@ class GeminiAdapter(LLMInterface):
|
|
|
135
135
|
if not text_input:
|
|
136
136
|
text_input = "No user input provided."
|
|
137
137
|
if not system_prompt:
|
|
138
|
-
raise
|
|
138
|
+
raise MissingSystemPromptPathError()
|
|
139
139
|
system_prompt = LLMGateway.read_query_prompt(system_prompt)
|
|
140
140
|
|
|
141
141
|
formatted_prompt = (
|
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
|
|
5
|
-
from cognee.exceptions import InvalidValueError
|
|
6
5
|
from cognee.infrastructure.llm import get_llm_config
|
|
7
6
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.ollama.adapter import (
|
|
8
7
|
OllamaAPIAdapter,
|
|
9
8
|
)
|
|
9
|
+
from cognee.infrastructure.llm.exceptions import (
|
|
10
|
+
LLMAPIKeyNotSetError,
|
|
11
|
+
UnsupportedLLMProviderError,
|
|
12
|
+
)
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
# Define an Enum for LLM Providers
|
|
@@ -35,7 +38,7 @@ def get_llm_client():
|
|
|
35
38
|
|
|
36
39
|
This function retrieves the configuration for the LLM provider and model, and
|
|
37
40
|
initializes the appropriate LLM client adapter accordingly. It raises an
|
|
38
|
-
|
|
41
|
+
LLMAPIKeyNotSetError if the LLM API key is not set for certain providers or if the provider
|
|
39
42
|
is unsupported.
|
|
40
43
|
|
|
41
44
|
Returns:
|
|
@@ -59,7 +62,7 @@ def get_llm_client():
|
|
|
59
62
|
|
|
60
63
|
if provider == LLMProvider.OPENAI:
|
|
61
64
|
if llm_config.llm_api_key is None:
|
|
62
|
-
raise
|
|
65
|
+
raise LLMAPIKeyNotSetError()
|
|
63
66
|
|
|
64
67
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.openai.adapter import (
|
|
65
68
|
OpenAIAdapter,
|
|
@@ -80,7 +83,7 @@ def get_llm_client():
|
|
|
80
83
|
|
|
81
84
|
elif provider == LLMProvider.OLLAMA:
|
|
82
85
|
if llm_config.llm_api_key is None:
|
|
83
|
-
raise
|
|
86
|
+
raise LLMAPIKeyNotSetError()
|
|
84
87
|
|
|
85
88
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.generic_llm_api.adapter import (
|
|
86
89
|
GenericAPIAdapter,
|
|
@@ -103,7 +106,7 @@ def get_llm_client():
|
|
|
103
106
|
|
|
104
107
|
elif provider == LLMProvider.CUSTOM:
|
|
105
108
|
if llm_config.llm_api_key is None:
|
|
106
|
-
raise
|
|
109
|
+
raise LLMAPIKeyNotSetError()
|
|
107
110
|
|
|
108
111
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.generic_llm_api.adapter import (
|
|
109
112
|
GenericAPIAdapter,
|
|
@@ -122,7 +125,7 @@ def get_llm_client():
|
|
|
122
125
|
|
|
123
126
|
elif provider == LLMProvider.GEMINI:
|
|
124
127
|
if llm_config.llm_api_key is None:
|
|
125
|
-
raise
|
|
128
|
+
raise LLMAPIKeyNotSetError()
|
|
126
129
|
|
|
127
130
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.gemini.adapter import (
|
|
128
131
|
GeminiAdapter,
|
|
@@ -138,4 +141,4 @@ def get_llm_client():
|
|
|
138
141
|
)
|
|
139
142
|
|
|
140
143
|
else:
|
|
141
|
-
raise
|
|
144
|
+
raise UnsupportedLLMProviderError(provider)
|
cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py
CHANGED
|
@@ -7,12 +7,14 @@ from openai import ContentFilterFinishReasonError
|
|
|
7
7
|
from litellm.exceptions import ContentPolicyViolationError
|
|
8
8
|
from instructor.exceptions import InstructorRetryException
|
|
9
9
|
|
|
10
|
-
from cognee.exceptions import InvalidValueError
|
|
11
10
|
from cognee.infrastructure.llm.LLMGateway import LLMGateway
|
|
12
11
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import (
|
|
13
12
|
LLMInterface,
|
|
14
13
|
)
|
|
15
|
-
from cognee.infrastructure.llm.exceptions import
|
|
14
|
+
from cognee.infrastructure.llm.exceptions import (
|
|
15
|
+
ContentPolicyFilterError,
|
|
16
|
+
MissingSystemPromptPathError,
|
|
17
|
+
)
|
|
16
18
|
from cognee.infrastructure.files.utils.open_data_file import open_data_file
|
|
17
19
|
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.rate_limiter import (
|
|
18
20
|
rate_limit_async,
|
|
@@ -308,7 +310,7 @@ class OpenAIAdapter(LLMInterface):
|
|
|
308
310
|
Format and display the prompt for a user query.
|
|
309
311
|
|
|
310
312
|
This method formats the prompt using the provided user input and system prompt,
|
|
311
|
-
returning a string representation. Raises
|
|
313
|
+
returning a string representation. Raises MissingSystemPromptPathError if the system prompt is not
|
|
312
314
|
provided.
|
|
313
315
|
|
|
314
316
|
Parameters:
|
|
@@ -325,7 +327,7 @@ class OpenAIAdapter(LLMInterface):
|
|
|
325
327
|
if not text_input:
|
|
326
328
|
text_input = "No user input provided."
|
|
327
329
|
if not system_prompt:
|
|
328
|
-
raise
|
|
330
|
+
raise MissingSystemPromptPathError()
|
|
329
331
|
system_prompt = LLMGateway.read_query_prompt(system_prompt)
|
|
330
332
|
|
|
331
333
|
formatted_prompt = (
|
|
@@ -58,7 +58,7 @@ class LoaderInterface(ABC):
|
|
|
58
58
|
pass
|
|
59
59
|
|
|
60
60
|
@abstractmethod
|
|
61
|
-
async def load(self, file_path: str,
|
|
61
|
+
async def load(self, file_path: str, **kwargs):
|
|
62
62
|
"""
|
|
63
63
|
Load and process the file, returning standardized result.
|
|
64
64
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import (
|
|
2
|
+
CogneeValidationError,
|
|
3
|
+
CogneeConfigurationError,
|
|
4
|
+
)
|
|
2
5
|
from fastapi import status
|
|
3
6
|
|
|
4
7
|
|
|
5
|
-
class UnstructuredLibraryImportError(
|
|
8
|
+
class UnstructuredLibraryImportError(CogneeConfigurationError):
|
|
6
9
|
def __init__(
|
|
7
10
|
self,
|
|
8
11
|
message: str = "Import error. Unstructured library is not installed.",
|
|
@@ -12,7 +15,7 @@ class UnstructuredLibraryImportError(CogneeApiError):
|
|
|
12
15
|
super().__init__(message, name, status_code)
|
|
13
16
|
|
|
14
17
|
|
|
15
|
-
class UnauthorizedDataAccessError(
|
|
18
|
+
class UnauthorizedDataAccessError(CogneeValidationError):
|
|
16
19
|
def __init__(
|
|
17
20
|
self,
|
|
18
21
|
message: str = "User does not have permission to access this data.",
|
|
@@ -22,7 +25,7 @@ class UnauthorizedDataAccessError(CogneeApiError):
|
|
|
22
25
|
super().__init__(message, name, status_code)
|
|
23
26
|
|
|
24
27
|
|
|
25
|
-
class DatasetNotFoundError(
|
|
28
|
+
class DatasetNotFoundError(CogneeValidationError):
|
|
26
29
|
def __init__(
|
|
27
30
|
self,
|
|
28
31
|
message: str = "Dataset not found.",
|
|
@@ -32,7 +35,7 @@ class DatasetNotFoundError(CogneeApiError):
|
|
|
32
35
|
super().__init__(message, name, status_code)
|
|
33
36
|
|
|
34
37
|
|
|
35
|
-
class DatasetTypeError(
|
|
38
|
+
class DatasetTypeError(CogneeValidationError):
|
|
36
39
|
def __init__(
|
|
37
40
|
self,
|
|
38
41
|
message: str = "Dataset type not supported.",
|
|
@@ -40,3 +43,13 @@ class DatasetTypeError(CogneeApiError):
|
|
|
40
43
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
41
44
|
):
|
|
42
45
|
super().__init__(message, name, status_code)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class InvalidTableAttributeError(CogneeValidationError):
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
message: str = "The provided data object is missing the required '__tablename__' attribute.",
|
|
52
|
+
name: str = "InvalidTableAttributeError",
|
|
53
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
54
|
+
):
|
|
55
|
+
super().__init__(message, name, status_code)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.modules.data.exceptions.exceptions import InvalidTableAttributeError
|
|
2
2
|
from cognee.modules.data.models import Data
|
|
3
3
|
from cognee.infrastructure.databases.relational import get_relational_engine
|
|
4
4
|
|
|
@@ -13,9 +13,7 @@ async def delete_data(data: Data):
|
|
|
13
13
|
ValueError: If the data object is invalid.
|
|
14
14
|
"""
|
|
15
15
|
if not hasattr(data, "__tablename__"):
|
|
16
|
-
raise
|
|
17
|
-
message="The provided data object is missing the required '__tablename__' attribute."
|
|
18
|
-
)
|
|
16
|
+
raise InvalidTableAttributeError()
|
|
19
17
|
|
|
20
18
|
db_engine = get_relational_engine()
|
|
21
19
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeSystemError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class PyPdfInternalError(
|
|
5
|
+
class PyPdfInternalError(CogneeSystemError):
|
|
6
6
|
"""Internal pypdf error"""
|
|
7
7
|
|
|
8
8
|
def __init__(
|
|
@@ -2,8 +2,11 @@ import time
|
|
|
2
2
|
from cognee.shared.logging_utils import get_logger
|
|
3
3
|
from typing import List, Dict, Union, Optional, Type
|
|
4
4
|
|
|
5
|
-
from cognee.exceptions import
|
|
6
|
-
|
|
5
|
+
from cognee.modules.graph.exceptions import (
|
|
6
|
+
EntityNotFoundError,
|
|
7
|
+
EntityAlreadyExistsError,
|
|
8
|
+
InvalidDimensionsError,
|
|
9
|
+
)
|
|
7
10
|
from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInterface
|
|
8
11
|
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge
|
|
9
12
|
from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph
|
|
@@ -66,8 +69,7 @@ class CogneeGraph(CogneeAbstractGraph):
|
|
|
66
69
|
node_name: Optional[List[str]] = None,
|
|
67
70
|
) -> None:
|
|
68
71
|
if node_dimension < 1 or edge_dimension < 1:
|
|
69
|
-
raise
|
|
70
|
-
|
|
72
|
+
raise InvalidDimensionsError()
|
|
71
73
|
try:
|
|
72
74
|
import time
|
|
73
75
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from typing import List, Dict, Optional, Any, Union
|
|
3
|
-
|
|
4
|
-
from cognee.exceptions import InvalidValueError
|
|
3
|
+
from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
class Node:
|
|
@@ -24,7 +23,7 @@ class Node:
|
|
|
24
23
|
self, node_id: str, attributes: Optional[Dict[str, Any]] = None, dimension: int = 1
|
|
25
24
|
):
|
|
26
25
|
if dimension <= 0:
|
|
27
|
-
raise
|
|
26
|
+
raise InvalidDimensionsError()
|
|
28
27
|
self.id = node_id
|
|
29
28
|
self.attributes = attributes if attributes is not None else {}
|
|
30
29
|
self.attributes["vector_distance"] = float("inf")
|
|
@@ -58,9 +57,7 @@ class Node:
|
|
|
58
57
|
|
|
59
58
|
def is_node_alive_in_dimension(self, dimension: int) -> bool:
|
|
60
59
|
if dimension < 0 or dimension >= len(self.status):
|
|
61
|
-
raise
|
|
62
|
-
message=f"Dimension {dimension} is out of range. Valid range is 0 to {len(self.status) - 1}."
|
|
63
|
-
)
|
|
60
|
+
raise DimensionOutOfRangeError(dimension=dimension, max_index=len(self.status) - 1)
|
|
64
61
|
return self.status[dimension] == 1
|
|
65
62
|
|
|
66
63
|
def add_attribute(self, key: str, value: Any) -> None:
|
|
@@ -110,7 +107,7 @@ class Edge:
|
|
|
110
107
|
dimension: int = 1,
|
|
111
108
|
):
|
|
112
109
|
if dimension <= 0:
|
|
113
|
-
raise
|
|
110
|
+
raise InvalidDimensionsError()
|
|
114
111
|
self.node1 = node1
|
|
115
112
|
self.node2 = node2
|
|
116
113
|
self.attributes = attributes if attributes is not None else {}
|
|
@@ -120,9 +117,7 @@ class Edge:
|
|
|
120
117
|
|
|
121
118
|
def is_edge_alive_in_dimension(self, dimension: int) -> bool:
|
|
122
119
|
if dimension < 0 or dimension >= len(self.status):
|
|
123
|
-
raise
|
|
124
|
-
message=f"Dimension {dimension} is out of range. Valid range is 0 to {len(self.status) - 1}."
|
|
125
|
-
)
|
|
120
|
+
raise DimensionOutOfRangeError(dimension=dimension, max_index=len(self.status) - 1)
|
|
126
121
|
return self.status[dimension] == 1
|
|
127
122
|
|
|
128
123
|
def add_attribute(self, key: str, value: Any) -> None:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeValidationError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class EntityNotFoundError(
|
|
5
|
+
class EntityNotFoundError(CogneeValidationError):
|
|
6
6
|
"""Database returns nothing"""
|
|
7
7
|
|
|
8
8
|
def __init__(
|
|
@@ -14,7 +14,7 @@ class EntityNotFoundError(CogneeApiError):
|
|
|
14
14
|
super().__init__(message, name, status_code)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
class EntityAlreadyExistsError(
|
|
17
|
+
class EntityAlreadyExistsError(CogneeValidationError):
|
|
18
18
|
"""Conflict detected, like trying to create a resource that already exists"""
|
|
19
19
|
|
|
20
20
|
def __init__(
|
|
@@ -24,3 +24,25 @@ class EntityAlreadyExistsError(CogneeApiError):
|
|
|
24
24
|
status_code=status.HTTP_409_CONFLICT,
|
|
25
25
|
):
|
|
26
26
|
super().__init__(message, name, status_code)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class InvalidDimensionsError(CogneeValidationError):
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
name: str = "InvalidDimensionsError",
|
|
33
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
34
|
+
):
|
|
35
|
+
message = "Dimensions must be positive integers."
|
|
36
|
+
super().__init__(message, name, status_code)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class DimensionOutOfRangeError(CogneeValidationError):
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
dimension: int,
|
|
43
|
+
max_index: int,
|
|
44
|
+
name: str = "DimensionOutOfRangeError",
|
|
45
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
46
|
+
):
|
|
47
|
+
message = f"Dimension {dimension} is out of range. Valid range is 0 to {max_index}."
|
|
48
|
+
super().__init__(message, name, status_code)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeValidationError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class IngestionError(
|
|
5
|
+
class IngestionError(CogneeValidationError):
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
message: str = "Type of data sent to classify not supported.",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeSystemError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class OntologyInitializationError(
|
|
5
|
+
class OntologyInitializationError(CogneeSystemError):
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
message: str = "Ontology initialization failed",
|
|
@@ -12,7 +12,7 @@ class OntologyInitializationError(CogneeApiError):
|
|
|
12
12
|
super().__init__(message, name, status_code)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
class FindClosestMatchError(
|
|
15
|
+
class FindClosestMatchError(CogneeSystemError):
|
|
16
16
|
def __init__(
|
|
17
17
|
self,
|
|
18
18
|
message: str = "Error in find_closest_match",
|
|
@@ -22,7 +22,7 @@ class FindClosestMatchError(CogneeApiError):
|
|
|
22
22
|
super().__init__(message, name, status_code)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class GetSubgraphError(
|
|
25
|
+
class GetSubgraphError(CogneeSystemError):
|
|
26
26
|
def __init__(
|
|
27
27
|
self,
|
|
28
28
|
message: str = "Failed to retrieve subgraph",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeSystemError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class PipelineRunFailedError(
|
|
5
|
+
class PipelineRunFailedError(CogneeSystemError):
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
message: str = "Pipeline run failed.",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from fastapi import status
|
|
2
|
-
from cognee.exceptions import
|
|
2
|
+
from cognee.exceptions import CogneeValidationError, CogneeSystemError
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class SearchTypeNotSupported(
|
|
5
|
+
class SearchTypeNotSupported(CogneeValidationError):
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
message: str = "CYPHER search type not supported by the adapter.",
|
|
@@ -12,7 +12,7 @@ class SearchTypeNotSupported(CogneeApiError):
|
|
|
12
12
|
super().__init__(message, name, status_code)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
class CypherSearchError(
|
|
15
|
+
class CypherSearchError(CogneeSystemError):
|
|
16
16
|
def __init__(
|
|
17
17
|
self,
|
|
18
18
|
message: str = "An error occurred during the execution of the Cypher query.",
|
|
@@ -22,11 +22,17 @@ class CypherSearchError(CogneeApiError):
|
|
|
22
22
|
super().__init__(message, name, status_code)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class NoDataError(
|
|
26
|
-
|
|
25
|
+
class NoDataError(CogneeValidationError):
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
message: str = "No data found in the system, please add data first.",
|
|
29
|
+
name: str = "NoDataError",
|
|
30
|
+
status_code: int = status.HTTP_404_NOT_FOUND,
|
|
31
|
+
):
|
|
32
|
+
super().__init__(message, name, status_code)
|
|
27
33
|
|
|
28
34
|
|
|
29
|
-
class CollectionDistancesNotFoundError(
|
|
35
|
+
class CollectionDistancesNotFoundError(CogneeValidationError):
|
|
30
36
|
def __init__(
|
|
31
37
|
self,
|
|
32
38
|
message: str = "No collection distances found for the given query.",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from cognee.exceptions import (
|
|
2
|
+
CogneeValidationError,
|
|
3
|
+
)
|
|
4
|
+
from fastapi import status
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class UnsupportedSearchTypeError(CogneeValidationError):
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
search_type: str,
|
|
11
|
+
name: str = "UnsupportedSearchTypeError",
|
|
12
|
+
status_code: int = status.HTTP_400_BAD_REQUEST,
|
|
13
|
+
):
|
|
14
|
+
message = f"Unsupported search type: {search_type}"
|
|
15
|
+
super().__init__(message, name, status_code)
|
|
@@ -3,9 +3,8 @@ import json
|
|
|
3
3
|
import asyncio
|
|
4
4
|
from uuid import UUID
|
|
5
5
|
from typing import Callable, List, Optional, Type, Union
|
|
6
|
-
|
|
6
|
+
from cognee.modules.search.exceptions import UnsupportedSearchTypeError
|
|
7
7
|
from cognee.context_global_variables import set_database_global_context_variables
|
|
8
|
-
from cognee.exceptions import InvalidValueError
|
|
9
8
|
from cognee.modules.retrieval.chunks_retriever import ChunksRetriever
|
|
10
9
|
from cognee.modules.retrieval.insights_retriever import InsightsRetriever
|
|
11
10
|
from cognee.modules.retrieval.summaries_retriever import SummariesRetriever
|
|
@@ -136,7 +135,7 @@ async def specific_search(
|
|
|
136
135
|
search_task = search_tasks.get(query_type)
|
|
137
136
|
|
|
138
137
|
if search_task is None:
|
|
139
|
-
raise
|
|
138
|
+
raise UnsupportedSearchTypeError(str(query_type))
|
|
140
139
|
|
|
141
140
|
send_telemetry("cognee.search EXECUTION STARTED", user.id)
|
|
142
141
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeValidationError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class RoleNotFoundError(
|
|
5
|
+
class RoleNotFoundError(CogneeValidationError):
|
|
6
6
|
"""User group not found"""
|
|
7
7
|
|
|
8
8
|
def __init__(
|
|
@@ -14,7 +14,7 @@ class RoleNotFoundError(CogneeApiError):
|
|
|
14
14
|
super().__init__(message, name, status_code)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
class TenantNotFoundError(
|
|
17
|
+
class TenantNotFoundError(CogneeValidationError):
|
|
18
18
|
"""User group not found"""
|
|
19
19
|
|
|
20
20
|
def __init__(
|
|
@@ -26,7 +26,7 @@ class TenantNotFoundError(CogneeApiError):
|
|
|
26
26
|
super().__init__(message, name, status_code)
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
class UserNotFoundError(
|
|
29
|
+
class UserNotFoundError(CogneeValidationError):
|
|
30
30
|
"""User not found"""
|
|
31
31
|
|
|
32
32
|
def __init__(
|
|
@@ -38,7 +38,7 @@ class UserNotFoundError(CogneeApiError):
|
|
|
38
38
|
super().__init__(message, name, status_code)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
class PermissionDeniedError(
|
|
41
|
+
class PermissionDeniedError(CogneeValidationError):
|
|
42
42
|
def __init__(
|
|
43
43
|
self,
|
|
44
44
|
message: str = "User does not have permission on documents.",
|
|
@@ -48,7 +48,7 @@ class PermissionDeniedError(CogneeApiError):
|
|
|
48
48
|
super().__init__(message, name, status_code)
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
class PermissionNotFoundError(
|
|
51
|
+
class PermissionNotFoundError(CogneeValidationError):
|
|
52
52
|
def __init__(
|
|
53
53
|
self,
|
|
54
54
|
message: str = "Permission type does not exist.",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from cognee.exceptions import
|
|
1
|
+
from cognee.exceptions import CogneeValidationError
|
|
2
2
|
from fastapi import status
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class IngestionError(
|
|
5
|
+
class IngestionError(CogneeValidationError):
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
message: str = "Failed to load data.",
|