cognee 0.5.1.dev0__py3-none-any.whl → 0.5.2.dev0__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 (238) hide show
  1. cognee/__init__.py +2 -0
  2. cognee/alembic/README +1 -0
  3. cognee/alembic/env.py +107 -0
  4. cognee/alembic/script.py.mako +26 -0
  5. cognee/alembic/versions/1a58b986e6e1_enable_delete_for_old_tutorial_notebooks.py +52 -0
  6. cognee/alembic/versions/1d0bb7fede17_add_pipeline_run_status.py +33 -0
  7. cognee/alembic/versions/1daae0df1866_incremental_loading.py +48 -0
  8. cognee/alembic/versions/211ab850ef3d_add_sync_operations_table.py +118 -0
  9. cognee/alembic/versions/45957f0a9849_add_notebook_table.py +46 -0
  10. cognee/alembic/versions/46a6ce2bd2b2_expand_dataset_database_with_json_.py +333 -0
  11. cognee/alembic/versions/482cd6517ce4_add_default_user.py +30 -0
  12. cognee/alembic/versions/76625596c5c3_expand_dataset_database_for_multi_user.py +98 -0
  13. cognee/alembic/versions/8057ae7329c2_initial_migration.py +25 -0
  14. cognee/alembic/versions/9e7a3cb85175_loader_separation.py +104 -0
  15. cognee/alembic/versions/a1b2c3d4e5f6_add_label_column_to_data.py +38 -0
  16. cognee/alembic/versions/ab7e313804ae_permission_system_rework.py +236 -0
  17. cognee/alembic/versions/b9274c27a25a_kuzu_11_migration.py +75 -0
  18. cognee/alembic/versions/c946955da633_multi_tenant_support.py +137 -0
  19. cognee/alembic/versions/e1ec1dcb50b6_add_last_accessed_to_data.py +51 -0
  20. cognee/alembic/versions/e4ebee1091e7_expand_data_model_info.py +140 -0
  21. cognee/alembic.ini +117 -0
  22. cognee/api/v1/add/routers/get_add_router.py +2 -0
  23. cognee/api/v1/cognify/cognify.py +11 -6
  24. cognee/api/v1/cognify/routers/get_cognify_router.py +8 -0
  25. cognee/api/v1/config/config.py +60 -0
  26. cognee/api/v1/datasets/routers/get_datasets_router.py +45 -3
  27. cognee/api/v1/memify/routers/get_memify_router.py +2 -0
  28. cognee/api/v1/search/routers/get_search_router.py +21 -6
  29. cognee/api/v1/search/search.py +25 -5
  30. cognee/api/v1/sync/routers/get_sync_router.py +3 -3
  31. cognee/cli/commands/add_command.py +1 -1
  32. cognee/cli/commands/cognify_command.py +6 -0
  33. cognee/cli/commands/config_command.py +1 -1
  34. cognee/context_global_variables.py +5 -1
  35. cognee/eval_framework/answer_generation/answer_generation_executor.py +7 -8
  36. cognee/infrastructure/databases/cache/cache_db_interface.py +38 -1
  37. cognee/infrastructure/databases/cache/config.py +6 -0
  38. cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py +21 -0
  39. cognee/infrastructure/databases/cache/get_cache_engine.py +9 -3
  40. cognee/infrastructure/databases/cache/redis/RedisAdapter.py +60 -1
  41. cognee/infrastructure/databases/dataset_database_handler/supported_dataset_database_handlers.py +7 -0
  42. cognee/infrastructure/databases/graph/get_graph_engine.py +29 -1
  43. cognee/infrastructure/databases/graph/neo4j_driver/Neo4jAuraDevDatasetDatabaseHandler.py +62 -27
  44. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +17 -4
  45. cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +2 -1
  46. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -0
  47. cognee/infrastructure/databases/vector/config.py +6 -0
  48. cognee/infrastructure/databases/vector/create_vector_engine.py +69 -22
  49. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +64 -9
  50. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +13 -2
  51. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +16 -3
  52. cognee/infrastructure/databases/vector/models/ScoredResult.py +3 -3
  53. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +16 -3
  54. cognee/infrastructure/databases/vector/pgvector/PGVectorDatasetDatabaseHandler.py +86 -0
  55. cognee/infrastructure/databases/vector/pgvector/create_db_and_tables.py +81 -2
  56. cognee/infrastructure/databases/vector/vector_db_interface.py +8 -0
  57. cognee/infrastructure/files/utils/get_data_file_path.py +33 -27
  58. cognee/infrastructure/llm/prompts/extract_query_time.txt +1 -1
  59. cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +1 -1
  60. cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +1 -1
  61. cognee/infrastructure/llm/prompts/generate_graph_prompt.txt +2 -2
  62. cognee/infrastructure/llm/prompts/generate_graph_prompt_guided.txt +1 -1
  63. cognee/infrastructure/llm/prompts/generate_graph_prompt_oneshot.txt +2 -2
  64. cognee/infrastructure/llm/prompts/generate_graph_prompt_simple.txt +1 -1
  65. cognee/infrastructure/llm/prompts/generate_graph_prompt_strict.txt +1 -1
  66. cognee/infrastructure/llm/prompts/search_type_selector_prompt.txt +6 -6
  67. cognee/infrastructure/llm/prompts/test.txt +1 -1
  68. cognee/infrastructure/llm/prompts/translate_content.txt +19 -0
  69. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +24 -0
  70. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llama_cpp/adapter.py +191 -0
  71. cognee/modules/chunking/models/DocumentChunk.py +0 -1
  72. cognee/modules/cognify/config.py +2 -0
  73. cognee/modules/data/models/Data.py +1 -0
  74. cognee/modules/engine/models/Entity.py +0 -1
  75. cognee/modules/engine/operations/setup.py +6 -0
  76. cognee/modules/graph/cognee_graph/CogneeGraph.py +150 -37
  77. cognee/modules/graph/cognee_graph/CogneeGraphElements.py +48 -2
  78. cognee/modules/graph/utils/__init__.py +1 -0
  79. cognee/modules/graph/utils/get_entity_nodes_from_triplets.py +12 -0
  80. cognee/modules/notebooks/methods/__init__.py +1 -0
  81. cognee/modules/notebooks/methods/create_notebook.py +0 -34
  82. cognee/modules/notebooks/methods/create_tutorial_notebooks.py +191 -0
  83. cognee/modules/notebooks/methods/get_notebooks.py +12 -8
  84. cognee/modules/notebooks/tutorials/cognee-basics/cell-1.md +3 -0
  85. cognee/modules/notebooks/tutorials/cognee-basics/cell-2.md +10 -0
  86. cognee/modules/notebooks/tutorials/cognee-basics/cell-3.md +7 -0
  87. cognee/modules/notebooks/tutorials/cognee-basics/cell-4.py +28 -0
  88. cognee/modules/notebooks/tutorials/cognee-basics/cell-5.py +3 -0
  89. cognee/modules/notebooks/tutorials/cognee-basics/cell-6.py +9 -0
  90. cognee/modules/notebooks/tutorials/cognee-basics/cell-7.py +17 -0
  91. cognee/modules/notebooks/tutorials/cognee-basics/config.json +4 -0
  92. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-1.md +3 -0
  93. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-10.md +3 -0
  94. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-11.md +3 -0
  95. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-12.py +3 -0
  96. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-13.md +7 -0
  97. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-14.py +6 -0
  98. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-15.md +3 -0
  99. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-16.py +7 -0
  100. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-2.md +9 -0
  101. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-3.md +7 -0
  102. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-4.md +9 -0
  103. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-5.md +5 -0
  104. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-6.py +13 -0
  105. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-7.md +3 -0
  106. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-8.md +3 -0
  107. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-9.py +31 -0
  108. cognee/modules/notebooks/tutorials/python-development-with-cognee/config.json +4 -0
  109. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/copilot_conversations.json +107 -0
  110. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/guido_contributions.json +976 -0
  111. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/my_developer_rules.md +79 -0
  112. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/pep_style_guide.md +74 -0
  113. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/zen_principles.md +74 -0
  114. cognee/modules/retrieval/EntityCompletionRetriever.py +51 -38
  115. cognee/modules/retrieval/__init__.py +0 -1
  116. cognee/modules/retrieval/base_retriever.py +66 -10
  117. cognee/modules/retrieval/chunks_retriever.py +57 -49
  118. cognee/modules/retrieval/coding_rules_retriever.py +12 -5
  119. cognee/modules/retrieval/completion_retriever.py +29 -28
  120. cognee/modules/retrieval/cypher_search_retriever.py +25 -20
  121. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +42 -46
  122. cognee/modules/retrieval/graph_completion_cot_retriever.py +68 -51
  123. cognee/modules/retrieval/graph_completion_retriever.py +78 -63
  124. cognee/modules/retrieval/graph_summary_completion_retriever.py +2 -0
  125. cognee/modules/retrieval/lexical_retriever.py +34 -12
  126. cognee/modules/retrieval/natural_language_retriever.py +18 -15
  127. cognee/modules/retrieval/summaries_retriever.py +51 -34
  128. cognee/modules/retrieval/temporal_retriever.py +59 -49
  129. cognee/modules/retrieval/triplet_retriever.py +31 -32
  130. cognee/modules/retrieval/utils/access_tracking.py +88 -0
  131. cognee/modules/retrieval/utils/brute_force_triplet_search.py +99 -85
  132. cognee/modules/retrieval/utils/node_edge_vector_search.py +174 -0
  133. cognee/modules/search/methods/__init__.py +1 -0
  134. cognee/modules/search/methods/get_retriever_output.py +53 -0
  135. cognee/modules/search/methods/get_search_type_retriever_instance.py +252 -0
  136. cognee/modules/search/methods/search.py +90 -215
  137. cognee/modules/search/models/SearchResultPayload.py +67 -0
  138. cognee/modules/search/types/SearchResult.py +1 -8
  139. cognee/modules/search/types/SearchType.py +1 -2
  140. cognee/modules/search/types/__init__.py +1 -1
  141. cognee/modules/search/utils/__init__.py +1 -2
  142. cognee/modules/search/utils/transform_insights_to_graph.py +2 -2
  143. cognee/modules/search/utils/{transform_context_to_graph.py → transform_triplets_to_graph.py} +2 -2
  144. cognee/modules/users/authentication/default/default_transport.py +11 -1
  145. cognee/modules/users/authentication/get_api_auth_backend.py +2 -1
  146. cognee/modules/users/authentication/get_client_auth_backend.py +2 -1
  147. cognee/modules/users/methods/create_user.py +0 -9
  148. cognee/modules/users/permissions/methods/has_user_management_permission.py +29 -0
  149. cognee/modules/visualization/cognee_network_visualization.py +1 -1
  150. cognee/run_migrations.py +48 -0
  151. cognee/shared/exceptions/__init__.py +1 -3
  152. cognee/shared/exceptions/exceptions.py +11 -1
  153. cognee/shared/usage_logger.py +332 -0
  154. cognee/shared/utils.py +12 -5
  155. cognee/tasks/cleanup/cleanup_unused_data.py +172 -0
  156. cognee/tasks/memify/extract_usage_frequency.py +613 -0
  157. cognee/tasks/summarization/models.py +0 -2
  158. cognee/tasks/temporal_graph/__init__.py +0 -1
  159. cognee/tasks/translation/__init__.py +96 -0
  160. cognee/tasks/translation/config.py +110 -0
  161. cognee/tasks/translation/detect_language.py +190 -0
  162. cognee/tasks/translation/exceptions.py +62 -0
  163. cognee/tasks/translation/models.py +72 -0
  164. cognee/tasks/translation/providers/__init__.py +44 -0
  165. cognee/tasks/translation/providers/azure_provider.py +192 -0
  166. cognee/tasks/translation/providers/base.py +85 -0
  167. cognee/tasks/translation/providers/google_provider.py +158 -0
  168. cognee/tasks/translation/providers/llm_provider.py +143 -0
  169. cognee/tasks/translation/translate_content.py +282 -0
  170. cognee/tasks/web_scraper/default_url_crawler.py +6 -2
  171. cognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py +1 -0
  172. cognee/tests/cli_tests/cli_unit_tests/test_cli_edge_cases.py +3 -0
  173. cognee/tests/integration/retrieval/test_brute_force_triplet_search_with_cognify.py +62 -0
  174. cognee/tests/integration/retrieval/test_chunks_retriever.py +115 -16
  175. cognee/tests/integration/retrieval/test_graph_completion_retriever.py +13 -5
  176. cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +22 -20
  177. cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +23 -24
  178. cognee/tests/integration/retrieval/test_rag_completion_retriever.py +70 -5
  179. cognee/tests/integration/retrieval/test_structured_output.py +62 -18
  180. cognee/tests/integration/retrieval/test_summaries_retriever.py +20 -9
  181. cognee/tests/integration/retrieval/test_temporal_retriever.py +38 -8
  182. cognee/tests/integration/retrieval/test_triplet_retriever.py +13 -4
  183. cognee/tests/integration/shared/test_usage_logger_integration.py +255 -0
  184. cognee/tests/tasks/translation/README.md +147 -0
  185. cognee/tests/tasks/translation/__init__.py +1 -0
  186. cognee/tests/tasks/translation/config_test.py +93 -0
  187. cognee/tests/tasks/translation/detect_language_test.py +118 -0
  188. cognee/tests/tasks/translation/providers_test.py +151 -0
  189. cognee/tests/tasks/translation/translate_content_test.py +213 -0
  190. cognee/tests/test_chromadb.py +1 -1
  191. cognee/tests/test_cleanup_unused_data.py +165 -0
  192. cognee/tests/test_delete_by_id.py +6 -6
  193. cognee/tests/test_extract_usage_frequency.py +308 -0
  194. cognee/tests/test_kuzu.py +17 -7
  195. cognee/tests/test_lancedb.py +3 -1
  196. cognee/tests/test_library.py +1 -1
  197. cognee/tests/test_neo4j.py +17 -7
  198. cognee/tests/test_neptune_analytics_vector.py +3 -1
  199. cognee/tests/test_permissions.py +172 -187
  200. cognee/tests/test_pgvector.py +3 -1
  201. cognee/tests/test_relational_db_migration.py +15 -1
  202. cognee/tests/test_remote_kuzu.py +3 -1
  203. cognee/tests/test_s3_file_storage.py +1 -1
  204. cognee/tests/test_search_db.py +97 -110
  205. cognee/tests/test_usage_logger_e2e.py +268 -0
  206. cognee/tests/unit/api/test_get_raw_data_endpoint.py +206 -0
  207. cognee/tests/unit/eval_framework/answer_generation_test.py +4 -3
  208. cognee/tests/unit/infrastructure/databases/cache/test_cache_config.py +2 -0
  209. cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +42 -2
  210. cognee/tests/unit/modules/graph/cognee_graph_test.py +329 -31
  211. cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +31 -59
  212. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +70 -33
  213. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +72 -52
  214. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +27 -33
  215. cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +28 -15
  216. cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +37 -42
  217. cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +48 -64
  218. cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +263 -24
  219. cognee/tests/unit/modules/retrieval/test_node_edge_vector_search.py +273 -0
  220. cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +30 -16
  221. cognee/tests/unit/modules/search/test_get_search_type_retriever_instance.py +125 -0
  222. cognee/tests/unit/modules/search/test_search.py +176 -0
  223. cognee/tests/unit/modules/search/test_search_prepare_search_result_contract.py +190 -0
  224. cognee/tests/unit/modules/users/test_tutorial_notebook_creation.py +511 -297
  225. cognee/tests/unit/shared/test_usage_logger.py +241 -0
  226. cognee/tests/unit/users/permissions/test_has_user_management_permission.py +46 -0
  227. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/METADATA +17 -10
  228. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/RECORD +232 -144
  229. cognee/api/.env.example +0 -5
  230. cognee/modules/retrieval/base_graph_retriever.py +0 -24
  231. cognee/modules/search/methods/get_search_type_tools.py +0 -223
  232. cognee/modules/search/methods/no_access_control_search.py +0 -62
  233. cognee/modules/search/utils/prepare_search_result.py +0 -63
  234. cognee/tests/test_feedback_enrichment.py +0 -174
  235. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/WHEEL +0 -0
  236. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/entry_points.txt +0 -0
  237. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/LICENSE +0 -0
  238. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/NOTICE.md +0 -0
