cognee 0.2.4__py3-none-any.whl → 0.3.0__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 (166) hide show
  1. cognee/__init__.py +2 -0
  2. cognee/api/client.py +28 -3
  3. cognee/api/health.py +10 -13
  4. cognee/api/v1/add/add.py +3 -1
  5. cognee/api/v1/add/routers/get_add_router.py +12 -37
  6. cognee/api/v1/cloud/routers/__init__.py +1 -0
  7. cognee/api/v1/cloud/routers/get_checks_router.py +23 -0
  8. cognee/api/v1/cognify/code_graph_pipeline.py +9 -4
  9. cognee/api/v1/cognify/cognify.py +50 -3
  10. cognee/api/v1/cognify/routers/get_cognify_router.py +1 -1
  11. cognee/api/v1/datasets/routers/get_datasets_router.py +15 -4
  12. cognee/api/v1/memify/__init__.py +0 -0
  13. cognee/api/v1/memify/routers/__init__.py +1 -0
  14. cognee/api/v1/memify/routers/get_memify_router.py +100 -0
  15. cognee/api/v1/notebooks/routers/__init__.py +1 -0
  16. cognee/api/v1/notebooks/routers/get_notebooks_router.py +96 -0
  17. cognee/api/v1/search/routers/get_search_router.py +20 -1
  18. cognee/api/v1/search/search.py +11 -4
  19. cognee/api/v1/sync/__init__.py +17 -0
  20. cognee/api/v1/sync/routers/__init__.py +3 -0
  21. cognee/api/v1/sync/routers/get_sync_router.py +241 -0
  22. cognee/api/v1/sync/sync.py +877 -0
  23. cognee/api/v1/ui/__init__.py +1 -0
  24. cognee/api/v1/ui/ui.py +529 -0
  25. cognee/api/v1/users/routers/get_auth_router.py +13 -1
  26. cognee/base_config.py +10 -1
  27. cognee/cli/_cognee.py +93 -0
  28. cognee/infrastructure/databases/graph/config.py +10 -4
  29. cognee/infrastructure/databases/graph/kuzu/adapter.py +135 -0
  30. cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +89 -0
  31. cognee/infrastructure/databases/relational/__init__.py +2 -0
  32. cognee/infrastructure/databases/relational/get_async_session.py +15 -0
  33. cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +6 -1
  34. cognee/infrastructure/databases/relational/with_async_session.py +25 -0
  35. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +1 -1
  36. cognee/infrastructure/databases/vector/config.py +13 -6
  37. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +1 -1
  38. cognee/infrastructure/databases/vector/embeddings/embedding_rate_limiter.py +2 -6
  39. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +4 -1
  40. cognee/infrastructure/files/storage/LocalFileStorage.py +9 -0
  41. cognee/infrastructure/files/storage/S3FileStorage.py +5 -0
  42. cognee/infrastructure/files/storage/StorageManager.py +7 -1
  43. cognee/infrastructure/files/storage/storage.py +16 -0
  44. cognee/infrastructure/llm/LLMGateway.py +18 -0
  45. cognee/infrastructure/llm/config.py +4 -2
  46. cognee/infrastructure/llm/prompts/extract_query_time.txt +15 -0
  47. cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +25 -0
  48. cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +30 -0
  49. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +2 -0
  50. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_event_entities.py +44 -0
  51. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/__init__.py +1 -0
  52. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_event_graph.py +46 -0
  53. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +25 -1
  54. cognee/infrastructure/utils/run_sync.py +8 -1
  55. cognee/modules/chunking/models/DocumentChunk.py +4 -3
  56. cognee/modules/cloud/exceptions/CloudApiKeyMissingError.py +15 -0
  57. cognee/modules/cloud/exceptions/CloudConnectionError.py +15 -0
  58. cognee/modules/cloud/exceptions/__init__.py +2 -0
  59. cognee/modules/cloud/operations/__init__.py +1 -0
  60. cognee/modules/cloud/operations/check_api_key.py +25 -0
  61. cognee/modules/data/deletion/prune_system.py +1 -1
  62. cognee/modules/data/methods/check_dataset_name.py +1 -1
  63. cognee/modules/data/methods/get_dataset_data.py +1 -1
  64. cognee/modules/data/methods/load_or_create_datasets.py +1 -1
  65. cognee/modules/engine/models/Event.py +16 -0
  66. cognee/modules/engine/models/Interval.py +8 -0
  67. cognee/modules/engine/models/Timestamp.py +13 -0
  68. cognee/modules/engine/models/__init__.py +3 -0
  69. cognee/modules/engine/utils/__init__.py +2 -0
  70. cognee/modules/engine/utils/generate_event_datapoint.py +46 -0
  71. cognee/modules/engine/utils/generate_timestamp_datapoint.py +51 -0
  72. cognee/modules/graph/cognee_graph/CogneeGraph.py +2 -2
  73. cognee/modules/graph/utils/__init__.py +1 -0
  74. cognee/modules/graph/utils/resolve_edges_to_text.py +71 -0
  75. cognee/modules/memify/__init__.py +1 -0
  76. cognee/modules/memify/memify.py +118 -0
  77. cognee/modules/notebooks/methods/__init__.py +5 -0
  78. cognee/modules/notebooks/methods/create_notebook.py +26 -0
  79. cognee/modules/notebooks/methods/delete_notebook.py +13 -0
  80. cognee/modules/notebooks/methods/get_notebook.py +21 -0
  81. cognee/modules/notebooks/methods/get_notebooks.py +18 -0
  82. cognee/modules/notebooks/methods/update_notebook.py +17 -0
  83. cognee/modules/notebooks/models/Notebook.py +53 -0
  84. cognee/modules/notebooks/models/__init__.py +1 -0
  85. cognee/modules/notebooks/operations/__init__.py +1 -0
  86. cognee/modules/notebooks/operations/run_in_local_sandbox.py +55 -0
  87. cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +19 -3
  88. cognee/modules/pipelines/operations/pipeline.py +1 -0
  89. cognee/modules/pipelines/operations/run_tasks.py +17 -41
  90. cognee/modules/retrieval/base_graph_retriever.py +18 -0
  91. cognee/modules/retrieval/base_retriever.py +1 -1
  92. cognee/modules/retrieval/code_retriever.py +8 -0
  93. cognee/modules/retrieval/coding_rules_retriever.py +31 -0
  94. cognee/modules/retrieval/completion_retriever.py +9 -3
  95. cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -0
  96. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +23 -14
  97. cognee/modules/retrieval/graph_completion_cot_retriever.py +21 -11
  98. cognee/modules/retrieval/graph_completion_retriever.py +32 -65
  99. cognee/modules/retrieval/graph_summary_completion_retriever.py +3 -1
  100. cognee/modules/retrieval/insights_retriever.py +14 -3
  101. cognee/modules/retrieval/summaries_retriever.py +1 -1
  102. cognee/modules/retrieval/temporal_retriever.py +152 -0
  103. cognee/modules/retrieval/utils/brute_force_triplet_search.py +7 -32
  104. cognee/modules/retrieval/utils/completion.py +10 -3
  105. cognee/modules/search/methods/get_search_type_tools.py +168 -0
  106. cognee/modules/search/methods/no_access_control_search.py +47 -0
  107. cognee/modules/search/methods/search.py +219 -139
  108. cognee/modules/search/types/SearchResult.py +21 -0
  109. cognee/modules/search/types/SearchType.py +2 -0
  110. cognee/modules/search/types/__init__.py +1 -0
  111. cognee/modules/search/utils/__init__.py +2 -0
  112. cognee/modules/search/utils/prepare_search_result.py +41 -0
  113. cognee/modules/search/utils/transform_context_to_graph.py +38 -0
  114. cognee/modules/sync/__init__.py +1 -0
  115. cognee/modules/sync/methods/__init__.py +23 -0
  116. cognee/modules/sync/methods/create_sync_operation.py +53 -0
  117. cognee/modules/sync/methods/get_sync_operation.py +107 -0
  118. cognee/modules/sync/methods/update_sync_operation.py +248 -0
  119. cognee/modules/sync/models/SyncOperation.py +142 -0
  120. cognee/modules/sync/models/__init__.py +3 -0
  121. cognee/modules/users/__init__.py +0 -1
  122. cognee/modules/users/methods/__init__.py +4 -1
  123. cognee/modules/users/methods/create_user.py +26 -1
  124. cognee/modules/users/methods/get_authenticated_user.py +36 -42
  125. cognee/modules/users/methods/get_default_user.py +3 -1
  126. cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +2 -1
  127. cognee/root_dir.py +19 -0
  128. cognee/shared/logging_utils.py +1 -1
  129. cognee/tasks/codingagents/__init__.py +0 -0
  130. cognee/tasks/codingagents/coding_rule_associations.py +127 -0
  131. cognee/tasks/ingestion/save_data_item_to_storage.py +23 -0
  132. cognee/tasks/memify/__init__.py +2 -0
  133. cognee/tasks/memify/extract_subgraph.py +7 -0
  134. cognee/tasks/memify/extract_subgraph_chunks.py +11 -0
  135. cognee/tasks/repo_processor/get_repo_file_dependencies.py +52 -27
  136. cognee/tasks/temporal_graph/__init__.py +1 -0
  137. cognee/tasks/temporal_graph/add_entities_to_event.py +85 -0
  138. cognee/tasks/temporal_graph/enrich_events.py +34 -0
  139. cognee/tasks/temporal_graph/extract_events_and_entities.py +32 -0
  140. cognee/tasks/temporal_graph/extract_knowledge_graph_from_events.py +41 -0
  141. cognee/tasks/temporal_graph/models.py +49 -0
  142. cognee/tests/test_kuzu.py +4 -4
  143. cognee/tests/test_neo4j.py +4 -4
  144. cognee/tests/test_permissions.py +3 -3
  145. cognee/tests/test_relational_db_migration.py +7 -5
  146. cognee/tests/test_search_db.py +18 -24
  147. cognee/tests/test_temporal_graph.py +167 -0
  148. cognee/tests/unit/api/__init__.py +1 -0
  149. cognee/tests/unit/api/test_conditional_authentication_endpoints.py +246 -0
  150. cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +18 -2
  151. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +13 -16
  152. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +11 -16
  153. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +5 -4
  154. cognee/tests/unit/modules/retrieval/insights_retriever_test.py +4 -2
  155. cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +18 -2
  156. cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +225 -0
  157. cognee/tests/unit/modules/users/__init__.py +1 -0
  158. cognee/tests/unit/modules/users/test_conditional_authentication.py +277 -0
  159. cognee/tests/unit/processing/utils/utils_test.py +20 -1
  160. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/METADATA +8 -6
  161. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/RECORD +165 -90
  162. cognee/tests/unit/modules/search/search_methods_test.py +0 -225
  163. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/WHEEL +0 -0
  164. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/entry_points.txt +0 -0
  165. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/licenses/LICENSE +0 -0
  166. {cognee-0.2.4.dist-info → cognee-0.3.0.dist-info}/licenses/NOTICE.md +0 -0
