cognee 0.2.4__py3-none-any.whl → 0.3.0.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.
- cognee/__init__.py +1 -0
- cognee/api/client.py +28 -3
- cognee/api/health.py +10 -13
- cognee/api/v1/add/add.py +3 -1
- cognee/api/v1/add/routers/get_add_router.py +12 -37
- cognee/api/v1/cloud/routers/__init__.py +1 -0
- cognee/api/v1/cloud/routers/get_checks_router.py +23 -0
- cognee/api/v1/cognify/code_graph_pipeline.py +9 -4
- cognee/api/v1/cognify/cognify.py +50 -3
- cognee/api/v1/cognify/routers/get_cognify_router.py +1 -1
- cognee/api/v1/datasets/routers/get_datasets_router.py +15 -4
- cognee/api/v1/memify/__init__.py +0 -0
- cognee/api/v1/memify/routers/__init__.py +1 -0
- cognee/api/v1/memify/routers/get_memify_router.py +100 -0
- cognee/api/v1/notebooks/routers/__init__.py +1 -0
- cognee/api/v1/notebooks/routers/get_notebooks_router.py +96 -0
- cognee/api/v1/search/routers/get_search_router.py +20 -1
- cognee/api/v1/search/search.py +11 -4
- cognee/api/v1/sync/__init__.py +17 -0
- cognee/api/v1/sync/routers/__init__.py +3 -0
- cognee/api/v1/sync/routers/get_sync_router.py +241 -0
- cognee/api/v1/sync/sync.py +877 -0
- cognee/api/v1/users/routers/get_auth_router.py +13 -1
- cognee/base_config.py +10 -1
- cognee/infrastructure/databases/graph/config.py +10 -4
- cognee/infrastructure/databases/graph/kuzu/adapter.py +135 -0
- cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +89 -0
- cognee/infrastructure/databases/relational/__init__.py +2 -0
- cognee/infrastructure/databases/relational/get_async_session.py +15 -0
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +6 -1
- cognee/infrastructure/databases/relational/with_async_session.py +25 -0
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +1 -1
- cognee/infrastructure/databases/vector/config.py +13 -6
- cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +1 -1
- cognee/infrastructure/databases/vector/embeddings/embedding_rate_limiter.py +2 -6
- cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +4 -1
- cognee/infrastructure/files/storage/LocalFileStorage.py +9 -0
- cognee/infrastructure/files/storage/S3FileStorage.py +5 -0
- cognee/infrastructure/files/storage/StorageManager.py +7 -1
- cognee/infrastructure/files/storage/storage.py +16 -0
- cognee/infrastructure/llm/LLMGateway.py +18 -0
- cognee/infrastructure/llm/config.py +4 -2
- cognee/infrastructure/llm/prompts/extract_query_time.txt +15 -0
- cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +25 -0
- cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +30 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +2 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_event_entities.py +44 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/__init__.py +1 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_event_graph.py +46 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +25 -1
- cognee/infrastructure/utils/run_sync.py +8 -1
- cognee/modules/chunking/models/DocumentChunk.py +4 -3
- cognee/modules/cloud/exceptions/CloudApiKeyMissingError.py +15 -0
- cognee/modules/cloud/exceptions/CloudConnectionError.py +15 -0
- cognee/modules/cloud/exceptions/__init__.py +2 -0
- cognee/modules/cloud/operations/__init__.py +1 -0
- cognee/modules/cloud/operations/check_api_key.py +25 -0
- cognee/modules/data/deletion/prune_system.py +1 -1
- cognee/modules/data/methods/check_dataset_name.py +1 -1
- cognee/modules/data/methods/get_dataset_data.py +1 -1
- cognee/modules/data/methods/load_or_create_datasets.py +1 -1
- cognee/modules/engine/models/Event.py +16 -0
- cognee/modules/engine/models/Interval.py +8 -0
- cognee/modules/engine/models/Timestamp.py +13 -0
- cognee/modules/engine/models/__init__.py +3 -0
- cognee/modules/engine/utils/__init__.py +2 -0
- cognee/modules/engine/utils/generate_event_datapoint.py +46 -0
- cognee/modules/engine/utils/generate_timestamp_datapoint.py +51 -0
- cognee/modules/graph/cognee_graph/CogneeGraph.py +2 -2
- cognee/modules/graph/utils/__init__.py +1 -0
- cognee/modules/graph/utils/resolve_edges_to_text.py +71 -0
- cognee/modules/memify/__init__.py +1 -0
- cognee/modules/memify/memify.py +118 -0
- cognee/modules/notebooks/methods/__init__.py +5 -0
- cognee/modules/notebooks/methods/create_notebook.py +26 -0
- cognee/modules/notebooks/methods/delete_notebook.py +13 -0
- cognee/modules/notebooks/methods/get_notebook.py +21 -0
- cognee/modules/notebooks/methods/get_notebooks.py +18 -0
- cognee/modules/notebooks/methods/update_notebook.py +17 -0
- cognee/modules/notebooks/models/Notebook.py +53 -0
- cognee/modules/notebooks/models/__init__.py +1 -0
- cognee/modules/notebooks/operations/__init__.py +1 -0
- cognee/modules/notebooks/operations/run_in_local_sandbox.py +55 -0
- cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +19 -3
- cognee/modules/pipelines/operations/pipeline.py +1 -0
- cognee/modules/pipelines/operations/run_tasks.py +17 -41
- cognee/modules/retrieval/base_graph_retriever.py +18 -0
- cognee/modules/retrieval/base_retriever.py +1 -1
- cognee/modules/retrieval/code_retriever.py +8 -0
- cognee/modules/retrieval/coding_rules_retriever.py +31 -0
- cognee/modules/retrieval/completion_retriever.py +9 -3
- cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -0
- cognee/modules/retrieval/graph_completion_context_extension_retriever.py +23 -14
- cognee/modules/retrieval/graph_completion_cot_retriever.py +21 -11
- cognee/modules/retrieval/graph_completion_retriever.py +32 -65
- cognee/modules/retrieval/graph_summary_completion_retriever.py +3 -1
- cognee/modules/retrieval/insights_retriever.py +14 -3
- cognee/modules/retrieval/summaries_retriever.py +1 -1
- cognee/modules/retrieval/temporal_retriever.py +152 -0
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +7 -32
- cognee/modules/retrieval/utils/completion.py +10 -3
- cognee/modules/search/methods/get_search_type_tools.py +168 -0
- cognee/modules/search/methods/no_access_control_search.py +47 -0
- cognee/modules/search/methods/search.py +219 -139
- cognee/modules/search/types/SearchResult.py +21 -0
- cognee/modules/search/types/SearchType.py +2 -0
- cognee/modules/search/types/__init__.py +1 -0
- cognee/modules/search/utils/__init__.py +2 -0
- cognee/modules/search/utils/prepare_search_result.py +41 -0
- cognee/modules/search/utils/transform_context_to_graph.py +38 -0
- cognee/modules/sync/__init__.py +1 -0
- cognee/modules/sync/methods/__init__.py +23 -0
- cognee/modules/sync/methods/create_sync_operation.py +53 -0
- cognee/modules/sync/methods/get_sync_operation.py +107 -0
- cognee/modules/sync/methods/update_sync_operation.py +248 -0
- cognee/modules/sync/models/SyncOperation.py +142 -0
- cognee/modules/sync/models/__init__.py +3 -0
- cognee/modules/users/__init__.py +0 -1
- cognee/modules/users/methods/__init__.py +4 -1
- cognee/modules/users/methods/create_user.py +26 -1
- cognee/modules/users/methods/get_authenticated_user.py +36 -42
- cognee/modules/users/methods/get_default_user.py +3 -1
- cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +2 -1
- cognee/root_dir.py +19 -0
- cognee/shared/logging_utils.py +1 -1
- cognee/tasks/codingagents/__init__.py +0 -0
- cognee/tasks/codingagents/coding_rule_associations.py +127 -0
- cognee/tasks/ingestion/save_data_item_to_storage.py +23 -0
- cognee/tasks/memify/__init__.py +2 -0
- cognee/tasks/memify/extract_subgraph.py +7 -0
- cognee/tasks/memify/extract_subgraph_chunks.py +11 -0
- cognee/tasks/repo_processor/get_repo_file_dependencies.py +52 -27
- cognee/tasks/temporal_graph/__init__.py +1 -0
- cognee/tasks/temporal_graph/add_entities_to_event.py +85 -0
- cognee/tasks/temporal_graph/enrich_events.py +34 -0
- cognee/tasks/temporal_graph/extract_events_and_entities.py +32 -0
- cognee/tasks/temporal_graph/extract_knowledge_graph_from_events.py +41 -0
- cognee/tasks/temporal_graph/models.py +49 -0
- cognee/tests/test_kuzu.py +4 -4
- cognee/tests/test_neo4j.py +4 -4
- cognee/tests/test_permissions.py +3 -3
- cognee/tests/test_relational_db_migration.py +7 -5
- cognee/tests/test_search_db.py +18 -24
- cognee/tests/test_temporal_graph.py +167 -0
- cognee/tests/unit/api/__init__.py +1 -0
- cognee/tests/unit/api/test_conditional_authentication_endpoints.py +246 -0
- cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +18 -2
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +13 -16
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +11 -16
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +5 -4
- cognee/tests/unit/modules/retrieval/insights_retriever_test.py +4 -2
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +18 -2
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +225 -0
- cognee/tests/unit/modules/users/__init__.py +1 -0
- cognee/tests/unit/modules/users/test_conditional_authentication.py +277 -0
- cognee/tests/unit/processing/utils/utils_test.py +20 -1
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.dist-info}/METADATA +8 -6
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.dist-info}/RECORD +162 -89
- cognee/tests/unit/modules/search/search_methods_test.py +0 -225
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.dist-info}/entry_points.txt +0 -0
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.4.dist-info → cognee-0.3.0.dev0.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|