cognee 0.3.4.dev3__py3-none-any.whl → 0.3.5__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 (186) hide show
  1. cognee/api/client.py +16 -7
  2. cognee/api/health.py +5 -9
  3. cognee/api/v1/add/add.py +3 -1
  4. cognee/api/v1/cognify/cognify.py +44 -7
  5. cognee/api/v1/permissions/routers/get_permissions_router.py +8 -4
  6. cognee/api/v1/search/search.py +3 -0
  7. cognee/api/v1/ui/__init__.py +1 -1
  8. cognee/api/v1/ui/ui.py +215 -150
  9. cognee/api/v1/update/__init__.py +1 -0
  10. cognee/api/v1/update/routers/__init__.py +1 -0
  11. cognee/api/v1/update/routers/get_update_router.py +90 -0
  12. cognee/api/v1/update/update.py +100 -0
  13. cognee/base_config.py +5 -2
  14. cognee/cli/_cognee.py +28 -10
  15. cognee/cli/commands/delete_command.py +34 -2
  16. cognee/eval_framework/corpus_builder/task_getters/get_default_tasks_by_indices.py +2 -2
  17. cognee/eval_framework/evaluation/direct_llm_eval_adapter.py +3 -2
  18. cognee/eval_framework/modal_eval_dashboard.py +9 -1
  19. cognee/infrastructure/databases/graph/config.py +9 -9
  20. cognee/infrastructure/databases/graph/get_graph_engine.py +4 -21
  21. cognee/infrastructure/databases/graph/kuzu/adapter.py +60 -9
  22. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +3 -3
  23. cognee/infrastructure/databases/relational/config.py +4 -4
  24. cognee/infrastructure/databases/relational/create_relational_engine.py +11 -3
  25. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +7 -3
  26. cognee/infrastructure/databases/vector/config.py +7 -7
  27. cognee/infrastructure/databases/vector/create_vector_engine.py +7 -15
  28. cognee/infrastructure/databases/vector/embeddings/EmbeddingEngine.py +9 -0
  29. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +11 -0
  30. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +19 -2
  31. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +11 -0
  32. cognee/infrastructure/databases/vector/embeddings/config.py +8 -0
  33. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +5 -0
  34. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +11 -10
  35. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +48 -38
  36. cognee/infrastructure/databases/vector/vector_db_interface.py +8 -4
  37. cognee/infrastructure/files/storage/S3FileStorage.py +15 -5
  38. cognee/infrastructure/files/storage/s3_config.py +1 -0
  39. cognee/infrastructure/files/utils/open_data_file.py +7 -14
  40. cognee/infrastructure/llm/LLMGateway.py +19 -117
  41. cognee/infrastructure/llm/config.py +28 -13
  42. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_categories.py +2 -1
  43. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_event_entities.py +3 -2
  44. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_summary.py +3 -2
  45. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/extract_content_graph.py +2 -1
  46. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/extract_event_graph.py +3 -2
  47. cognee/infrastructure/llm/prompts/read_query_prompt.py +3 -2
  48. cognee/infrastructure/llm/prompts/show_prompt.py +35 -0
  49. cognee/infrastructure/llm/prompts/test.txt +1 -0
  50. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py +2 -2
  51. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py +50 -397
  52. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py +2 -3
  53. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py +8 -88
  54. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py +78 -0
  55. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py +2 -99
  56. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py +49 -401
  57. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py +19 -882
  58. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py +2 -34
  59. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py +2 -107
  60. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/acreate_structured_output.baml +26 -0
  61. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/__init__.py +1 -2
  62. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/acreate_structured_output.py +76 -0
  63. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/create_dynamic_baml_type.py +122 -0
  64. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/generators.baml +3 -3
  65. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +0 -32
  66. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +107 -98
  67. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +5 -6
  68. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +5 -6
  69. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llm_interface.py +0 -26
  70. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +17 -67
  71. cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +8 -7
  72. cognee/infrastructure/llm/utils.py +4 -4
  73. cognee/infrastructure/loaders/LoaderEngine.py +5 -2
  74. cognee/infrastructure/loaders/external/__init__.py +7 -0
  75. cognee/infrastructure/loaders/external/advanced_pdf_loader.py +244 -0
  76. cognee/infrastructure/loaders/supported_loaders.py +7 -0
  77. cognee/modules/data/methods/create_authorized_dataset.py +9 -0
  78. cognee/modules/data/methods/get_authorized_dataset.py +1 -1
  79. cognee/modules/data/methods/get_authorized_dataset_by_name.py +11 -0
  80. cognee/modules/data/methods/get_deletion_counts.py +92 -0
  81. cognee/modules/graph/cognee_graph/CogneeGraph.py +1 -1
  82. cognee/modules/graph/utils/expand_with_nodes_and_edges.py +22 -8
  83. cognee/modules/graph/utils/retrieve_existing_edges.py +0 -2
  84. cognee/modules/ingestion/data_types/TextData.py +0 -1
  85. cognee/modules/notebooks/methods/create_notebook.py +3 -1
  86. cognee/modules/notebooks/methods/get_notebooks.py +27 -1
  87. cognee/modules/observability/get_observe.py +14 -0
  88. cognee/modules/observability/observers.py +1 -0
  89. cognee/modules/ontology/base_ontology_resolver.py +42 -0
  90. cognee/modules/ontology/get_default_ontology_resolver.py +41 -0
  91. cognee/modules/ontology/matching_strategies.py +53 -0
  92. cognee/modules/ontology/models.py +20 -0
  93. cognee/modules/ontology/ontology_config.py +24 -0
  94. cognee/modules/ontology/ontology_env_config.py +45 -0
  95. cognee/modules/ontology/rdf_xml/{OntologyResolver.py → RDFLibOntologyResolver.py} +20 -28
  96. cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +21 -24
  97. cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +3 -3
  98. cognee/modules/retrieval/code_retriever.py +2 -1
  99. cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -4
  100. cognee/modules/retrieval/graph_completion_cot_retriever.py +6 -5
  101. cognee/modules/retrieval/graph_completion_retriever.py +0 -3
  102. cognee/modules/retrieval/insights_retriever.py +1 -1
  103. cognee/modules/retrieval/jaccard_retrival.py +60 -0
  104. cognee/modules/retrieval/lexical_retriever.py +123 -0
  105. cognee/modules/retrieval/natural_language_retriever.py +2 -1
  106. cognee/modules/retrieval/temporal_retriever.py +3 -2
  107. cognee/modules/retrieval/utils/brute_force_triplet_search.py +2 -12
  108. cognee/modules/retrieval/utils/completion.py +4 -7
  109. cognee/modules/search/methods/get_search_type_tools.py +7 -0
  110. cognee/modules/search/methods/no_access_control_search.py +1 -1
  111. cognee/modules/search/methods/search.py +32 -13
  112. cognee/modules/search/types/SearchType.py +1 -0
  113. cognee/modules/users/methods/create_user.py +0 -2
  114. cognee/modules/users/permissions/methods/authorized_give_permission_on_datasets.py +12 -0
  115. cognee/modules/users/permissions/methods/check_permission_on_dataset.py +11 -0
  116. cognee/modules/users/permissions/methods/get_all_user_permission_datasets.py +10 -0
  117. cognee/modules/users/permissions/methods/get_document_ids_for_user.py +10 -0
  118. cognee/modules/users/permissions/methods/get_principal.py +9 -0
  119. cognee/modules/users/permissions/methods/get_principal_datasets.py +11 -0
  120. cognee/modules/users/permissions/methods/get_role.py +10 -0
  121. cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +3 -3
  122. cognee/modules/users/permissions/methods/get_tenant.py +9 -0
  123. cognee/modules/users/permissions/methods/give_default_permission_to_role.py +9 -0
  124. cognee/modules/users/permissions/methods/give_default_permission_to_tenant.py +9 -0
  125. cognee/modules/users/permissions/methods/give_default_permission_to_user.py +9 -0
  126. cognee/modules/users/permissions/methods/give_permission_on_dataset.py +10 -0
  127. cognee/modules/users/roles/methods/add_user_to_role.py +11 -0
  128. cognee/modules/users/roles/methods/create_role.py +12 -1
  129. cognee/modules/users/tenants/methods/add_user_to_tenant.py +12 -0
  130. cognee/modules/users/tenants/methods/create_tenant.py +12 -1
  131. cognee/modules/visualization/cognee_network_visualization.py +13 -9
  132. cognee/shared/data_models.py +0 -1
  133. cognee/shared/utils.py +0 -32
  134. cognee/tasks/chunk_naive_llm_classifier/chunk_naive_llm_classifier.py +2 -2
  135. cognee/tasks/codingagents/coding_rule_associations.py +3 -2
  136. cognee/tasks/entity_completion/entity_extractors/llm_entity_extractor.py +3 -2
  137. cognee/tasks/graph/cascade_extract/utils/extract_content_nodes_and_relationship_names.py +3 -2
  138. cognee/tasks/graph/cascade_extract/utils/extract_edge_triplets.py +3 -2
  139. cognee/tasks/graph/cascade_extract/utils/extract_nodes.py +3 -2
  140. cognee/tasks/graph/extract_graph_from_code.py +2 -2
  141. cognee/tasks/graph/extract_graph_from_data.py +55 -12
  142. cognee/tasks/graph/extract_graph_from_data_v2.py +16 -4
  143. cognee/tasks/ingestion/migrate_relational_database.py +132 -41
  144. cognee/tasks/ingestion/resolve_data_directories.py +4 -1
  145. cognee/tasks/schema/ingest_database_schema.py +134 -0
  146. cognee/tasks/schema/models.py +40 -0
  147. cognee/tasks/storage/index_data_points.py +1 -1
  148. cognee/tasks/storage/index_graph_edges.py +3 -1
  149. cognee/tasks/summarization/summarize_code.py +2 -2
  150. cognee/tasks/summarization/summarize_text.py +2 -2
  151. cognee/tasks/temporal_graph/enrich_events.py +2 -2
  152. cognee/tasks/temporal_graph/extract_events_and_entities.py +2 -2
  153. cognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py +13 -4
  154. cognee/tests/cli_tests/cli_unit_tests/test_cli_edge_cases.py +13 -3
  155. cognee/tests/test_advanced_pdf_loader.py +141 -0
  156. cognee/tests/test_chromadb.py +40 -0
  157. cognee/tests/test_cognee_server_start.py +6 -1
  158. cognee/tests/test_data/Quantum_computers.txt +9 -0
  159. cognee/tests/test_lancedb.py +211 -0
  160. cognee/tests/test_pgvector.py +40 -0
  161. cognee/tests/test_relational_db_migration.py +76 -0
  162. cognee/tests/unit/infrastructure/databases/test_index_graph_edges.py +2 -1
  163. cognee/tests/unit/modules/ontology/test_ontology_adapter.py +330 -13
  164. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +0 -4
  165. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +0 -4
  166. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +0 -4
  167. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/METADATA +92 -96
  168. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/RECORD +176 -162
  169. distributed/pyproject.toml +0 -1
  170. cognee/infrastructure/data/utils/extract_keywords.py +0 -48
  171. cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py +0 -1227
  172. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_categories.baml +0 -109
  173. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_content_graph.baml +0 -343
  174. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/extract_categories.py +0 -0
  175. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/extract_summary.py +0 -89
  176. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/__init__.py +0 -0
  177. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +0 -44
  178. cognee/tasks/graph/infer_data_ontology.py +0 -309
  179. cognee/tests/test_falkordb.py +0 -174
  180. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/__init__.py +0 -0
  181. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/__init__.py +0 -0
  182. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/texts.json +0 -0
  183. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/WHEEL +0 -0
  184. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/entry_points.txt +0 -0
  185. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/licenses/LICENSE +0 -0
  186. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/licenses/NOTICE.md +0 -0