@@ -63,8 +63,8 @@ async def test_filter_top_k_events_sorts_and_limits():
63
63
  ]
64
64
 
65
65
  scored_results = [
66
- SimpleNamespace(payload={"id": "e2"}, score=0.10),
67
- SimpleNamespace(payload={"id": "e1"}, score=0.20),
66
+ SimpleNamespace(id="e2", payload={"id": "e2"}, score=0.10),
67
+ SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.20),
68
68
  ]
69
69
 
70
70
  top = await tr.filter_top_k_events(relevant_events, scored_results)
@@ -91,8 +91,8 @@ async def test_filter_top_k_events_includes_unknown_as_infinite_but_not_in_top_k
91
91
  ]
92
92
 
93
93
  scored_results = [
94
- SimpleNamespace(payload={"id": "known2"}, score=0.05),
95
- SimpleNamespace(payload={"id": "known1"}, score=0.50),
94
+ SimpleNamespace(id="known2", payload={"id": "known2"}, score=0.05),
95
+ SimpleNamespace(id="known1", payload={"id": "known1"}, score=0.50),
96
96
  ]
97
97
 
98
98
  top = await tr.filter_top_k_events(relevant_events, scored_results)
@@ -119,8 +119,8 @@ async def test_filter_top_k_events_limits_when_top_k_exceeds_events():
119
119
  tr = TemporalRetriever(top_k=10)