@@ -1,225 +0,0 @@
1
- import json
2
- import uuid
3
- from unittest.mock import AsyncMock, MagicMock, patch
4
-
5
- import pytest
6
- from pylint.checkers.utils import node_type
7
-
8
- from cognee.modules.search.exceptions import UnsupportedSearchTypeError
9
- from cognee.modules.search.methods.search import search, specific_search
10
- from cognee.modules.search.types import SearchType
11
- from cognee.modules.users.models import User
12
- import sys
13
-
14
- search_module = sys.modules.get("cognee.modules.search.methods.search")
15
-
16
-
17
- @pytest.fixture
18
- def mock_user():
19
- user = MagicMock(spec=User)
20
- user.id = uuid.uuid4()
21
- return user
22
-
23
-
24
- @pytest.mark.asyncio
25
- @patch.object(search_module, "log_query")
26
- @patch.object(search_module, "log_result")
27
- @patch.object(search_module, "specific_search")
28
- async def test_search(
29
- mock_specific_search,
30
- mock_log_result,
31
- mock_log_query,
32
- mock_user,
33
- ):
34
- # Setup
35
- query_text = "test query"
36
- query_type = SearchType.CHUNKS
37
- datasets = ["dataset1", "dataset2"]
38
-
39
- # Mock the query logging
40
- mock_query = MagicMock()
41
- mock_query.id = uuid.uuid4()
42
- mock_log_query.return_value = mock_query
43
-
44
- # Mock document IDs
45
- doc_id1 = uuid.uuid4()
46
- doc_id2 = uuid.uuid4()
47
-
48
- # Mock search results
49
- search_results = [
50
- {"document_id": str(doc_id1), "content": "Result 1"},
51
- {"document_id": str(doc_id2), "content": "Result 2"},
52
- ]
53
- mock_specific_search.return_value = search_results
54
-
55
- # Execute
56
- await search(query_text, query_type, datasets, mock_user)
57
-
58
- # Verify
59
- mock_log_query.assert_called_once_with(query_text, query_type.value, mock_user.id)
60
- mock_specific_search.assert_called_once_with(
61
- query_type,
62
- query_text,
63
- mock_user,
64
- system_prompt_path="answer_simple_question.txt",
65
- top_k=10,
66
- node_type=None,
67
- node_name=None,
68
- save_interaction=False,
69
- last_k=None,
70
- )
71
-
72
- # Verify result logging
73
- mock_log_result.assert_called_once()
74
- # Check that the first argument is the query ID
75
- assert mock_log_result.call_args[0][0] == mock_query.id
76
- # The second argument should be the JSON string of the filtered results
77
- # We can't directly compare the JSON strings due to potential ordering differences
78
- # So we parse the JSON and compare the objects
79
- logged_results = json.loads(mock_log_result.call_args[0][1])
80
- assert len(logged_results) == 2
81
- assert logged_results[0]["document_id"] == str(doc_id1)
82
- assert logged_results[1]["document_id"] == str(doc_id2)
83
-
84
-
85
- @pytest.mark.asyncio
86
- @patch.object(search_module, "SummariesRetriever")
87
- @patch.object(search_module, "send_telemetry")
88
- async def test_specific_search_summaries(mock_send_telemetry, mock_summaries_retriever, mock_user):
89
- # Setup
90
- query = "test query"
91
- query_type = SearchType.SUMMARIES
92
-
93
- # Mock the retriever
94
- mock_retriever = MagicMock()
95
- mock_retriever.get_completion = AsyncMock()
96
- mock_retriever.get_completion.return_value = [{"content": "Summary result"}]
97
- mock_summaries_retriever.return_value = mock_retriever
98
-
99
- # Execute
100
- results = await specific_search(query_type, query, mock_user)
101
-
102
- # Verify
103
- mock_summaries_retriever.assert_called_once()
104
- mock_retriever.get_completion.assert_called_once_with(query)
105
- mock_send_telemetry.assert_called()
106
- assert len(results) == 1
107
- assert results[0]["content"] == "Summary result"
108
-
109
-
110
- @pytest.mark.asyncio
111
- @patch.object(search_module, "InsightsRetriever")
112
- @patch.object(search_module, "send_telemetry")
113
- async def test_specific_search_insights(mock_send_telemetry, mock_insights_retriever, mock_user):
114
- # Setup
115
- query = "test query"
116
- query_type = SearchType.INSIGHTS
117
-
118
- # Mock the retriever
119
- mock_retriever = MagicMock()
120
- mock_retriever.get_completion = AsyncMock()
121
- mock_retriever.get_completion.return_value = [{"content": "Insight result"}]
122
- mock_insights_retriever.return_value = mock_retriever
123
-
124
- # Execute
125
- results = await specific_search(query_type, query, mock_user)
126
-
127
- # Verify
128
- mock_insights_retriever.assert_called_once()
129
- mock_retriever.get_completion.assert_called_once_with(query)
130
- mock_send_telemetry.assert_called()
131
- assert len(results) == 1
132
- assert results[0]["content"] == "Insight result"
133
-
134
-
135
- @pytest.mark.asyncio
136
- @patch.object(search_module, "ChunksRetriever")
137
- @patch.object(search_module, "send_telemetry")
138
- async def test_specific_search_chunks(mock_send_telemetry, mock_chunks_retriever, mock_user):
139
- # Setup
140
- query = "test query"
141
- query_type = SearchType.CHUNKS
142
-
143
- # Mock the retriever
144
- mock_retriever = MagicMock()
145
- mock_retriever.get_completion = AsyncMock()
146
- mock_retriever.get_completion.return_value = [{"content": "Chunk result"}]
147
- mock_chunks_retriever.return_value = mock_retriever
148
-
149
- # Execute
150
- results = await specific_search(query_type, query, mock_user)
151
-
152
- # Verify
153
- mock_chunks_retriever.assert_called_once()
154
- mock_retriever.get_completion.assert_called_once_with(query)
155
- mock_send_telemetry.assert_called()
156
- assert len(results) == 1
157
- assert results[0]["content"] == "Chunk result"
158
-
159
-
160
- @pytest.mark.asyncio
161
- @pytest.mark.parametrize(
162
- "selected_type, retriever_name, expected_content, top_k",
163
- [
164
- (SearchType.RAG_COMPLETION, "CompletionRetriever", "RAG result from lucky search", 10),
165
- (SearchType.CHUNKS, "ChunksRetriever", "Chunk result from lucky search", 5),
166
- (SearchType.SUMMARIES, "SummariesRetriever", "Summary from lucky search", 15),
167
- (SearchType.INSIGHTS, "InsightsRetriever", "Insight result from lucky search", 20),
168
- ],
169
- )
170
- @patch.object(search_module, "select_search_type")
171
- @patch.object(search_module, "send_telemetry")
172
- async def test_specific_search_feeling_lucky(
173
- mock_send_telemetry,
174
- mock_select_search_type,
175
- selected_type,
176
- retriever_name,
177
- expected_content,
178
- top_k,
179
- mock_user,
180
- ):
181
- with patch.object(search_module, retriever_name) as mock_retriever_class:
182
- # Setup
183
- query = f"test query for {retriever_name}"
184
- query_type = SearchType.FEELING_LUCKY
185
-
186
- # Mock the intelligent search type selection
187
- mock_select_search_type.return_value = selected_type
188
-
189
- # Mock the retriever
190
- mock_retriever_instance = MagicMock()
191
- mock_retriever_instance.get_completion = AsyncMock(
192
- return_value=[{"content": expected_content}]
193
- )
194
- mock_retriever_class.return_value = mock_retriever_instance
195
-
196
- # Execute
197
- results = await specific_search(query_type, query, mock_user, top_k=top_k)
198
-
199
- # Verify
200
- mock_select_search_type.assert_called_once_with(query)
201
-
202
- if retriever_name == "CompletionRetriever":
203
- mock_retriever_class.assert_called_once_with(
204
- system_prompt_path="answer_simple_question.txt", top_k=top_k
205
- )
206
- else:
207
- mock_retriever_class.assert_called_once_with(top_k=top_k)
208
-
209
- mock_retriever_instance.get_completion.assert_called_once_with(query)
210
- mock_send_telemetry.assert_called()
211
- assert len(results) == 1
212
- assert results[0]["content"] == expected_content
213
-
214
-
215
- @pytest.mark.asyncio
216
- async def test_specific_search_invalid_type(mock_user):
217
- # Setup
218
- query = "test query"
219
- query_type = "INVALID_TYPE" # Not a valid SearchType
220
-
221
- # Execute and verify
222
- with pytest.raises(UnsupportedSearchTypeError) as excinfo:
223
- await specific_search(query_type, query, mock_user)
224
-
225
- assert "Unsupported search type" in str(excinfo.value)
File without changes