@@ -1,12 +1,14 @@
1
1
  import pytest
2
2
  from rdflib import Graph, Namespace, RDF, OWL, RDFS
3
- from cognee.modules.ontology.rdf_xml.OntologyResolver import OntologyResolver, AttachedOntologyNode
3
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
4
+ from cognee.modules.ontology.models import AttachedOntologyNode
5
+ from cognee.modules.ontology.get_default_ontology_resolver import get_default_ontology_resolver
4
6
 
5
7
 
6
8
  def test_ontology_adapter_initialization_success():
7
- """Test successful initialization of OntologyAdapter."""
9
+ """Test successful initialization of RDFLibOntologyResolver from get_default_ontology_resolver."""
8
10
 
9
- adapter = OntologyResolver()
11
+ adapter = get_default_ontology_resolver()
10
12
  adapter.build_lookup()
11
13
 
12
14
  assert isinstance(adapter.lookup, dict)
@@ -14,7 +16,7 @@ def test_ontology_adapter_initialization_success():
14
16
 
15
17
  def test_ontology_adapter_initialization_file_not_found():
16
18
  """Test OntologyAdapter initialization with nonexistent file."""
17
- adapter = OntologyResolver(ontology_file="nonexistent.owl")
19
+ adapter = RDFLibOntologyResolver(ontology_file="nonexistent.owl")
18
20
  assert adapter.graph is None
