cognee 0.5.0.dev1__py3-none-any.whl → 0.5.1.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/api/v1/add/add.py +2 -1
- cognee/api/v1/datasets/routers/get_datasets_router.py +1 -0
- cognee/api/v1/memify/routers/get_memify_router.py +1 -0
- cognee/infrastructure/databases/relational/config.py +16 -1
- cognee/infrastructure/databases/relational/create_relational_engine.py +13 -3
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +24 -2
- cognee/infrastructure/databases/vector/create_vector_engine.py +9 -2
- cognee/infrastructure/llm/LLMGateway.py +0 -13
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +17 -12
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +31 -25
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +132 -7
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +5 -5
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llm_interface.py +2 -6
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/mistral/adapter.py +58 -13
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +0 -1
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +25 -131
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/types.py +10 -0
- cognee/modules/data/models/Data.py +2 -1
- cognee/modules/retrieval/triplet_retriever.py +1 -1
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +0 -18
- cognee/tasks/ingestion/data_item.py +8 -0
- cognee/tasks/ingestion/ingest_data.py +12 -1
- cognee/tasks/ingestion/save_data_item_to_storage.py +5 -0
- cognee/tests/integration/retrieval/test_chunks_retriever.py +252 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever.py +268 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +226 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +218 -0
- cognee/tests/integration/retrieval/test_rag_completion_retriever.py +254 -0
- cognee/tests/{unit/modules/retrieval/structured_output_test.py → integration/retrieval/test_structured_output.py} +87 -77
- cognee/tests/integration/retrieval/test_summaries_retriever.py +184 -0
- cognee/tests/integration/retrieval/test_temporal_retriever.py +306 -0
- cognee/tests/integration/retrieval/test_triplet_retriever.py +35 -0
- cognee/tests/test_custom_data_label.py +68 -0
- cognee/tests/test_search_db.py +334 -181
- cognee/tests/unit/eval_framework/benchmark_adapters_test.py +25 -0
- cognee/tests/unit/eval_framework/corpus_builder_test.py +33 -4
- cognee/tests/unit/infrastructure/databases/relational/test_RelationalConfig.py +69 -0
- cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +181 -199
- cognee/tests/unit/modules/retrieval/conversation_history_test.py +338 -0
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +454 -162
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +674 -156
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +625 -200
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +319 -203
- cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +189 -155
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +539 -58
- cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +218 -9
- cognee/tests/unit/modules/retrieval/test_completion.py +343 -0
- cognee/tests/unit/modules/retrieval/test_graph_summary_completion_retriever.py +157 -0
- cognee/tests/unit/modules/retrieval/test_user_qa_feedback.py +312 -0
- cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +246 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/METADATA +1 -1
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/RECORD +56 -42
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.0.dev1.dist-info → cognee-0.5.1.dev0.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -152,3 +152,341 @@ class TestConversationHistoryUtils:
|
|
|
152
152
|
assert result is True
|
|
153
153
|
call_kwargs = mock_cache.add_qa.call_args.kwargs
|
|
154
154
|
assert call_kwargs["session_id"] == "default_session"
|
|
155
|
+
|
|
156
|
+
@pytest.mark.asyncio
|
|
157
|
+
async def test_save_conversation_history_no_user_id(self):
|
|
158
|
+
"""Test save_conversation_history returns False when user_id is None."""
|
|
159
|
+
session_user.set(None)
|
|
160
|
+
|
|
161
|
+
with patch("cognee.modules.retrieval.utils.session_cache.CacheConfig") as MockCacheConfig:
|
|
162
|
+
mock_config = MagicMock()
|
|
163
|
+
mock_config.caching = True
|
|
164
|
+
MockCacheConfig.return_value = mock_config
|
|
165
|
+
|
|
166
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
167
|
+
save_conversation_history,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
result = await save_conversation_history(
|
|
171
|
+
query="Test question",
|
|
172
|
+
context_summary="Test context",
|
|
173
|
+
answer="Test answer",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
assert result is False
|
|
177
|
+
|
|
178
|
+
@pytest.mark.asyncio
|
|
179
|
+
async def test_save_conversation_history_caching_disabled(self):
|
|
180
|
+
"""Test save_conversation_history returns False when caching is disabled."""
|
|
181
|
+
user = create_mock_user()
|
|
182
|
+
session_user.set(user)
|
|
183
|
+
|
|
184
|
+
with patch("cognee.modules.retrieval.utils.session_cache.CacheConfig") as MockCacheConfig:
|
|
185
|
+
mock_config = MagicMock()
|
|
186
|
+
mock_config.caching = False
|
|
187
|
+
MockCacheConfig.return_value = mock_config
|
|
188
|
+
|
|
189
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
190
|
+
save_conversation_history,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
result = await save_conversation_history(
|
|
194
|
+
query="Test question",
|
|
195
|
+
context_summary="Test context",
|
|
196
|
+
answer="Test answer",
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
assert result is False
|
|
200
|
+
|
|
201
|
+
@pytest.mark.asyncio
|
|
202
|
+
async def test_save_conversation_history_cache_engine_none(self):
|
|
203
|
+
"""Test save_conversation_history returns False when cache_engine is None."""
|
|
204
|
+
user = create_mock_user()
|
|
205
|
+
session_user.set(user)
|
|
206
|
+
|
|
207
|
+
cache_module = importlib.import_module(
|
|
208
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
with patch.object(cache_module, "get_cache_engine", return_value=None):
|
|
212
|
+
with patch(
|
|
213
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
214
|
+
) as MockCacheConfig:
|
|
215
|
+
mock_config = MagicMock()
|
|
216
|
+
mock_config.caching = True
|
|
217
|
+
MockCacheConfig.return_value = mock_config
|
|
218
|
+
|
|
219
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
220
|
+
save_conversation_history,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
result = await save_conversation_history(
|
|
224
|
+
query="Test question",
|
|
225
|
+
context_summary="Test context",
|
|
226
|
+
answer="Test answer",
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
assert result is False
|
|
230
|
+
|
|
231
|
+
@pytest.mark.asyncio
|
|
232
|
+
async def test_save_conversation_history_cache_connection_error(self):
|
|
233
|
+
"""Test save_conversation_history handles CacheConnectionError gracefully."""
|
|
234
|
+
user = create_mock_user()
|
|
235
|
+
session_user.set(user)
|
|
236
|
+
|
|
237
|
+
from cognee.infrastructure.databases.exceptions import CacheConnectionError
|
|
238
|
+
|
|
239
|
+
mock_cache = create_mock_cache_engine([])
|
|
240
|
+
mock_cache.add_qa = AsyncMock(side_effect=CacheConnectionError("Connection failed"))
|
|
241
|
+
|
|
242
|
+
cache_module = importlib.import_module(
|
|
243
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
247
|
+
with patch(
|
|
248
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
249
|
+
) as MockCacheConfig:
|
|
250
|
+
mock_config = MagicMock()
|
|
251
|
+
mock_config.caching = True
|
|
252
|
+
MockCacheConfig.return_value = mock_config
|
|
253
|
+
|
|
254
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
255
|
+
save_conversation_history,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
result = await save_conversation_history(
|
|
259
|
+
query="Test question",
|
|
260
|
+
context_summary="Test context",
|
|
261
|
+
answer="Test answer",
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
assert result is False
|
|
265
|
+
|
|
266
|
+
@pytest.mark.asyncio
|
|
267
|
+
async def test_save_conversation_history_generic_exception(self):
|
|
268
|
+
"""Test save_conversation_history handles generic exceptions gracefully."""
|
|
269
|
+
user = create_mock_user()
|
|
270
|
+
session_user.set(user)
|
|
271
|
+
|
|
272
|
+
mock_cache = create_mock_cache_engine([])
|
|
273
|
+
mock_cache.add_qa = AsyncMock(side_effect=ValueError("Unexpected error"))
|
|
274
|
+
|
|
275
|
+
cache_module = importlib.import_module(
|
|
276
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
280
|
+
with patch(
|
|
281
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
282
|
+
) as MockCacheConfig:
|
|
283
|
+
mock_config = MagicMock()
|
|
284
|
+
mock_config.caching = True
|
|
285
|
+
MockCacheConfig.return_value = mock_config
|
|
286
|
+
|
|
287
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
288
|
+
save_conversation_history,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
result = await save_conversation_history(
|
|
292
|
+
query="Test question",
|
|
293
|
+
context_summary="Test context",
|
|
294
|
+
answer="Test answer",
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
assert result is False
|
|
298
|
+
|
|
299
|
+
@pytest.mark.asyncio
|
|
300
|
+
async def test_get_conversation_history_no_user_id(self):
|
|
301
|
+
"""Test get_conversation_history returns empty string when user_id is None."""
|
|
302
|
+
session_user.set(None)
|
|
303
|
+
|
|
304
|
+
with patch("cognee.modules.retrieval.utils.session_cache.CacheConfig") as MockCacheConfig:
|
|
305
|
+
mock_config = MagicMock()
|
|
306
|
+
mock_config.caching = True
|
|
307
|
+
MockCacheConfig.return_value = mock_config
|
|
308
|
+
|
|
309
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
310
|
+
get_conversation_history,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
result = await get_conversation_history(session_id="test_session")
|
|
314
|
+
|
|
315
|
+
assert result == ""
|
|
316
|
+
|
|
317
|
+
@pytest.mark.asyncio
|
|
318
|
+
async def test_get_conversation_history_caching_disabled(self):
|
|
319
|
+
"""Test get_conversation_history returns empty string when caching is disabled."""
|
|
320
|
+
user = create_mock_user()
|
|
321
|
+
session_user.set(user)
|
|
322
|
+
|
|
323
|
+
with patch("cognee.modules.retrieval.utils.session_cache.CacheConfig") as MockCacheConfig:
|
|
324
|
+
mock_config = MagicMock()
|
|
325
|
+
mock_config.caching = False
|
|
326
|
+
MockCacheConfig.return_value = mock_config
|
|
327
|
+
|
|
328
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
329
|
+
get_conversation_history,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
result = await get_conversation_history(session_id="test_session")
|
|
333
|
+
|
|
334
|
+
assert result == ""
|
|
335
|
+
|
|
336
|
+
@pytest.mark.asyncio
|
|
337
|
+
async def test_get_conversation_history_default_session(self):
|
|
338
|
+
"""Test get_conversation_history uses 'default_session' when session_id is None."""
|
|
339
|
+
user = create_mock_user()
|
|
340
|
+
session_user.set(user)
|
|
341
|
+
|
|
342
|
+
mock_cache = create_mock_cache_engine([])
|
|
343
|
+
|
|
344
|
+
cache_module = importlib.import_module(
|
|
345
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
349
|
+
with patch(
|
|
350
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
351
|
+
) as MockCacheConfig:
|
|
352
|
+
mock_config = MagicMock()
|
|
353
|
+
mock_config.caching = True
|
|
354
|
+
MockCacheConfig.return_value = mock_config
|
|
355
|
+
|
|
356
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
357
|
+
get_conversation_history,
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
await get_conversation_history(session_id=None)
|
|
361
|
+
|
|
362
|
+
mock_cache.get_latest_qa.assert_called_once_with(str(user.id), "default_session")
|
|
363
|
+
|
|
364
|
+
@pytest.mark.asyncio
|
|
365
|
+
async def test_get_conversation_history_cache_engine_none(self):
|
|
366
|
+
"""Test get_conversation_history returns empty string when cache_engine is None."""
|
|
367
|
+
user = create_mock_user()
|
|
368
|
+
session_user.set(user)
|
|
369
|
+
|
|
370
|
+
cache_module = importlib.import_module(
|
|
371
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
with patch.object(cache_module, "get_cache_engine", return_value=None):
|
|
375
|
+
with patch(
|
|
376
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
377
|
+
) as MockCacheConfig:
|
|
378
|
+
mock_config = MagicMock()
|
|
379
|
+
mock_config.caching = True
|
|
380
|
+
MockCacheConfig.return_value = mock_config
|
|
381
|
+
|
|
382
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
383
|
+
get_conversation_history,
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
result = await get_conversation_history(session_id="test_session")
|
|
387
|
+
|
|
388
|
+
assert result == ""
|
|
389
|
+
|
|
390
|
+
@pytest.mark.asyncio
|
|
391
|
+
async def test_get_conversation_history_cache_connection_error(self):
|
|
392
|
+
"""Test get_conversation_history handles CacheConnectionError gracefully."""
|
|
393
|
+
user = create_mock_user()
|
|
394
|
+
session_user.set(user)
|
|
395
|
+
|
|
396
|
+
from cognee.infrastructure.databases.exceptions import CacheConnectionError
|
|
397
|
+
|
|
398
|
+
mock_cache = create_mock_cache_engine([])
|
|
399
|
+
mock_cache.get_latest_qa = AsyncMock(side_effect=CacheConnectionError("Connection failed"))
|
|
400
|
+
|
|
401
|
+
cache_module = importlib.import_module(
|
|
402
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
406
|
+
with patch(
|
|
407
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
408
|
+
) as MockCacheConfig:
|
|
409
|
+
mock_config = MagicMock()
|
|
410
|
+
mock_config.caching = True
|
|
411
|
+
MockCacheConfig.return_value = mock_config
|
|
412
|
+
|
|
413
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
414
|
+
get_conversation_history,
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
result = await get_conversation_history(session_id="test_session")
|
|
418
|
+
|
|
419
|
+
assert result == ""
|
|
420
|
+
|
|
421
|
+
@pytest.mark.asyncio
|
|
422
|
+
async def test_get_conversation_history_generic_exception(self):
|
|
423
|
+
"""Test get_conversation_history handles generic exceptions gracefully."""
|
|
424
|
+
user = create_mock_user()
|
|
425
|
+
session_user.set(user)
|
|
426
|
+
|
|
427
|
+
mock_cache = create_mock_cache_engine([])
|
|
428
|
+
mock_cache.get_latest_qa = AsyncMock(side_effect=ValueError("Unexpected error"))
|
|
429
|
+
|
|
430
|
+
cache_module = importlib.import_module(
|
|
431
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
435
|
+
with patch(
|
|
436
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
437
|
+
) as MockCacheConfig:
|
|
438
|
+
mock_config = MagicMock()
|
|
439
|
+
mock_config.caching = True
|
|
440
|
+
MockCacheConfig.return_value = mock_config
|
|
441
|
+
|
|
442
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
443
|
+
get_conversation_history,
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
result = await get_conversation_history(session_id="test_session")
|
|
447
|
+
|
|
448
|
+
assert result == ""
|
|
449
|
+
|
|
450
|
+
@pytest.mark.asyncio
|
|
451
|
+
async def test_get_conversation_history_missing_keys(self):
|
|
452
|
+
"""Test get_conversation_history handles missing keys in history entries."""
|
|
453
|
+
user = create_mock_user()
|
|
454
|
+
session_user.set(user)
|
|
455
|
+
|
|
456
|
+
mock_history = [
|
|
457
|
+
{
|
|
458
|
+
"time": "2024-01-15 10:30:45",
|
|
459
|
+
"question": "What is AI?",
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
"context": "AI is artificial intelligence",
|
|
463
|
+
"answer": "AI stands for Artificial Intelligence",
|
|
464
|
+
},
|
|
465
|
+
{},
|
|
466
|
+
]
|
|
467
|
+
mock_cache = create_mock_cache_engine(mock_history)
|
|
468
|
+
|
|
469
|
+
cache_module = importlib.import_module(
|
|
470
|
+
"cognee.infrastructure.databases.cache.get_cache_engine"
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
with patch.object(cache_module, "get_cache_engine", return_value=mock_cache):
|
|
474
|
+
with patch(
|
|
475
|
+
"cognee.modules.retrieval.utils.session_cache.CacheConfig"
|
|
476
|
+
) as MockCacheConfig:
|
|
477
|
+
mock_config = MagicMock()
|
|
478
|
+
mock_config.caching = True
|
|
479
|
+
MockCacheConfig.return_value = mock_config
|
|
480
|
+
|
|
481
|
+
from cognee.modules.retrieval.utils.session_cache import (
|
|
482
|
+
get_conversation_history,
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
result = await get_conversation_history(session_id="test_session")
|
|
486
|
+
|
|
487
|
+
assert "Previous conversation:" in result
|
|
488
|
+
assert "[2024-01-15 10:30:45]" in result
|
|
489
|
+
assert "QUESTION: What is AI?" in result
|
|
490
|
+
assert "Unknown time" in result
|
|
491
|
+
assert "CONTEXT: AI is artificial intelligence" in result
|
|
492
|
+
assert "ANSWER: AI stands for Artificial Intelligence" in result
|