120
120
  relevant_events = [{"events": [{"id": "a"}, {"id": "b"}]}]
121
121
  scored_results = [
122
- SimpleNamespace(payload={"id": "a"}, score=0.1),
123
- SimpleNamespace(payload={"id": "b"}, score=0.2),
122
+ SimpleNamespace(id="a", payload={"id": "a"}, score=0.1),
123
+ SimpleNamespace(id="b", payload={"id": "b"}, score=0.2),
124
124
  ]
125
125
  out = await tr.filter_top_k_events(relevant_events, scored_results)
126
126
  assert [e["id"] for e in out] == ["a", "b"]
@@ -179,8 +179,8 @@ async def test_get_context_with_time_range(mock_graph_engine, mock_vector_engine
179
179
  }
180
180
  ]
181
181
 
182
- mock_result1 = SimpleNamespace(payload={"id": "e2"}, score=0.05)
183
- mock_result2 = SimpleNamespace(payload={"id": "e1"}, score=0.10)
182
+ mock_result1 = SimpleNamespace(id="e2", payload={"id": "e2"}, score=0.05)
183
+ mock_result2 = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.10)
184
184
  mock_vector_engine.search.return_value = [mock_result1, mock_result2]
185
185
 
186
186
  with (
@@ -196,7 +196,8 @@ async def test_get_context_with_time_range(mock_graph_engine, mock_vector_engine
196
196
  return_value=mock_vector_engine,
197
197
  ),
198
198
  ):