19
21
 
20
22
 
@@ -27,7 +29,7 @@ def test_build_lookup():
27
29
 
28
30
  g.add((ns.Audi, RDF.type, ns.Car))
29
31
 
30
- resolver = OntologyResolver()
32
+ resolver = RDFLibOntologyResolver()
31
33
  resolver.graph = g
32
34
  resolver.build_lookup()
33
35
 
@@ -50,7 +52,7 @@ def test_find_closest_match_exact():
50
52
  g.add((ns.Car, RDF.type, OWL.Class))
51
53
  g.add((ns.Audi, RDF.type, ns.Car))
52
54
 
53
- resolver = OntologyResolver()
55
+ resolver = RDFLibOntologyResolver()
54
56
  resolver.graph = g
55
57
  resolver.build_lookup()
56
58
 
@@ -71,7 +73,7 @@ def test_find_closest_match_fuzzy():
71
73
  g.add((ns.Audi, RDF.type, ns.Car))
72
74
  g.add((ns.BMW, RDF.type, ns.Car))
73
75
 
74
- resolver = OntologyResolver()
76
+ resolver = RDFLibOntologyResolver()
75
77
  resolver.graph = g
76
78
  resolver.build_lookup()
77
79
 
@@ -92,7 +94,7 @@ def test_find_closest_match_no_match():
92
94
  g.add((ns.Audi, RDF.type, ns.Car))
