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.
Files changed (89) hide show
  1. cognee/api/v1/add/add.py +0 -5
  2. cognee/api/v1/cognify/cognify.py +0 -8
  3. cognee/api/v1/config/config.py +5 -13
  4. cognee/api/v1/datasets/routers/get_datasets_router.py +1 -1
  5. cognee/api/v1/delete/delete.py +1 -1
  6. cognee/api/v1/exceptions/__init__.py +13 -0
  7. cognee/api/v1/{delete → exceptions}/exceptions.py +15 -12
  8. cognee/api/v1/search/search.py +0 -7
  9. cognee/exceptions/__init__.py +5 -5
  10. cognee/exceptions/exceptions.py +37 -17
  11. cognee/infrastructure/data/exceptions/__init__.py +7 -0
  12. cognee/infrastructure/data/exceptions/exceptions.py +22 -0
  13. cognee/infrastructure/data/utils/extract_keywords.py +3 -3
  14. cognee/infrastructure/databases/exceptions/__init__.py +3 -0
  15. cognee/infrastructure/databases/exceptions/exceptions.py +57 -9
  16. cognee/infrastructure/databases/graph/neptune_driver/exceptions.py +15 -10
  17. cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py +2 -2
  18. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +4 -5
  19. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -2
  20. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +1 -1
  21. cognee/infrastructure/databases/vector/exceptions/exceptions.py +3 -3
  22. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +2 -2
  23. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +4 -3
  24. cognee/infrastructure/llm/exceptions.py +30 -2
  25. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +2 -2
  26. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +3 -3
  27. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +10 -7
  28. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +6 -4
  29. cognee/infrastructure/loaders/LoaderInterface.py +1 -1
  30. cognee/modules/data/exceptions/exceptions.py +18 -5
  31. cognee/modules/data/methods/delete_data.py +2 -4
  32. cognee/modules/data/processing/document_types/exceptions/exceptions.py +2 -2
  33. cognee/modules/graph/cognee_graph/CogneeGraph.py +6 -4
  34. cognee/modules/graph/cognee_graph/CogneeGraphElements.py +5 -10
  35. cognee/modules/graph/exceptions/__init__.py +2 -0
  36. cognee/modules/graph/exceptions/exceptions.py +25 -3
  37. cognee/modules/ingestion/exceptions/exceptions.py +2 -2
  38. cognee/modules/ontology/exceptions/exceptions.py +4 -4
  39. cognee/modules/pipelines/exceptions/exceptions.py +2 -2
  40. cognee/modules/retrieval/exceptions/exceptions.py +12 -6
  41. cognee/modules/search/exceptions/__init__.py +7 -0
  42. cognee/modules/search/exceptions/exceptions.py +15 -0
  43. cognee/modules/search/methods/search.py +2 -3
  44. cognee/modules/users/exceptions/exceptions.py +6 -6
  45. cognee/shared/exceptions/exceptions.py +2 -2
  46. cognee/tasks/completion/exceptions/exceptions.py +3 -3
  47. cognee/tasks/documents/classify_documents.py +4 -0
  48. cognee/tasks/documents/exceptions/__init__.py +11 -0
  49. cognee/tasks/documents/exceptions/exceptions.py +36 -0
  50. cognee/tasks/documents/extract_chunks_from_documents.py +8 -2
  51. cognee/tasks/graph/exceptions/__init__.py +12 -0
  52. cognee/tasks/graph/exceptions/exceptions.py +41 -0
  53. cognee/tasks/graph/extract_graph_from_data.py +28 -0
  54. cognee/tasks/ingestion/exceptions/__init__.py +8 -0
  55. cognee/tasks/ingestion/exceptions/exceptions.py +12 -0
  56. cognee/tasks/ingestion/resolve_data_directories.py +5 -0
  57. cognee/tasks/storage/add_data_points.py +8 -0
  58. cognee/tasks/storage/exceptions/__init__.py +9 -0
  59. cognee/tasks/storage/exceptions/exceptions.py +13 -0
  60. cognee/tasks/storage/index_data_points.py +1 -1
  61. cognee/tasks/summarization/exceptions/__init__.py +9 -0
  62. cognee/tasks/summarization/exceptions/exceptions.py +14 -0
  63. cognee/tasks/summarization/summarize_text.py +8 -1
  64. cognee/tests/test_delete_by_id.py +1 -1
  65. cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +5 -5
  66. cognee/tests/unit/modules/search/search_methods_test.py +2 -2
  67. {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/METADATA +4 -4
  68. {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/RECORD +88 -57
  69. distributed/Dockerfile +34 -0
  70. distributed/__init__.py +0 -0
  71. distributed/app.py +4 -0
  72. distributed/entrypoint.py +71 -0
  73. distributed/entrypoint.sh +5 -0
  74. distributed/modal_image.py +11 -0
  75. distributed/poetry.lock +12238 -0
  76. distributed/pyproject.toml +186 -0
  77. distributed/queues.py +5 -0
  78. distributed/tasks/__init__.py +0 -0
  79. distributed/tasks/queued_add_data_points.py +13 -0
  80. distributed/tasks/queued_add_edges.py +13 -0
  81. distributed/tasks/queued_add_nodes.py +13 -0
  82. distributed/test.py +28 -0
  83. distributed/utils.py +19 -0
  84. distributed/workers/data_point_saving_worker.py +93 -0
  85. distributed/workers/graph_saving_worker.py +104 -0
  86. cognee/infrastructure/databases/exceptions/EmbeddingException.py +0 -20
  87. {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/WHEEL +0 -0
  88. {cognee-0.2.2.dev1.dist-info → cognee-0.2.3.dev1.dist-info}/licenses/LICENSE +0 -0
  89. {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 InvalidValueError
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 InvalidValueError(message="One of query_text or query_vector must be provided!")
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
- from cognee.exceptions import InvalidValueError
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!", log_level="DEBUG"
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 InvalidValueError(message="One of query_text or query_vector must be provided!")
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 CriticalError
1
+ from cognee.exceptions.exceptions import CogneeValidationError
2
2
 
3
3
 
4
- class ContentPolicyFilterError(CriticalError):
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)
@@ -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 InvalidValueError
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 InvalidValueError(message="No system prompt path provided.")
92
+ raise MissingSystemPromptPathError()
93
93
 
94
94
  system_prompt = LLMGateway.read_query_prompt(system_prompt)
95
95
 
@@ -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 InvalidValueError
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 InvalidValueError if no system prompt is provided.
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 InvalidValueError(message="No system prompt path provided.")
138
+ raise MissingSystemPromptPathError()
139
139
  system_prompt = LLMGateway.read_query_prompt(system_prompt)
140
140
 
141
141
  formatted_prompt = (
@@ -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
- InvalidValueError if the LLM API key is not set for certain providers or if the provider
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 InvalidValueError(message="LLM API key is not set.")
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 InvalidValueError(message="LLM API key is not set.")
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 InvalidValueError(message="LLM API key is not set.")
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 InvalidValueError(message="LLM API key is not set.")
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 InvalidValueError(message=f"Unsupported LLM provider: {provider}")
144
+ raise UnsupportedLLMProviderError(provider)
@@ -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 ContentPolicyFilterError
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 InvalidValueError if the system prompt is not
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 InvalidValueError(message="No system prompt path provided.")
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, file_stream: Optional[Any] = None, **kwargs):
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 CogneeApiError
1
+ from cognee.exceptions import (
2
+ CogneeValidationError,
3
+ CogneeConfigurationError,
4
+ )
2
5
  from fastapi import status
3
6
 
4
7
 
5
- class UnstructuredLibraryImportError(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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 InvalidAttributeError
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 InvalidAttributeError(
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 CogneeApiError
1
+ from cognee.exceptions import CogneeSystemError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class PyPdfInternalError(CogneeApiError):
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 InvalidValueError
6
- from cognee.modules.graph.exceptions import EntityNotFoundError, EntityAlreadyExistsError
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 InvalidValueError(message="Dimensions must be positive integers")
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 InvalidValueError(message="Dimension must be a positive integer")
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 InvalidValueError(
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 InvalidValueError(message="Dimensions must be a positive integer.")
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 InvalidValueError(
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:
@@ -7,4 +7,6 @@ This module defines a set of exceptions for handling various graph errors
7
7
  from .exceptions import (
8
8
  EntityNotFoundError,
9
9
  EntityAlreadyExistsError,
10
+ InvalidDimensionsError,
11
+ DimensionOutOfRangeError,
10
12
  )
@@ -1,8 +1,8 @@
1
- from cognee.exceptions import CogneeApiError
1
+ from cognee.exceptions import CogneeValidationError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class EntityNotFoundError(CogneeApiError):
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(CogneeApiError):
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 CogneeApiError
1
+ from cognee.exceptions import CogneeValidationError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class IngestionError(CogneeApiError):
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 CogneeApiError
1
+ from cognee.exceptions import CogneeSystemError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class OntologyInitializationError(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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 CogneeApiError
1
+ from cognee.exceptions import CogneeSystemError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class PipelineRunFailedError(CogneeApiError):
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 CogneeApiError, CriticalError
2
+ from cognee.exceptions import CogneeValidationError, CogneeSystemError
3
3
 
4
4
 
5
- class SearchTypeNotSupported(CogneeApiError):
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(CogneeApiError):
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(CriticalError):
26
- message: str = "No data found in the system, please add data first."
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(CogneeApiError):
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,7 @@
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 UnsupportedSearchTypeError
@@ -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 InvalidValueError(message=f"Unsupported search type: {query_type}")
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 CogneeApiError
1
+ from cognee.exceptions import CogneeValidationError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class RoleNotFoundError(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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(CogneeApiError):
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 CogneeApiError
1
+ from cognee.exceptions import CogneeValidationError
2
2
  from fastapi import status
3
3
 
4
4
 
5
- class IngestionError(CogneeApiError):
5
+ class IngestionError(CogneeValidationError):
6
6
  def __init__(
7
7
  self,
8
8
  message: str = "Failed to load data.",