199
- context = await retriever.get_context("What happened in 2024?")
199
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
200
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
200
201
 
201
202
  assert isinstance(context, str)
202
203
  assert len(context) > 0
@@ -226,7 +227,8 @@ async def test_get_context_fallback_to_triplets_no_time(mock_graph_engine):
226
227
 
227
228
  retriever.extract_time_from_query = mock_extract_time
228
229
 
229
- context = await retriever.get_context("test query")
230
+ objects = await retriever.get_retrieved_objects("test query")
231
+ context = await retriever.get_context_from_objects("test query", objects)
230
232
 
231
233
  assert context == "triplet text"
232
234
  mock_get_triplets.assert_awaited_once_with("test query")
@@ -258,7 +260,8 @@ async def test_get_context_no_events_found(mock_graph_engine):
258
260
 
259
261
  retriever.extract_time_from_query = mock_extract_time
260
262
 
261
- context = await retriever.get_context("test query")
263
+ objects = await retriever.get_retrieved_objects("test query")
264
+ context = await retriever.get_context_from_objects("test query", objects)
262
265
 
263
266
  assert context == "triplet text"
264
267
  mock_get_triplets.assert_awaited_once_with("test query")
@@ -279,7 +282,7 @@ async def test_get_context_time_from_only(mock_graph_engine, mock_vector_engine)
279
282
  }