93
95
  g.add((ns.BMW, RDF.type, ns.Car))
94
96
 
95
- resolver = OntologyResolver()
97
+ resolver = RDFLibOntologyResolver()
96
98
  resolver.graph = g
97
99
  resolver.build_lookup()
98
100
 
@@ -102,10 +104,10 @@ def test_find_closest_match_no_match():
102
104
 
103
105
 
104
106
  def test_get_subgraph_no_match_rdflib():
105
- """Test get_subgraph returns empty results for a non-existent node."""
107
+ """Test get_subgraph returns empty results for a non-existent node using RDFLibOntologyResolver."""
106
108
  g = Graph()
107
109
 
108
- resolver = OntologyResolver()
110
+ resolver = get_default_ontology_resolver()
109
111
  resolver.graph = g
110
112
  resolver.build_lookup()
111
113
 
@@ -138,7 +140,7 @@ def test_get_subgraph_success_rdflib():
138
140
  g.add((ns.VW, owns, ns.Audi))
139
141
  g.add((ns.VW, owns, ns.Porsche))
140
142
 
141
- resolver = OntologyResolver()
143
+ resolver = RDFLibOntologyResolver()
142
144
  resolver.graph = g
143
145
  resolver.build_lookup()
144
146
 
@@ -160,10 +162,10 @@ def test_get_subgraph_success_rdflib():
160
162
 
161
163
 
162
164
  def test_refresh_lookup_rdflib():
163
- """Test that refresh_lookup rebuilds the lookup dict into a new object."""
165
+ """Test that refresh_lookup rebuilds the lookup dict into a new object using RDFLibOntologyResolver."""
164
166
  g = Graph()
165
167
 
166
- resolver = OntologyResolver()
168
+ resolver = get_default_ontology_resolver()
167
169
  resolver.graph = g
168
170
  resolver.build_lookup()
169
171
 
@@ -172,3 +174,318 @@ def test_refresh_lookup_rdflib():
172
174
  resolver.refresh_lookup()
173
175
 
174
176
  assert resolver.lookup is not original_lookup
