cognee 0.5.1__py3-none-any.whl → 0.5.2__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 +2 -0
- cognee/alembic/README +1 -0
- cognee/alembic/env.py +107 -0
- cognee/alembic/script.py.mako +26 -0
- cognee/alembic/versions/1a58b986e6e1_enable_delete_for_old_tutorial_notebooks.py +52 -0
- cognee/alembic/versions/1d0bb7fede17_add_pipeline_run_status.py +33 -0
- cognee/alembic/versions/1daae0df1866_incremental_loading.py +48 -0
- cognee/alembic/versions/211ab850ef3d_add_sync_operations_table.py +118 -0
- cognee/alembic/versions/45957f0a9849_add_notebook_table.py +46 -0
- cognee/alembic/versions/46a6ce2bd2b2_expand_dataset_database_with_json_.py +333 -0
- cognee/alembic/versions/482cd6517ce4_add_default_user.py +30 -0
- cognee/alembic/versions/76625596c5c3_expand_dataset_database_for_multi_user.py +98 -0
- cognee/alembic/versions/8057ae7329c2_initial_migration.py +25 -0
- cognee/alembic/versions/9e7a3cb85175_loader_separation.py +104 -0
- cognee/alembic/versions/a1b2c3d4e5f6_add_label_column_to_data.py +38 -0
- cognee/alembic/versions/ab7e313804ae_permission_system_rework.py +236 -0
- cognee/alembic/versions/b9274c27a25a_kuzu_11_migration.py +75 -0
- cognee/alembic/versions/c946955da633_multi_tenant_support.py +137 -0
- cognee/alembic/versions/e1ec1dcb50b6_add_last_accessed_to_data.py +51 -0
- cognee/alembic/versions/e4ebee1091e7_expand_data_model_info.py +140 -0
- cognee/alembic.ini +117 -0
- cognee/api/v1/add/add.py +2 -1
- cognee/api/v1/add/routers/get_add_router.py +2 -0
- cognee/api/v1/cognify/cognify.py +11 -6
- cognee/api/v1/cognify/routers/get_cognify_router.py +8 -0
- cognee/api/v1/config/config.py +60 -0
- cognee/api/v1/datasets/routers/get_datasets_router.py +46 -3
- cognee/api/v1/memify/routers/get_memify_router.py +3 -0
- cognee/api/v1/search/routers/get_search_router.py +21 -6
- cognee/api/v1/search/search.py +21 -5
- cognee/api/v1/sync/routers/get_sync_router.py +3 -3
- cognee/cli/commands/add_command.py +1 -1
- cognee/cli/commands/cognify_command.py +6 -0
- cognee/cli/commands/config_command.py +1 -1
- cognee/context_global_variables.py +5 -1
- cognee/eval_framework/answer_generation/answer_generation_executor.py +7 -8
- cognee/infrastructure/databases/cache/cache_db_interface.py +38 -1
- cognee/infrastructure/databases/cache/config.py +6 -0
- cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py +21 -0
- cognee/infrastructure/databases/cache/get_cache_engine.py +9 -3
- cognee/infrastructure/databases/cache/redis/RedisAdapter.py +60 -1
- cognee/infrastructure/databases/dataset_database_handler/supported_dataset_database_handlers.py +7 -0
- cognee/infrastructure/databases/graph/get_graph_engine.py +29 -1
- cognee/infrastructure/databases/graph/neo4j_driver/Neo4jAuraDevDatasetDatabaseHandler.py +62 -27
- cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +17 -4
- 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 +26 -3
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -0
- cognee/infrastructure/databases/vector/config.py +6 -0
- cognee/infrastructure/databases/vector/create_vector_engine.py +70 -16
- cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +64 -9
- cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +13 -2
- cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +16 -3
- cognee/infrastructure/databases/vector/models/ScoredResult.py +3 -3
- cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +16 -3
- cognee/infrastructure/databases/vector/pgvector/PGVectorDatasetDatabaseHandler.py +86 -0
- cognee/infrastructure/databases/vector/pgvector/create_db_and_tables.py +81 -2
- cognee/infrastructure/databases/vector/vector_db_interface.py +8 -0
- cognee/infrastructure/files/utils/get_data_file_path.py +33 -27
- cognee/infrastructure/llm/LLMGateway.py +0 -13
- cognee/infrastructure/llm/prompts/extract_query_time.txt +1 -1
- cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +1 -1
- cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +1 -1
- cognee/infrastructure/llm/prompts/generate_graph_prompt.txt +2 -2
- cognee/infrastructure/llm/prompts/generate_graph_prompt_guided.txt +1 -1
- cognee/infrastructure/llm/prompts/generate_graph_prompt_oneshot.txt +2 -2
- cognee/infrastructure/llm/prompts/generate_graph_prompt_simple.txt +1 -1
- cognee/infrastructure/llm/prompts/generate_graph_prompt_strict.txt +1 -1
- cognee/infrastructure/llm/prompts/search_type_selector_prompt.txt +6 -6
- cognee/infrastructure/llm/prompts/test.txt +1 -1
- cognee/infrastructure/llm/prompts/translate_content.txt +19 -0
- 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 +29 -5
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llama_cpp/adapter.py +191 -0
- 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/chunking/models/DocumentChunk.py +0 -1
- cognee/modules/cognify/config.py +2 -0
- cognee/modules/data/models/Data.py +3 -1
- cognee/modules/engine/models/Entity.py +0 -1
- cognee/modules/engine/operations/setup.py +6 -0
- cognee/modules/graph/cognee_graph/CogneeGraph.py +150 -37
- cognee/modules/graph/cognee_graph/CogneeGraphElements.py +48 -2
- cognee/modules/graph/utils/__init__.py +1 -0
- cognee/modules/graph/utils/get_entity_nodes_from_triplets.py +12 -0
- cognee/modules/notebooks/methods/__init__.py +1 -0
- cognee/modules/notebooks/methods/create_notebook.py +0 -34
- cognee/modules/notebooks/methods/create_tutorial_notebooks.py +191 -0
- cognee/modules/notebooks/methods/get_notebooks.py +12 -8
- cognee/modules/notebooks/tutorials/cognee-basics/cell-1.md +3 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-2.md +10 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-3.md +7 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-4.py +28 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-5.py +3 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-6.py +9 -0
- cognee/modules/notebooks/tutorials/cognee-basics/cell-7.py +17 -0
- cognee/modules/notebooks/tutorials/cognee-basics/config.json +4 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-1.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-10.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-11.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-12.py +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-13.md +7 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-14.py +6 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-15.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-16.py +7 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-2.md +9 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-3.md +7 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-4.md +9 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-5.md +5 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-6.py +13 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-7.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-8.md +3 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-9.py +31 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/config.json +4 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/data/copilot_conversations.json +107 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/data/guido_contributions.json +976 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/data/my_developer_rules.md +79 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/data/pep_style_guide.md +74 -0
- cognee/modules/notebooks/tutorials/python-development-with-cognee/data/zen_principles.md +74 -0
- cognee/modules/retrieval/EntityCompletionRetriever.py +51 -38
- cognee/modules/retrieval/__init__.py +0 -1
- cognee/modules/retrieval/base_retriever.py +66 -10
- cognee/modules/retrieval/chunks_retriever.py +57 -49
- cognee/modules/retrieval/coding_rules_retriever.py +12 -5
- cognee/modules/retrieval/completion_retriever.py +29 -28
- cognee/modules/retrieval/cypher_search_retriever.py +25 -20
- cognee/modules/retrieval/graph_completion_context_extension_retriever.py +42 -46
- cognee/modules/retrieval/graph_completion_cot_retriever.py +68 -51
- cognee/modules/retrieval/graph_completion_retriever.py +78 -63
- cognee/modules/retrieval/graph_summary_completion_retriever.py +2 -0
- cognee/modules/retrieval/lexical_retriever.py +34 -12
- cognee/modules/retrieval/natural_language_retriever.py +18 -15
- cognee/modules/retrieval/summaries_retriever.py +51 -34
- cognee/modules/retrieval/temporal_retriever.py +59 -49
- cognee/modules/retrieval/triplet_retriever.py +32 -33
- cognee/modules/retrieval/utils/access_tracking.py +88 -0
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +99 -103
- cognee/modules/retrieval/utils/node_edge_vector_search.py +174 -0
- cognee/modules/search/methods/__init__.py +1 -0
- cognee/modules/search/methods/get_retriever_output.py +53 -0
- cognee/modules/search/methods/get_search_type_retriever_instance.py +252 -0
- cognee/modules/search/methods/search.py +90 -222
- cognee/modules/search/models/SearchResultPayload.py +67 -0
- cognee/modules/search/types/SearchResult.py +1 -8
- cognee/modules/search/types/SearchType.py +1 -2
- cognee/modules/search/types/__init__.py +1 -1
- cognee/modules/search/utils/__init__.py +1 -2
- cognee/modules/search/utils/transform_insights_to_graph.py +2 -2
- cognee/modules/search/utils/{transform_context_to_graph.py → transform_triplets_to_graph.py} +2 -2
- cognee/modules/users/authentication/default/default_transport.py +11 -1
- cognee/modules/users/authentication/get_api_auth_backend.py +2 -1
- cognee/modules/users/authentication/get_client_auth_backend.py +2 -1
- cognee/modules/users/methods/create_user.py +0 -9
- cognee/modules/users/permissions/methods/has_user_management_permission.py +29 -0
- cognee/modules/visualization/cognee_network_visualization.py +1 -1
- cognee/run_migrations.py +48 -0
- cognee/shared/exceptions/__init__.py +1 -3
- cognee/shared/exceptions/exceptions.py +11 -1
- cognee/shared/usage_logger.py +332 -0
- cognee/shared/utils.py +12 -5
- cognee/tasks/chunks/__init__.py +9 -0
- cognee/tasks/cleanup/cleanup_unused_data.py +172 -0
- cognee/tasks/graph/__init__.py +7 -0
- 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/tasks/memify/__init__.py +8 -0
- cognee/tasks/memify/extract_usage_frequency.py +613 -0
- cognee/tasks/summarization/models.py +0 -2
- cognee/tasks/temporal_graph/__init__.py +0 -1
- cognee/tasks/translation/__init__.py +96 -0
- cognee/tasks/translation/config.py +110 -0
- cognee/tasks/translation/detect_language.py +190 -0
- cognee/tasks/translation/exceptions.py +62 -0
- cognee/tasks/translation/models.py +72 -0
- cognee/tasks/translation/providers/__init__.py +44 -0
- cognee/tasks/translation/providers/azure_provider.py +192 -0
- cognee/tasks/translation/providers/base.py +85 -0
- cognee/tasks/translation/providers/google_provider.py +158 -0
- cognee/tasks/translation/providers/llm_provider.py +143 -0
- cognee/tasks/translation/translate_content.py +282 -0
- cognee/tasks/web_scraper/default_url_crawler.py +6 -2
- cognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py +1 -0
- cognee/tests/cli_tests/cli_unit_tests/test_cli_edge_cases.py +3 -0
- cognee/tests/integration/retrieval/test_brute_force_triplet_search_with_cognify.py +62 -0
- cognee/tests/integration/retrieval/test_chunks_retriever.py +351 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever.py +276 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +228 -0
- cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +217 -0
- cognee/tests/integration/retrieval/test_rag_completion_retriever.py +319 -0
- cognee/tests/integration/retrieval/test_structured_output.py +258 -0
- cognee/tests/integration/retrieval/test_summaries_retriever.py +195 -0
- cognee/tests/integration/retrieval/test_temporal_retriever.py +336 -0
- cognee/tests/integration/retrieval/test_triplet_retriever.py +45 -1
- cognee/tests/integration/shared/test_usage_logger_integration.py +255 -0
- cognee/tests/tasks/translation/README.md +147 -0
- cognee/tests/tasks/translation/__init__.py +1 -0
- cognee/tests/tasks/translation/config_test.py +93 -0
- cognee/tests/tasks/translation/detect_language_test.py +118 -0
- cognee/tests/tasks/translation/providers_test.py +151 -0
- cognee/tests/tasks/translation/translate_content_test.py +213 -0
- cognee/tests/test_chromadb.py +1 -1
- cognee/tests/test_cleanup_unused_data.py +165 -0
- cognee/tests/test_custom_data_label.py +68 -0
- cognee/tests/test_delete_by_id.py +6 -6
- cognee/tests/test_extract_usage_frequency.py +308 -0
- cognee/tests/test_kuzu.py +17 -7
- cognee/tests/test_lancedb.py +3 -1
- cognee/tests/test_library.py +1 -1
- cognee/tests/test_neo4j.py +17 -7
- cognee/tests/test_neptune_analytics_vector.py +3 -1
- cognee/tests/test_permissions.py +172 -187
- cognee/tests/test_pgvector.py +3 -1
- cognee/tests/test_relational_db_migration.py +15 -1
- cognee/tests/test_remote_kuzu.py +3 -1
- cognee/tests/test_s3_file_storage.py +1 -1
- cognee/tests/test_search_db.py +345 -205
- cognee/tests/test_usage_logger_e2e.py +268 -0
- cognee/tests/unit/api/test_get_raw_data_endpoint.py +206 -0
- cognee/tests/unit/eval_framework/answer_generation_test.py +4 -3
- 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/cache/test_cache_config.py +2 -0
- cognee/tests/unit/infrastructure/databases/relational/test_RelationalConfig.py +69 -0
- cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +42 -2
- cognee/tests/unit/modules/graph/cognee_graph_test.py +329 -31
- cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +122 -168
- cognee/tests/unit/modules/retrieval/conversation_history_test.py +338 -0
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +486 -157
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +693 -155
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +619 -200
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +300 -171
- cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +184 -155
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +544 -79
- cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +476 -28
- 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_node_edge_vector_search.py +273 -0
- cognee/tests/unit/modules/retrieval/test_user_qa_feedback.py +312 -0
- cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +267 -7
- cognee/tests/unit/modules/search/test_get_search_type_retriever_instance.py +125 -0
- cognee/tests/unit/modules/search/test_search.py +96 -20
- cognee/tests/unit/modules/search/test_search_prepare_search_result_contract.py +190 -0
- cognee/tests/unit/modules/users/test_tutorial_notebook_creation.py +511 -297
- cognee/tests/unit/shared/test_usage_logger.py +241 -0
- cognee/tests/unit/users/permissions/test_has_user_management_permission.py +46 -0
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/METADATA +22 -17
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/RECORD +258 -157
- cognee/api/.env.example +0 -5
- cognee/modules/retrieval/base_graph_retriever.py +0 -24
- cognee/modules/search/methods/get_search_type_tools.py +0 -223
- cognee/modules/search/methods/no_access_control_search.py +0 -62
- cognee/modules/search/utils/prepare_search_result.py +0 -63
- cognee/tests/test_feedback_enrichment.py +0 -174
- cognee/tests/unit/modules/retrieval/structured_output_test.py +0 -204
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/WHEEL +0 -0
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.1.dist-info → cognee-0.5.2.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,159 +1,188 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import pytest
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from cognee.low_level import setup
|
|
7
|
-
from cognee.tasks.storage import add_data_points
|
|
8
|
-
from cognee.infrastructure.databases.vector import get_vector_engine
|
|
9
|
-
from cognee.modules.chunking.models import DocumentChunk
|
|
10
|
-
from cognee.tasks.summarization.models import TextSummary
|
|
11
|
-
from cognee.modules.data.processing.document_types import TextDocument
|
|
12
|
-
from cognee.modules.retrieval.exceptions.exceptions import NoDataError
|
|
2
|
+
from unittest.mock import AsyncMock, patch, MagicMock
|
|
3
|
+
from types import SimpleNamespace
|
|
4
|
+
|
|
13
5
|
from cognee.modules.retrieval.summaries_retriever import SummariesRetriever
|
|
6
|
+
from cognee.modules.retrieval.exceptions.exceptions import NoDataError
|
|
7
|
+
from cognee.infrastructure.databases.vector.exceptions import CollectionNotFoundError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture
|
|
11
|
+
def mock_vector_engine():
|
|
12
|
+
"""Create a mock vector engine."""
|
|
13
|
+
engine = AsyncMock()
|
|
14
|
+
engine.search = AsyncMock()
|
|
15
|
+
return engine
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.asyncio
|
|
19
|
+
async def test_get_context_success(mock_vector_engine):
|
|
20
|
+
"""Test successful retrieval of summary context."""
|
|
21
|
+
mock_result1 = MagicMock()
|
|
22
|
+
mock_result1.payload = {"text": "S.R.", "made_from": "chunk1"}
|
|
23
|
+
mock_result2 = MagicMock()
|
|
24
|
+
mock_result2.payload = {"text": "M.B.", "made_from": "chunk2"}
|
|
25
|
+
|
|
26
|
+
mock_vector_engine.search.return_value = [mock_result1, mock_result2]
|
|
27
|
+
|
|
28
|
+
retriever = SummariesRetriever(top_k=5)
|
|
29
|
+
|
|
30
|
+
with patch(
|
|
31
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
32
|
+
return_value=mock_vector_engine,
|
|
33
|
+
):
|
|
34
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
35
|
+
context = await retriever.get_context_from_objects("test query", objects)
|
|
36
|
+
completion = await retriever.get_completion_from_context("test query", objects, context)
|
|
37
|
+
|
|
38
|
+
assert len(completion) == 2
|
|
39
|
+
assert completion[0]["text"] == "S.R."
|
|
40
|
+
assert completion[1]["text"] == "M.B."
|
|
41
|
+
mock_vector_engine.search.assert_awaited_once_with(
|
|
42
|
+
"TextSummary_text", "test query", limit=5, include_payload=True
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.mark.asyncio
|
|
47
|
+
async def test_get_context_collection_not_found_error(mock_vector_engine):
|
|
48
|
+
"""Test that CollectionNotFoundError is converted to NoDataError."""
|
|
49
|
+
mock_vector_engine.search.side_effect = CollectionNotFoundError("Collection not found")
|
|
50
|
+
|
|
51
|
+
retriever = SummariesRetriever()
|
|
52
|
+
|
|
53
|
+
with patch(
|
|
54
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
55
|
+
return_value=mock_vector_engine,
|
|
56
|
+
):
|
|
57
|
+
with pytest.raises(NoDataError, match="No data found"):
|
|
58
|
+
await retriever.get_retrieved_objects("test query")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.mark.asyncio
|
|
62
|
+
async def test_get_objects_empty_results(mock_vector_engine):
|
|
63
|
+
"""Test that empty list is returned when no summaries are found."""
|
|
64
|
+
mock_vector_engine.search.return_value = []
|
|
65
|
+
|
|
66
|
+
retriever = SummariesRetriever()
|
|
67
|
+
|
|
68
|
+
with patch(
|
|
69
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
70
|
+
return_value=mock_vector_engine,
|
|
71
|
+
):
|
|
72
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
73
|
+
|
|
74
|
+
assert objects == []
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.asyncio
|
|
78
|
+
async def test_get_objects_top_k_limit(mock_vector_engine):
|
|
79
|
+
"""Test that top_k parameter limits the number of results."""
|
|
80
|
+
mock_results = [MagicMock() for _ in range(3)]
|
|
81
|
+
for i, result in enumerate(mock_results):
|
|
82
|
+
result.payload = {"text": f"Summary {i}"}
|
|
83
|
+
|
|
84
|
+
mock_vector_engine.search.return_value = mock_results
|
|
85
|
+
|
|
86
|
+
retriever = SummariesRetriever(top_k=3)
|
|
87
|
+
|
|
88
|
+
with patch(
|
|
89
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
90
|
+
return_value=mock_vector_engine,
|
|
91
|
+
):
|
|
92
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
93
|
+
|
|
94
|
+
assert len(objects) == 3
|
|
95
|
+
mock_vector_engine.search.assert_awaited_once_with(
|
|
96
|
+
"TextSummary_text", "test query", limit=3, include_payload=True
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@pytest.mark.asyncio
|
|
101
|
+
async def test_get_context_with_objects(mock_vector_engine):
|
|
102
|
+
"""Test get_completion returns provided context."""
|
|
103
|
+
retriever = SummariesRetriever()
|
|
104
|
+
|
|
105
|
+
provided_context = {"text": "S.R."}
|
|
106
|
+
sn = SimpleNamespace()
|
|
107
|
+
sn.payload = provided_context
|
|
108
|
+
completion = await retriever.get_context_from_objects("test query", retrieved_objects=[sn])
|
|
109
|
+
|
|
110
|
+
assert completion == provided_context["text"]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@pytest.mark.asyncio
|
|
114
|
+
async def test_get_completion_without_context(mock_vector_engine):
|
|
115
|
+
"""Test get_completion retrieves context when not provided."""
|
|
116
|
+
mock_result = MagicMock()
|
|
117
|
+
mock_result.payload = {"text": "S.R."}
|
|
118
|
+
mock_vector_engine.search.return_value = [mock_result]
|
|
119
|
+
|
|
120
|
+
retriever = SummariesRetriever()
|
|
121
|
+
|
|
122
|
+
with patch(
|
|
123
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
124
|
+
return_value=mock_vector_engine,
|
|
125
|
+
):
|
|
126
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
127
|
+
context = await retriever.get_context_from_objects("test query", objects)
|
|
128
|
+
completion = await retriever.get_completion_from_context("test query", objects, context)
|
|
129
|
+
|
|
130
|
+
assert len(completion) == 1
|
|
131
|
+
assert completion[0]["text"] == "S.R."
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@pytest.mark.asyncio
|
|
135
|
+
async def test_init_defaults():
|
|
136
|
+
"""Test SummariesRetriever initialization with defaults."""
|
|
137
|
+
retriever = SummariesRetriever()
|
|
138
|
+
|
|
139
|
+
assert retriever.top_k == 5
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@pytest.mark.asyncio
|
|
143
|
+
async def test_init_custom_top_k():
|
|
144
|
+
"""Test SummariesRetriever initialization with custom top_k."""
|
|
145
|
+
retriever = SummariesRetriever(top_k=10)
|
|
146
|
+
|
|
147
|
+
assert retriever.top_k == 10
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@pytest.mark.asyncio
|
|
151
|
+
async def test_get_objects_empty_payload(mock_vector_engine):
|
|
152
|
+
"""Test get_context handles empty payload."""
|
|
153
|
+
mock_result = MagicMock()
|
|
154
|
+
mock_result.payload = {}
|
|
155
|
+
|
|
156
|
+
mock_vector_engine.search.return_value = [mock_result]
|
|
157
|
+
|
|
158
|
+
retriever = SummariesRetriever()
|
|
159
|
+
|
|
160
|
+
with patch(
|
|
161
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
162
|
+
return_value=mock_vector_engine,
|
|
163
|
+
):
|
|
164
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
165
|
+
|
|
166
|
+
assert len(objects) == 1
|
|
167
|
+
assert objects[0].payload == {}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@pytest.mark.asyncio
|
|
171
|
+
async def test_get_completion_with_session_id(mock_vector_engine):
|
|
172
|
+
"""Test get_completion with session_id parameter."""
|
|
173
|
+
mock_result = MagicMock()
|
|
174
|
+
mock_result.payload = {"text": "S.R."}
|
|
175
|
+
mock_vector_engine.search.return_value = [mock_result]
|
|
176
|
+
|
|
177
|
+
retriever = SummariesRetriever(session_id="test_session")
|
|
14
178
|
|
|
179
|
+
with patch(
|
|
180
|
+
"cognee.modules.retrieval.summaries_retriever.get_vector_engine",
|
|
181
|
+
return_value=mock_vector_engine,
|
|
182
|
+
):
|
|
183
|
+
objects = await retriever.get_retrieved_objects("test query")
|
|
184
|
+
context = await retriever.get_context_from_objects("test query", objects)
|
|
185
|
+
completion = await retriever.get_completion_from_context("test query", objects, context)
|
|
15
186
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async def test_chunk_context(self):
|
|
19
|
-
system_directory_path = os.path.join(
|
|
20
|
-
pathlib.Path(__file__).parent, ".cognee_system/test_chunk_context"
|
|
21
|
-
)
|
|
22
|
-
cognee.config.system_root_directory(system_directory_path)
|
|
23
|
-
data_directory_path = os.path.join(
|
|
24
|
-
pathlib.Path(__file__).parent, ".data_storage/test_chunk_context"
|
|
25
|
-
)
|
|
26
|
-
cognee.config.data_root_directory(data_directory_path)
|
|
27
|
-
|
|
28
|
-
await cognee.prune.prune_data()
|
|
29
|
-
await cognee.prune.prune_system(metadata=True)
|
|
30
|
-
await setup()
|
|
31
|
-
|
|
32
|
-
document1 = TextDocument(
|
|
33
|
-
name="Employee List",
|
|
34
|
-
raw_data_location="somewhere",
|
|
35
|
-
external_metadata="",
|
|
36
|
-
mime_type="text/plain",
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
document2 = TextDocument(
|
|
40
|
-
name="Car List",
|
|
41
|
-
raw_data_location="somewhere",
|
|
42
|
-
external_metadata="",
|
|
43
|
-
mime_type="text/plain",
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
chunk1 = DocumentChunk(
|
|
47
|
-
text="Steve Rodger",
|
|
48
|
-
chunk_size=2,
|
|
49
|
-
chunk_index=0,
|
|
50
|
-
cut_type="sentence_end",
|
|
51
|
-
is_part_of=document1,
|
|
52
|
-
contains=[],
|
|
53
|
-
)
|
|
54
|
-
chunk1_summary = TextSummary(
|
|
55
|
-
text="S.R.",
|
|
56
|
-
made_from=chunk1,
|
|
57
|
-
)
|
|
58
|
-
chunk2 = DocumentChunk(
|
|
59
|
-
text="Mike Broski",
|
|
60
|
-
chunk_size=2,
|
|
61
|
-
chunk_index=1,
|
|
62
|
-
cut_type="sentence_end",
|
|
63
|
-
is_part_of=document1,
|
|
64
|
-
contains=[],
|
|
65
|
-
)
|
|
66
|
-
chunk2_summary = TextSummary(
|
|
67
|
-
text="M.B.",
|
|
68
|
-
made_from=chunk2,
|
|
69
|
-
)
|
|
70
|
-
chunk3 = DocumentChunk(
|
|
71
|
-
text="Christina Mayer",
|
|
72
|
-
chunk_size=2,
|
|
73
|
-
chunk_index=2,
|
|
74
|
-
cut_type="sentence_end",
|
|
75
|
-
is_part_of=document1,
|
|
76
|
-
contains=[],
|
|
77
|
-
)
|
|
78
|
-
chunk3_summary = TextSummary(
|
|
79
|
-
text="C.M.",
|
|
80
|
-
made_from=chunk3,
|
|
81
|
-
)
|
|
82
|
-
chunk4 = DocumentChunk(
|
|
83
|
-
text="Range Rover",
|
|
84
|
-
chunk_size=2,
|
|
85
|
-
chunk_index=0,
|
|
86
|
-
cut_type="sentence_end",
|
|
87
|
-
is_part_of=document2,
|
|
88
|
-
contains=[],
|
|
89
|
-
)
|
|
90
|
-
chunk4_summary = TextSummary(
|
|
91
|
-
text="R.R.",
|
|
92
|
-
made_from=chunk4,
|
|
93
|
-
)
|
|
94
|
-
chunk5 = DocumentChunk(
|
|
95
|
-
text="Hyundai",
|
|
96
|
-
chunk_size=2,
|
|
97
|
-
chunk_index=1,
|
|
98
|
-
cut_type="sentence_end",
|
|
99
|
-
is_part_of=document2,
|
|
100
|
-
contains=[],
|
|
101
|
-
)
|
|
102
|
-
chunk5_summary = TextSummary(
|
|
103
|
-
text="H.Y.",
|
|
104
|
-
made_from=chunk5,
|
|
105
|
-
)
|
|
106
|
-
chunk6 = DocumentChunk(
|
|
107
|
-
text="Chrysler",
|
|
108
|
-
chunk_size=2,
|
|
109
|
-
chunk_index=2,
|
|
110
|
-
cut_type="sentence_end",
|
|
111
|
-
is_part_of=document2,
|
|
112
|
-
contains=[],
|
|
113
|
-
)
|
|
114
|
-
chunk6_summary = TextSummary(
|
|
115
|
-
text="C.H.",
|
|
116
|
-
made_from=chunk6,
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
entities = [
|
|
120
|
-
chunk1_summary,
|
|
121
|
-
chunk2_summary,
|
|
122
|
-
chunk3_summary,
|
|
123
|
-
chunk4_summary,
|
|
124
|
-
chunk5_summary,
|
|
125
|
-
chunk6_summary,
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
await add_data_points(entities)
|
|
129
|
-
|
|
130
|
-
retriever = SummariesRetriever(top_k=20)
|
|
131
|
-
|
|
132
|
-
context = await retriever.get_context("Christina")
|
|
133
|
-
|
|
134
|
-
assert context[0]["text"] == "C.M.", "Failed to get Christina Mayer"
|
|
135
|
-
|
|
136
|
-
@pytest.mark.asyncio
|
|
137
|
-
async def test_chunk_context_on_empty_graph(self):
|
|
138
|
-
system_directory_path = os.path.join(
|
|
139
|
-
pathlib.Path(__file__).parent, ".cognee_system/test_chunk_context_on_empty_graph"
|
|
140
|
-
)
|
|
141
|
-
cognee.config.system_root_directory(system_directory_path)
|
|
142
|
-
data_directory_path = os.path.join(
|
|
143
|
-
pathlib.Path(__file__).parent, ".data_storage/test_chunk_context_on_empty_graph"
|
|
144
|
-
)
|
|
145
|
-
cognee.config.data_root_directory(data_directory_path)
|
|
146
|
-
|
|
147
|
-
await cognee.prune.prune_data()
|
|
148
|
-
await cognee.prune.prune_system(metadata=True)
|
|
149
|
-
|
|
150
|
-
retriever = SummariesRetriever()
|
|
151
|
-
|
|
152
|
-
with pytest.raises(NoDataError):
|
|
153
|
-
await retriever.get_context("Christina Mayer")
|
|
154
|
-
|
|
155
|
-
vector_engine = get_vector_engine()
|
|
156
|
-
await vector_engine.create_collection("TextSummary_text", payload_schema=TextSummary)
|
|
157
|
-
|
|
158
|
-
context = await retriever.get_context("Christina Mayer")
|
|
159
|
-
assert context == [], "Returned context should be empty on an empty graph"
|
|
187
|
+
assert len(completion) == 1
|
|
188
|
+
assert completion[0]["text"] == "S.R."
|