280
283
  ]
281
284
 
282
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
285
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
283
286
  mock_vector_engine.search.return_value = [mock_result]
284
287
 
285
288
  with (
@@ -293,7 +296,8 @@ async def test_get_context_time_from_only(mock_graph_engine, mock_vector_engine)
293
296
  return_value=mock_vector_engine,
294
297
  ),
295
298
  ):
296
- context = await retriever.get_context("What happened after 2024?")
299
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
300
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
297
301
 
298
302
  assert isinstance(context, str)
299
303
  assert "Event 1" in context
@@ -313,7 +317,7 @@ async def test_get_context_time_to_only(mock_graph_engine, mock_vector_engine):
313
317
  }
314
318
  ]
315
319
 
316
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
320
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
317
321
  mock_vector_engine.search.return_value = [mock_result]
318
322
 
319
323
  with (
@@ -327,7 +331,8 @@ async def test_get_context_time_to_only(mock_graph_engine, mock_vector_engine):
327
331
  return_value=mock_vector_engine,
328
332
  ),
329
333
  ):
330
- context = await retriever.get_context("What happened before 2024?")
334
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
335
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
331
336
 
332
337
  assert isinstance(context, str)
333
338
  assert "Event 1" in context
@@ -347,7 +352,7 @@ async def test_get_completion_without_context(mock_graph_engine, mock_vector_eng
347
352
  }