177
+
178
+
179
+ def test_fuzzy_matching_strategy_exact_match():
180
+ """Test FuzzyMatchingStrategy finds exact matches."""
181
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
182
+
183
+ strategy = FuzzyMatchingStrategy()
184
+ candidates = ["audi", "bmw", "mercedes"]
185
+
186
+ result = strategy.find_match("audi", candidates)
187
+ assert result == "audi"
188
+
189
+
190
+ def test_fuzzy_matching_strategy_fuzzy_match():
191
+ """Test FuzzyMatchingStrategy finds fuzzy matches."""
192
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
193
+
194
+ strategy = FuzzyMatchingStrategy(cutoff=0.6)
195
+ candidates = ["audi", "bmw", "mercedes"]
196
+
197
+ result = strategy.find_match("audii", candidates)
198
+ assert result == "audi"
199
+
200
+
201
+ def test_fuzzy_matching_strategy_no_match():
202
+ """Test FuzzyMatchingStrategy returns None when no match meets cutoff."""
203
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
204
+
205
+ strategy = FuzzyMatchingStrategy(cutoff=0.9)
206
+ candidates = ["audi", "bmw", "mercedes"]
207
+
208
+ result = strategy.find_match("completely_different", candidates)
209
+ assert result is None
210
+
211
+
212
+ def test_fuzzy_matching_strategy_empty_candidates():
213
+ """Test FuzzyMatchingStrategy handles empty candidates list."""
214
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
215
+
216
+ strategy = FuzzyMatchingStrategy()
217
+
218
+ result = strategy.find_match("audi", [])
219
+ assert result is None
220
+
221
+
222
+ def test_base_ontology_resolver_initialization():
223
+ """Test BaseOntologyResolver initialization with default matching strategy."""
224
+ from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
225
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
226
+
227
+ class TestOntologyResolver(BaseOntologyResolver):
228
+ def build_lookup(self):
229
+ pass
230
+
231
+ def refresh_lookup(self):
232
+ pass
233
+
234
+ def find_closest_match(self, name, category):
235
+ return None
236
+
237
+ def get_subgraph(self, node_name, node_type="individuals", directed=True):
238
+ return [], [], None
239
+
240
+ resolver = TestOntologyResolver()
241
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
242
+
243
+
244
+ def test_base_ontology_resolver_custom_matching_strategy():
245
+ """Test BaseOntologyResolver initialization with custom matching strategy."""
246
+ from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
247
+ from cognee.modules.ontology.matching_strategies import MatchingStrategy
248
+
249
+ class CustomMatchingStrategy(MatchingStrategy):
250
+ def find_match(self, name, candidates):
251
+ return "custom_match"
252
+
253
+ class TestOntologyResolver(BaseOntologyResolver):
254
+ def build_lookup(self):
255
+ pass
256
+
257
+ def refresh_lookup(self):
258
+ pass
259
+
260
+ def find_closest_match(self, name, category):
261
+ return None
262
+
263
+ def get_subgraph(self, node_name, node_type="individuals", directed=True):
264
+ return [], [], None
265
+
266
+ custom_strategy = CustomMatchingStrategy()
267
+ resolver = TestOntologyResolver(matching_strategy=custom_strategy)
268
+ assert resolver.matching_strategy == custom_strategy
269
+
270
+
271
+ def test_ontology_config_structure():
272
+ """Test TypedDict structure for ontology configuration."""
273
+ from cognee.modules.ontology.ontology_config import Config
274
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
275
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
276
+
277
+ matching_strategy = FuzzyMatchingStrategy()
278
+ resolver = RDFLibOntologyResolver(matching_strategy=matching_strategy)
279
+
280
+ config: Config = {"ontology_config": {"ontology_resolver": resolver}}
281
+
282
+ assert config["ontology_config"]["ontology_resolver"] == resolver
283
+
284
+
285
+ def test_get_ontology_resolver_default():
286
+ """Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
287
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
288
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
289
+
290
+ resolver = get_default_ontology_resolver()
291
+
292
+ assert isinstance(resolver, RDFLibOntologyResolver)
293
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
294
+
295
+
296
+ def test_get_default_ontology_resolver():
297
+ """Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
298
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
299
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
300
+
301
+ resolver = get_default_ontology_resolver()
302
+
303
+ assert isinstance(resolver, RDFLibOntologyResolver)
304
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
305
+
306
+
307
+ def test_rdflib_ontology_resolver_uses_matching_strategy():
308
+ """Test that RDFLibOntologyResolver uses the provided matching strategy."""
309
+ from cognee.modules.ontology.matching_strategies import MatchingStrategy
310
+
311
+ class TestMatchingStrategy(MatchingStrategy):
312
+ def find_match(self, name, candidates):
313
+ return "test_match" if candidates else None
314
+
315
+ ns = Namespace("http://example.org/test#")
316
+ g = Graph()
317
+ g.add((ns.Car, RDF.type, OWL.Class))
318
+ g.add((ns.Audi, RDF.type, ns.Car))
319
+
320
+ resolver = RDFLibOntologyResolver(matching_strategy=TestMatchingStrategy())
321
+ resolver.graph = g
322
+ resolver.build_lookup()
323
+
324
+ result = resolver.find_closest_match("Audi", "individuals")
325
+ assert result == "test_match"
326
+
327
+
328
+ def test_rdflib_ontology_resolver_default_matching_strategy():
329
+ """Test that RDFLibOntologyResolver uses FuzzyMatchingStrategy by default."""
330
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
331
+
332
+ resolver = RDFLibOntologyResolver()
333
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
334
+
335
+
336
+ def test_get_ontology_resolver_from_env_success():
337
+ """Test get_ontology_resolver_from_env returns correct resolver with valid parameters."""
338
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
339
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
340
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
341
+
342
+ resolver = get_ontology_resolver_from_env(
343
+ ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
344
+ )
345
+
346
+ assert isinstance(resolver, RDFLibOntologyResolver)
347
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
348
+ assert resolver.ontology_file == "/test/path.owl"
349
+
350
+
351
+ def test_get_ontology_resolver_from_env_unsupported_resolver():
352
+ """Test get_ontology_resolver_from_env raises EnvironmentError for unsupported resolver."""
353
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
354
+
355
+ with pytest.raises(EnvironmentError) as exc_info:
356
+ get_ontology_resolver_from_env(
357
+ ontology_resolver="unsupported",
358
+ matching_strategy="fuzzy",
359
+ ontology_file_path="/test/path.owl",
360
+ )
361
+
362
+ assert "Unsupported ontology resolver: unsupported" in str(exc_info.value)
363
+ assert "Supported resolvers are: RdfLib with FuzzyMatchingStrategy" in str(exc_info.value)
364
+
365
+
366
+ def test_get_ontology_resolver_from_env_unsupported_strategy():
367
+ """Test get_ontology_resolver_from_env raises EnvironmentError for unsupported strategy."""
368
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
369
+
370
+ with pytest.raises(EnvironmentError) as exc_info:
371
+ get_ontology_resolver_from_env(
372
+ ontology_resolver="rdflib",
373
+ matching_strategy="unsupported",
374
+ ontology_file_path="/test/path.owl",
375
+ )
376
+
377
+ assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
378
+
379
+
380
+ def test_get_ontology_resolver_from_env_empty_file_path():
381
+ """Test get_ontology_resolver_from_env raises EnvironmentError for empty file path."""
382
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
383
+
384
+ with pytest.raises(EnvironmentError) as exc_info:
385
+ get_ontology_resolver_from_env(
386
+ ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path=""
387
+ )
388
+
389
+ assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
390
+
391
+
392
+ def test_get_ontology_resolver_from_env_none_file_path():
393
+ """Test get_ontology_resolver_from_env raises EnvironmentError for None file path."""
394
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
395
+
396
+ with pytest.raises(EnvironmentError) as exc_info:
397
+ get_ontology_resolver_from_env(
398
+ ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path=None
399
+ )
400
+
401
+ assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
402
+
403
+
404
+ def test_get_ontology_resolver_from_env_empty_resolver():
405
+ """Test get_ontology_resolver_from_env raises EnvironmentError for empty resolver."""
406
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
407
+
408
+ with pytest.raises(EnvironmentError) as exc_info:
409
+ get_ontology_resolver_from_env(
410
+ ontology_resolver="", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
411
+ )
412
+
413
+ assert "Unsupported ontology resolver:" in str(exc_info.value)
414
+
415
+
416
+ def test_get_ontology_resolver_from_env_empty_strategy():
417
+ """Test get_ontology_resolver_from_env raises EnvironmentError for empty strategy."""
418
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
419
+
420
+ with pytest.raises(EnvironmentError) as exc_info:
421
+ get_ontology_resolver_from_env(
422
+ ontology_resolver="rdflib", matching_strategy="", ontology_file_path="/test/path.owl"
423
+ )
424
+
425
+ assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
426
+
427
+
428
+ def test_get_ontology_resolver_from_env_default_parameters():
429
+ """Test get_ontology_resolver_from_env with default empty parameters raises EnvironmentError."""
430
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
431
+
432
+ with pytest.raises(EnvironmentError) as exc_info:
433
+ get_ontology_resolver_from_env()
434
+
435
+ assert "Unsupported ontology resolver:" in str(exc_info.value)
436
+
437
+
438
+ def test_get_ontology_resolver_from_env_case_sensitivity():
439
+ """Test get_ontology_resolver_from_env is case sensitive."""
440
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
441
+
442
+ with pytest.raises(EnvironmentError):
443
+ get_ontology_resolver_from_env(
444
+ ontology_resolver="RDFLIB",
445
+ matching_strategy="fuzzy",
446
+ ontology_file_path="/test/path.owl",
447
+ )
448
+
449
+ with pytest.raises(EnvironmentError):
450
+ get_ontology_resolver_from_env(
451
+ ontology_resolver="RdfLib",
452
+ matching_strategy="fuzzy",
453
+ ontology_file_path="/test/path.owl",
454
+ )
455
+
456
+
457
+ def test_get_ontology_resolver_from_env_with_actual_file():
458
+ """Test get_ontology_resolver_from_env works with actual file path."""
459
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
460
+ from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
461
+ from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
462
+
463
+ resolver = get_ontology_resolver_from_env(
464
+ ontology_resolver="rdflib",
465
+ matching_strategy="fuzzy",
466
+ ontology_file_path="/path/to/ontology.owl",
467
+ )
468
+
469
+ assert isinstance(resolver, RDFLibOntologyResolver)
470
+ assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
471
+ assert resolver.ontology_file == "/path/to/ontology.owl"
472
+
473
+
474
+ def test_get_ontology_resolver_from_env_resolver_functionality():
475
+ """Test that resolver created from env function works correctly."""
476
+ from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
477
+
478
+ resolver = get_ontology_resolver_from_env(
479
+ ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
480
+ )
481
+
482
+ resolver.build_lookup()
483
+ assert isinstance(resolver.lookup, dict)
484
+
485
+ result = resolver.find_closest_match("test", "individuals")
486
+ assert result is None # Should return None for non-existent entity
487
+
488
+ nodes, relationships, start_node = resolver.get_subgraph("test", "individuals")
489
+ assert nodes == []
490
+ assert relationships == []
491
+ assert start_node is None
@@ -7,7 +7,6 @@ import cognee
7
7
  from cognee.low_level import setup, DataPoint
8
8
  from cognee.tasks.storage import add_data_points
9
9
  from cognee.modules.graph.utils import resolve_edges_to_text
10
- from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
11
10
  from cognee.modules.retrieval.graph_completion_context_extension_retriever import (
12
11
  GraphCompletionContextExtensionRetriever,
13
12
  )
@@ -165,9 +164,6 @@ class TestGraphCompletionWithContextExtensionRetriever:
165
164
 
166
165
  retriever = GraphCompletionContextExtensionRetriever()
167
166
 
168
- with pytest.raises(DatabaseNotCreatedError):
169
- await retriever.get_context("Who works at Figma?")
170
-
171
167
  await setup()
172
168
 
173
169
  context = await retriever.get_context("Who works at Figma?")
@@ -7,7 +7,6 @@ import cognee
7
7
  from cognee.low_level import setup, DataPoint
8
8
  from cognee.modules.graph.utils import resolve_edges_to_text
9
9
  from cognee.tasks.storage import add_data_points
10
- from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
11
10
  from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever
12
11
 
13
12
 
@@ -158,9 +157,6 @@ class TestGraphCompletionCoTRetriever:
158
157
 
159
158
  retriever = GraphCompletionCotRetriever()
160
159
 
161
- with pytest.raises(DatabaseNotCreatedError):
162
- await retriever.get_context("Who works at Figma?")
163
-
164
160
  await setup()
165
161
 
166
162
  context = await retriever.get_context("Who works at Figma?")
@@ -7,7 +7,6 @@ import cognee
7
7
  from cognee.low_level import setup, DataPoint
8
8
  from cognee.modules.graph.utils import resolve_edges_to_text
9
9
  from cognee.tasks.storage import add_data_points
10
- from cognee.infrastructure.databases.exceptions import DatabaseNotCreatedError
11
10
  from cognee.modules.retrieval.graph_completion_retriever import GraphCompletionRetriever
12
11
 
13
12
 
@@ -218,9 +217,6 @@ class TestGraphCompletionRetriever:
218
217
 
219
218
  retriever = GraphCompletionRetriever()
220
219
 
221
- with pytest.raises(DatabaseNotCreatedError):
222
- await retriever.get_context("Who works at Figma?")
223
-
224
220
  await setup()
225
221
 
226
222
  context = await retriever.get_context("Who works at Figma?")