348
353
  ]
349
354
 
350
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
355
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
351
356
  mock_vector_engine.search.return_value = [mock_result]
352
357
 
353
358
  with (
@@ -372,7 +377,11 @@ async def test_get_completion_without_context(mock_graph_engine, mock_vector_eng
372
377
  mock_config.caching = False
373
378
  mock_cache_config.return_value = mock_config
374
379
 
375
- completion = await retriever.get_completion("What happened in 2024?")
380
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
381
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
382
+ completion = await retriever.get_completion_from_context(
383
+ "What happened in 2024?", objects, context=context
384
+ )
376
385
 
377
386
  assert isinstance(completion, list)
378
387
  assert len(completion) == 1
@@ -395,7 +404,11 @@ async def test_get_completion_with_provided_context():
395
404
  mock_config.caching = False
396
405
  mock_cache_config.return_value = mock_config
397
406
 
398
- completion = await retriever.get_completion("test query", context="Provided context")
407
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
408
+ await retriever.get_context_from_objects("What happened in 2024?", objects)
409
+ completion = await retriever.get_completion_from_context(
410
+ "test query", objects, context="Provided context"
411
+ )
399
412
 
400
413
  assert isinstance(completion, list)
401
414
  assert len(completion) == 1
@@ -405,7 +418,7 @@ async def test_get_completion_with_provided_context():
405
418
  @pytest.mark.asyncio
406
419
  async def test_get_completion_with_session(mock_graph_engine, mock_vector_engine):
407
420
  """Test get_completion with session caching enabled."""
408
- retriever = TemporalRetriever()
421
+ retriever = TemporalRetriever(session_id="test_session")
409
422
 
410
423
  mock_graph_engine.collect_time_ids.return_value = ["e1"]
411
424
  mock_graph_engine.collect_events.return_value = [
@@ -416,7 +429,7 @@ async def test_get_completion_with_session(mock_graph_engine, mock_vector_engine
416
429
  }
417
430
  ]
418
431
 
419
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
432
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
420
433
  mock_vector_engine.search.return_value = [mock_result]
421
434
 
422
435
  mock_user = MagicMock()
@@ -457,8 +470,10 @@ async def test_get_completion_with_session(mock_graph_engine, mock_vector_engine
457
470
  mock_cache_config.return_value = mock_config
458
471
  mock_session_user.get.return_value = mock_user
459
472
 
460
- completion = await retriever.get_completion(
461
- "What happened in 2024?", session_id="test_session"
473
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
474
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
475
+ completion = await retriever.get_completion_from_context(
476
+ "What happened in 2024?", objects, context
462
477
  )
463
478
 
464
479
  assert isinstance(completion, list)
@@ -481,7 +496,7 @@ async def test_get_completion_with_session_no_user_id(mock_graph_engine, mock_ve
481
496
  }
482
497
  ]
483
498
 
484
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
499
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
485
500
  mock_vector_engine.search.return_value = [mock_result]
486
501
 
487
502
  with (
@@ -508,49 +523,16 @@ async def test_get_completion_with_session_no_user_id(mock_graph_engine, mock_ve
508
523
  mock_cache_config.return_value = mock_config
509
524
  mock_session_user.get.return_value = None # No user
510
525
 
511
- completion = await retriever.get_completion("What happened in 2024?")
526
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
527
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
528
+ completion = await retriever.get_completion_from_context(
529
+ "What happened in 2024?", objects, context
530
+ )
512
531
 
513
532
  assert isinstance(completion, list)
514
533
  assert len(completion) == 1
515
534
 
516
535
 
517
- @pytest.mark.asyncio
518
- async def test_get_completion_context_retrieved_but_empty(mock_graph_engine):
519
- """Test get_completion when get_context returns empty string."""
520
- retriever = TemporalRetriever()
521
-
522
- with (
523
- patch.object(
524
- retriever, "extract_time_from_query", return_value=("2024-01-01", "2024-12-31")
525
- ),
526
- patch(
527
- "cognee.modules.retrieval.temporal_retriever.get_graph_engine",
528
- return_value=mock_graph_engine,
529
- ),
530
- patch(
531
- "cognee.modules.retrieval.temporal_retriever.get_vector_engine",
532
- ) as mock_get_vector,
533
- patch.object(retriever, "filter_top_k_events", return_value=[]),
534
- ):
535
- mock_vector_engine = AsyncMock()
536
- mock_vector_engine.embedding_engine = AsyncMock()
537
- mock_vector_engine.embedding_engine.embed_text = AsyncMock(return_value=[[0.1, 0.2, 0.3]])
538
- mock_vector_engine.search = AsyncMock(return_value=[])
539
- mock_get_vector.return_value = mock_vector_engine
540
-
541
- mock_graph_engine.collect_time_ids.return_value = ["e1"]
542
- mock_graph_engine.collect_events.return_value = [
543
- {
544
- "events": [
545
- {"id": "e1", "description": ""},
546
- ]
547
- }
548
- ]
549
-
550
- with pytest.raises((UnboundLocalError, NameError)):
551
- await retriever.get_completion("test query")
552
-
553
-
554
536
  @pytest.mark.asyncio
555
537
  async def test_get_completion_with_response_model(mock_graph_engine, mock_vector_engine):
556
538
  """Test get_completion with custom response model."""
@@ -570,7 +552,7 @@ async def test_get_completion_with_response_model(mock_graph_engine, mock_vector
570
552
  }
571
553
  ]
572
554
 
573
- mock_result = SimpleNamespace(payload={"id": "e1"}, score=0.05)
555
+ mock_result = SimpleNamespace(id="e1", payload={"id": "e1"}, score=0.05)
574
556
  mock_vector_engine.search.return_value = [mock_result]
575
557
 
576
558
  with (
@@ -595,8 +577,10 @@ async def test_get_completion_with_response_model(mock_graph_engine, mock_vector
595
577
  mock_config.caching = False
596
578
  mock_cache_config.return_value = mock_config
597
579
 
598
- completion = await retriever.get_completion(
599
- "What happened in 2024?", response_model=TestModel
580
+ objects = await retriever.get_retrieved_objects("What happened in 2024?")
581
+ context = await retriever.get_context_from_objects("What happened in 2024?", objects)
582
+ completion = await retriever.get_completion_from_context(
583
+ "What happened in 2024?", objects, context
600
584
  )
601
585
 
602
586
  assert isinstance(completion, list)