cognee 0.5.1.dev0__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/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 +45 -3
- cognee/api/v1/memify/routers/get_memify_router.py +2 -0
- cognee/api/v1/search/routers/get_search_router.py +21 -6
- cognee/api/v1/search/search.py +25 -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/sqlalchemy/SqlAlchemyAdapter.py +2 -1
- 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 +69 -22
- 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/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/get_llm_client.py +24 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llama_cpp/adapter.py +191 -0
- cognee/modules/chunking/models/DocumentChunk.py +0 -1
- cognee/modules/cognify/config.py +2 -0
- cognee/modules/data/models/Data.py +1 -0
- 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 +31 -32
- cognee/modules/retrieval/utils/access_tracking.py +88 -0
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +99 -85
- 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 -215
- 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/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 +115 -16
- cognee/tests/integration/retrieval/test_graph_completion_retriever.py +13 -5
- cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +22 -20
- cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +23 -24
- cognee/tests/integration/retrieval/test_rag_completion_retriever.py +70 -5
- cognee/tests/integration/retrieval/test_structured_output.py +62 -18
- cognee/tests/integration/retrieval/test_summaries_retriever.py +20 -9
- cognee/tests/integration/retrieval/test_temporal_retriever.py +38 -8
- cognee/tests/integration/retrieval/test_triplet_retriever.py +13 -4
- 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_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 +97 -110
- 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/infrastructure/databases/cache/test_cache_config.py +2 -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 +31 -59
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +70 -33
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +72 -52
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +27 -33
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +28 -15
- cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +37 -42
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +48 -64
- cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +263 -24
- cognee/tests/unit/modules/retrieval/test_node_edge_vector_search.py +273 -0
- cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +30 -16
- cognee/tests/unit/modules/search/test_get_search_type_retriever_instance.py +125 -0
- cognee/tests/unit/modules/search/test_search.py +176 -0
- 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.dev0.dist-info → cognee-0.5.2.dist-info}/METADATA +22 -17
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dist-info}/RECORD +235 -147
- 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-0.5.1.dev0.dist-info → cognee-0.5.2.dist-info}/WHEEL +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -164,13 +164,18 @@ async def setup_test_environment_empty():
|
|
|
164
164
|
async def test_graph_completion_extension_context_simple(setup_test_environment_simple):
|
|
165
165
|
"""Integration test: verify GraphCompletionContextExtensionRetriever can retrieve context (simple)."""
|
|
166
166
|
retriever = GraphCompletionContextExtensionRetriever()
|
|
167
|
+
query = "Who works at Canva?"
|
|
167
168
|
|
|
168
|
-
|
|
169
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
170
|
+
|
|
171
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
169
172
|
|
|
170
173
|
assert "Mike Broski --[works_for]--> Canva" in context, "Failed to get Mike Broski"
|
|
171
174
|
assert "Christina Mayer --[works_for]--> Canva" in context, "Failed to get Christina Mayer"
|
|
172
175
|
|
|
173
|
-
answer = await retriever.
|
|
176
|
+
answer = await retriever.get_completion_from_context(
|
|
177
|
+
query=query, retrieved_objects=triplets, context=context
|
|
178
|
+
)
|
|
174
179
|
|
|
175
180
|
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
176
181
|
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
@@ -182,16 +187,19 @@ async def test_graph_completion_extension_context_simple(setup_test_environment_
|
|
|
182
187
|
async def test_graph_completion_extension_context_complex(setup_test_environment_complex):
|
|
183
188
|
"""Integration test: verify GraphCompletionContextExtensionRetriever can retrieve context (complex)."""
|
|
184
189
|
retriever = GraphCompletionContextExtensionRetriever(top_k=20)
|
|
190
|
+
query = "Who works at Figma and drives Tesla?"
|
|
185
191
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
192
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
193
|
+
|
|
194
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
189
195
|
|
|
190
196
|
assert "Mike Rodger --[works_for]--> Figma" in context, "Failed to get Mike Rodger"
|
|
191
197
|
assert "Ike Loma --[works_for]--> Figma" in context, "Failed to get Ike Loma"
|
|
192
198
|
assert "Jason Statham --[works_for]--> Figma" in context, "Failed to get Jason Statham"
|
|
193
199
|
|
|
194
|
-
answer = await retriever.
|
|
200
|
+
answer = await retriever.get_completion_from_context(
|
|
201
|
+
query=query, retrieved_objects=triplets, context=context
|
|
202
|
+
)
|
|
195
203
|
|
|
196
204
|
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
197
205
|
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
@@ -203,24 +211,18 @@ async def test_graph_completion_extension_context_complex(setup_test_environment
|
|
|
203
211
|
async def test_get_graph_completion_extension_context_on_empty_graph(setup_test_environment_empty):
|
|
204
212
|
"""Integration test: verify GraphCompletionContextExtensionRetriever handles empty graph correctly."""
|
|
205
213
|
retriever = GraphCompletionContextExtensionRetriever()
|
|
214
|
+
query = "Who works at Figma?"
|
|
215
|
+
|
|
216
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
206
217
|
|
|
207
|
-
context = await retriever.
|
|
208
|
-
assert context ==
|
|
218
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
219
|
+
assert context == "", "Context should be empty on an empty graph"
|
|
209
220
|
|
|
210
|
-
answer = await retriever.
|
|
221
|
+
answer = await retriever.get_completion_from_context(
|
|
222
|
+
query=query, retrieved_objects=triplets, context=context
|
|
223
|
+
)
|
|
211
224
|
|
|
212
225
|
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
213
226
|
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
214
227
|
"Answer must contain only non-empty strings"
|
|
215
228
|
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
@pytest.mark.asyncio
|
|
219
|
-
async def test_graph_completion_extension_get_triplets_empty(setup_test_environment_empty):
|
|
220
|
-
"""Integration test: verify GraphCompletionContextExtensionRetriever get_triplets handles empty graph."""
|
|
221
|
-
retriever = GraphCompletionContextExtensionRetriever()
|
|
222
|
-
|
|
223
|
-
triplets = await retriever.get_triplets("Who works at Figma?")
|
|
224
|
-
|
|
225
|
-
assert isinstance(triplets, list), "Triplets should be a list"
|
|
226
|
-
assert len(triplets) == 0, "Should return empty list on empty graph"
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import pytest
|
|
3
2
|
import pathlib
|
|
4
3
|
import pytest_asyncio
|
|
5
4
|
from typing import Optional, Union
|
|
6
5
|
import cognee
|
|
6
|
+
from cognee.exceptions import CogneeValidationError
|
|
7
7
|
|
|
8
8
|
from cognee.low_level import setup, DataPoint
|
|
9
|
-
from cognee.modules.graph.utils import resolve_edges_to_text
|
|
10
9
|
from cognee.tasks.storage import add_data_points
|
|
11
10
|
from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever
|
|
12
11
|
|
|
@@ -158,13 +157,18 @@ async def setup_test_environment_empty():
|
|
|
158
157
|
async def test_graph_completion_cot_context_simple(setup_test_environment_simple):
|
|
159
158
|
"""Integration test: verify GraphCompletionCotRetriever can retrieve context (simple)."""
|
|
160
159
|
retriever = GraphCompletionCotRetriever()
|
|
160
|
+
query = "Who works at Canva?"
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
163
|
+
|
|
164
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
163
165
|
|
|
164
166
|
assert "Mike Broski --[works_for]--> Canva" in context, "Failed to get Mike Broski"
|
|
165
167
|
assert "Christina Mayer --[works_for]--> Canva" in context, "Failed to get Christina Mayer"
|
|
166
168
|
|
|
167
|
-
answer = await retriever.
|
|
169
|
+
answer = await retriever.get_completion_from_context(
|
|
170
|
+
query=query, retrieved_objects=triplets, context=context
|
|
171
|
+
)
|
|
168
172
|
|
|
169
173
|
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
170
174
|
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
@@ -176,14 +180,19 @@ async def test_graph_completion_cot_context_simple(setup_test_environment_simple
|
|
|
176
180
|
async def test_graph_completion_cot_context_complex(setup_test_environment_complex):
|
|
177
181
|
"""Integration test: verify GraphCompletionCotRetriever can retrieve context (complex)."""
|
|
178
182
|
retriever = GraphCompletionCotRetriever(top_k=20)
|
|
183
|
+
query = "Who works at Figma?"
|
|
179
184
|
|
|
180
|
-
|
|
185
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
186
|
+
|
|
187
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
181
188
|
|
|
182
189
|
assert "Mike Rodger --[works_for]--> Figma" in context, "Failed to get Mike Rodger"
|
|
183
190
|
assert "Ike Loma --[works_for]--> Figma" in context, "Failed to get Ike Loma"
|
|
184
191
|
assert "Jason Statham --[works_for]--> Figma" in context, "Failed to get Jason Statham"
|
|
185
192
|
|
|
186
|
-
answer = await retriever.
|
|
193
|
+
answer = await retriever.get_completion_from_context(
|
|
194
|
+
query=query, retrieved_objects=triplets, context=context
|
|
195
|
+
)
|
|
187
196
|
|
|
188
197
|
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
189
198
|
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
@@ -195,24 +204,14 @@ async def test_graph_completion_cot_context_complex(setup_test_environment_compl
|
|
|
195
204
|
async def test_get_graph_completion_cot_context_on_empty_graph(setup_test_environment_empty):
|
|
196
205
|
"""Integration test: verify GraphCompletionCotRetriever handles empty graph correctly."""
|
|
197
206
|
retriever = GraphCompletionCotRetriever()
|
|
207
|
+
query = "Who works at Figma?"
|
|
198
208
|
|
|
199
|
-
|
|
200
|
-
assert context == [], "Context should be empty on an empty graph"
|
|
201
|
-
|
|
202
|
-
answer = await retriever.get_completion("Who works at Figma?")
|
|
203
|
-
|
|
204
|
-
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
205
|
-
assert all(isinstance(item, str) and item.strip() for item in answer), (
|
|
206
|
-
"Answer must contain only non-empty strings"
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
@pytest.mark.asyncio
|
|
211
|
-
async def test_graph_completion_cot_get_triplets_empty(setup_test_environment_empty):
|
|
212
|
-
"""Integration test: verify GraphCompletionCotRetriever get_triplets handles empty graph."""
|
|
213
|
-
retriever = GraphCompletionCotRetriever()
|
|
209
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
214
210
|
|
|
215
|
-
|
|
211
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
212
|
+
assert context == "", "Context should be empty on an empty graph"
|
|
216
213
|
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
with pytest.raises(CogneeValidationError):
|
|
215
|
+
await retriever.get_completion_from_context(
|
|
216
|
+
query=query, retrieved_objects=triplets, context=context
|
|
217
|
+
)
|
|
@@ -83,6 +83,18 @@ async def setup_test_environment_with_chunks_simple():
|
|
|
83
83
|
try:
|
|
84
84
|
await cognee.prune.prune_data()
|
|
85
85
|
await cognee.prune.prune_system(metadata=True)
|
|
86
|
+
|
|
87
|
+
from cognee.infrastructure.databases.graph.get_graph_engine import _create_graph_engine
|
|
88
|
+
from cognee.infrastructure.databases.vector.create_vector_engine import (
|
|
89
|
+
_create_vector_engine,
|
|
90
|
+
)
|
|
91
|
+
from cognee.infrastructure.databases.relational.create_relational_engine import (
|
|
92
|
+
create_relational_engine,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
_create_graph_engine.cache_clear()
|
|
96
|
+
_create_vector_engine.cache_clear()
|
|
97
|
+
create_relational_engine.cache_clear()
|
|
86
98
|
except Exception:
|
|
87
99
|
pass
|
|
88
100
|
|
|
@@ -174,6 +186,18 @@ async def setup_test_environment_with_chunks_complex():
|
|
|
174
186
|
try:
|
|
175
187
|
await cognee.prune.prune_data()
|
|
176
188
|
await cognee.prune.prune_system(metadata=True)
|
|
189
|
+
|
|
190
|
+
from cognee.infrastructure.databases.graph.get_graph_engine import _create_graph_engine
|
|
191
|
+
from cognee.infrastructure.databases.vector.create_vector_engine import (
|
|
192
|
+
_create_vector_engine,
|
|
193
|
+
)
|
|
194
|
+
from cognee.infrastructure.databases.relational.create_relational_engine import (
|
|
195
|
+
create_relational_engine,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
_create_graph_engine.cache_clear()
|
|
199
|
+
_create_vector_engine.cache_clear()
|
|
200
|
+
create_relational_engine.cache_clear()
|
|
177
201
|
except Exception:
|
|
178
202
|
pass
|
|
179
203
|
|
|
@@ -195,11 +219,33 @@ async def setup_test_environment_empty():
|
|
|
195
219
|
await cognee.prune.prune_data()
|
|
196
220
|
await cognee.prune.prune_system(metadata=True)
|
|
197
221
|
|
|
222
|
+
from cognee.infrastructure.databases.graph.get_graph_engine import _create_graph_engine
|
|
223
|
+
from cognee.infrastructure.databases.vector.create_vector_engine import _create_vector_engine
|
|
224
|
+
from cognee.infrastructure.databases.relational.create_relational_engine import (
|
|
225
|
+
create_relational_engine,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
_create_graph_engine.cache_clear()
|
|
229
|
+
_create_vector_engine.cache_clear()
|
|
230
|
+
create_relational_engine.cache_clear()
|
|
231
|
+
|
|
198
232
|
yield
|
|
199
233
|
|
|
200
234
|
try:
|
|
201
235
|
await cognee.prune.prune_data()
|
|
202
236
|
await cognee.prune.prune_system(metadata=True)
|
|
237
|
+
|
|
238
|
+
from cognee.infrastructure.databases.graph.get_graph_engine import _create_graph_engine
|
|
239
|
+
from cognee.infrastructure.databases.vector.create_vector_engine import (
|
|
240
|
+
_create_vector_engine,
|
|
241
|
+
)
|
|
242
|
+
from cognee.infrastructure.databases.relational.create_relational_engine import (
|
|
243
|
+
create_relational_engine,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
_create_graph_engine.cache_clear()
|
|
247
|
+
_create_vector_engine.cache_clear()
|
|
248
|
+
create_relational_engine.cache_clear()
|
|
203
249
|
except Exception:
|
|
204
250
|
pass
|
|
205
251
|
|
|
@@ -208,8 +254,13 @@ async def setup_test_environment_empty():
|
|
|
208
254
|
async def test_rag_completion_context_simple(setup_test_environment_with_chunks_simple):
|
|
209
255
|
"""Integration test: verify CompletionRetriever can retrieve context (simple)."""
|
|
210
256
|
retriever = CompletionRetriever()
|
|
257
|
+
query = "Mike"
|
|
211
258
|
|
|
212
|
-
|
|
259
|
+
retrieved_objects = await retriever.get_retrieved_objects(query)
|
|
260
|
+
|
|
261
|
+
context = await retriever.get_context_from_objects(
|
|
262
|
+
query=query, retrieved_objects=retrieved_objects
|
|
263
|
+
)
|
|
213
264
|
|
|
214
265
|
assert isinstance(context, str), "Context should be a string"
|
|
215
266
|
assert "Mike Broski" in context, "Failed to get Mike Broski"
|
|
@@ -219,8 +270,13 @@ async def test_rag_completion_context_simple(setup_test_environment_with_chunks_
|
|
|
219
270
|
async def test_rag_completion_context_multiple_chunks(setup_test_environment_with_chunks_simple):
|
|
220
271
|
"""Integration test: verify CompletionRetriever can retrieve context from multiple chunks."""
|
|
221
272
|
retriever = CompletionRetriever()
|
|
273
|
+
query = "Steve"
|
|
274
|
+
|
|
275
|
+
retrieved_objects = await retriever.get_retrieved_objects(query)
|
|
222
276
|
|
|
223
|
-
context = await retriever.
|
|
277
|
+
context = await retriever.get_context_from_objects(
|
|
278
|
+
query=query, retrieved_objects=retrieved_objects
|
|
279
|
+
)
|
|
224
280
|
|
|
225
281
|
assert isinstance(context, str), "Context should be a string"
|
|
226
282
|
assert "Steve Rodger" in context, "Failed to get Steve Rodger"
|
|
@@ -231,8 +287,13 @@ async def test_rag_completion_context_complex(setup_test_environment_with_chunks
|
|
|
231
287
|
"""Integration test: verify CompletionRetriever can retrieve context (complex)."""
|
|
232
288
|
# TODO: top_k doesn't affect the output, it should be fixed.
|
|
233
289
|
retriever = CompletionRetriever(top_k=20)
|
|
290
|
+
query = "Christina"
|
|
234
291
|
|
|
235
|
-
|
|
292
|
+
retrieved_objects = await retriever.get_retrieved_objects(query)
|
|
293
|
+
|
|
294
|
+
context = await retriever.get_context_from_objects(
|
|
295
|
+
query=query, retrieved_objects=retrieved_objects
|
|
296
|
+
)
|
|
236
297
|
|
|
237
298
|
assert context[0:15] == "Christina Mayer", "Failed to get Christina Mayer"
|
|
238
299
|
|
|
@@ -241,14 +302,18 @@ async def test_rag_completion_context_complex(setup_test_environment_with_chunks
|
|
|
241
302
|
async def test_get_rag_completion_context_on_empty_graph(setup_test_environment_empty):
|
|
242
303
|
"""Integration test: verify CompletionRetriever handles empty graph correctly."""
|
|
243
304
|
retriever = CompletionRetriever()
|
|
305
|
+
query = "Christina Mayer"
|
|
244
306
|
|
|
245
307
|
with pytest.raises(NoDataError):
|
|
246
|
-
await retriever.
|
|
308
|
+
await retriever.get_retrieved_objects(query)
|
|
247
309
|
|
|
248
310
|
vector_engine = get_vector_engine()
|
|
249
311
|
await vector_engine.create_collection(
|
|
250
312
|
"DocumentChunk_text", payload_schema=DocumentChunkWithEntities
|
|
251
313
|
)
|
|
252
314
|
|
|
253
|
-
|
|
315
|
+
retrieved_objects = await retriever.get_retrieved_objects(query)
|
|
316
|
+
context = await retriever.get_context_from_objects(
|
|
317
|
+
query=query, retrieved_objects=retrieved_objects
|
|
318
|
+
)
|
|
254
319
|
assert context == "", "Returned context should be empty on an empty graph"
|
|
@@ -43,84 +43,128 @@ def _assert_structured_answer(answer: list[TestAnswer]):
|
|
|
43
43
|
|
|
44
44
|
async def _test_get_structured_graph_completion_cot():
|
|
45
45
|
retriever = GraphCompletionCotRetriever()
|
|
46
|
+
query = "Who works at Figma?"
|
|
47
|
+
|
|
48
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
49
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
46
50
|
|
|
47
51
|
# Test with string response model (default)
|
|
48
|
-
string_answer = await retriever.
|
|
52
|
+
string_answer = await retriever.get_completion_from_context(
|
|
53
|
+
query=query, retrieved_objects=triplets, context=context
|
|
54
|
+
)
|
|
49
55
|
_assert_string_answer(string_answer)
|
|
50
56
|
|
|
57
|
+
retriever.response_model = TestAnswer
|
|
51
58
|
# Test with structured response model
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
60
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
61
|
+
query=query, retrieved_objects=triplets, context=context
|
|
54
62
|
)
|
|
55
63
|
_assert_structured_answer(structured_answer)
|
|
56
64
|
|
|
57
65
|
|
|
58
66
|
async def _test_get_structured_graph_completion():
|
|
59
67
|
retriever = GraphCompletionRetriever()
|
|
68
|
+
query = "Who works at Figma?"
|
|
69
|
+
|
|
70
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
71
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
60
72
|
|
|
61
73
|
# Test with string response model (default)
|
|
62
|
-
string_answer = await retriever.
|
|
74
|
+
string_answer = await retriever.get_completion_from_context(
|
|
75
|
+
query=query, retrieved_objects=triplets, context=context
|
|
76
|
+
)
|
|
63
77
|
_assert_string_answer(string_answer)
|
|
64
78
|
|
|
79
|
+
retriever.response_model = TestAnswer
|
|
65
80
|
# Test with structured response model
|
|
66
|
-
structured_answer = await retriever.
|
|
67
|
-
|
|
81
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
82
|
+
query=query, retrieved_objects=triplets, context=context
|
|
68
83
|
)
|
|
69
84
|
_assert_structured_answer(structured_answer)
|
|
70
85
|
|
|
71
86
|
|
|
72
87
|
async def _test_get_structured_graph_completion_temporal():
|
|
73
88
|
retriever = TemporalRetriever()
|
|
89
|
+
query = "When did Steve start working at Figma?"
|
|
74
90
|
|
|
75
91
|
# Test with string response model (default)
|
|
76
|
-
|
|
92
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
93
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
94
|
+
|
|
95
|
+
# Test with string response model (default)
|
|
96
|
+
string_answer = await retriever.get_completion_from_context(
|
|
97
|
+
query=query, retrieved_objects=triplets, context=context
|
|
98
|
+
)
|
|
77
99
|
_assert_string_answer(string_answer)
|
|
78
100
|
|
|
101
|
+
retriever.response_model = TestAnswer
|
|
79
102
|
# Test with structured response model
|
|
80
|
-
structured_answer = await retriever.
|
|
81
|
-
|
|
103
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
104
|
+
query=query, retrieved_objects=triplets, context=context
|
|
82
105
|
)
|
|
83
106
|
_assert_structured_answer(structured_answer)
|
|
84
107
|
|
|
85
108
|
|
|
86
109
|
async def _test_get_structured_graph_completion_rag():
|
|
87
110
|
retriever = CompletionRetriever()
|
|
111
|
+
query = "Where does Steve work?"
|
|
112
|
+
|
|
113
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
114
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
88
115
|
|
|
89
116
|
# Test with string response model (default)
|
|
90
|
-
string_answer = await retriever.
|
|
117
|
+
string_answer = await retriever.get_completion_from_context(
|
|
118
|
+
query=query, retrieved_objects=triplets, context=context
|
|
119
|
+
)
|
|
91
120
|
_assert_string_answer(string_answer)
|
|
92
121
|
|
|
122
|
+
retriever.response_model = TestAnswer
|
|
93
123
|
# Test with structured response model
|
|
94
|
-
structured_answer = await retriever.
|
|
95
|
-
|
|
124
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
125
|
+
query=query, retrieved_objects=triplets, context=context
|
|
96
126
|
)
|
|
97
127
|
_assert_structured_answer(structured_answer)
|
|
98
128
|
|
|
99
129
|
|
|
100
130
|
async def _test_get_structured_graph_completion_context_extension():
|
|
101
131
|
retriever = GraphCompletionContextExtensionRetriever()
|
|
132
|
+
query = "Who works at Figma?"
|
|
133
|
+
|
|
134
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
135
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
102
136
|
|
|
103
137
|
# Test with string response model (default)
|
|
104
|
-
string_answer = await retriever.
|
|
138
|
+
string_answer = await retriever.get_completion_from_context(
|
|
139
|
+
query=query, retrieved_objects=triplets, context=context
|
|
140
|
+
)
|
|
105
141
|
_assert_string_answer(string_answer)
|
|
106
142
|
|
|
143
|
+
retriever.response_model = TestAnswer
|
|
107
144
|
# Test with structured response model
|
|
108
|
-
structured_answer = await retriever.
|
|
109
|
-
|
|
145
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
146
|
+
query=query, retrieved_objects=triplets, context=context
|
|
110
147
|
)
|
|
111
148
|
_assert_structured_answer(structured_answer)
|
|
112
149
|
|
|
113
150
|
|
|
114
151
|
async def _test_get_structured_entity_completion():
|
|
115
152
|
retriever = EntityCompletionRetriever(DummyEntityExtractor(), DummyContextProvider())
|
|
153
|
+
query = "Who is Albert Einstein?"
|
|
154
|
+
|
|
155
|
+
entities = await retriever.get_retrieved_objects(query)
|
|
156
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=entities)
|
|
116
157
|
|
|
117
158
|
# Test with string response model (default)
|
|
118
|
-
string_answer = await retriever.
|
|
159
|
+
string_answer = await retriever.get_completion_from_context(
|
|
160
|
+
query=query, retrieved_objects=entities, context=context
|
|
161
|
+
)
|
|
119
162
|
_assert_string_answer(string_answer)
|
|
120
163
|
|
|
164
|
+
retriever.response_model = TestAnswer
|
|
121
165
|
# Test with structured response model
|
|
122
|
-
structured_answer = await retriever.
|
|
123
|
-
|
|
166
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
167
|
+
query=query, retrieved_objects=entities, context=context
|
|
124
168
|
)
|
|
125
169
|
_assert_structured_answer(structured_answer)
|
|
126
170
|
|
|
@@ -158,27 +158,38 @@ async def setup_test_environment_empty():
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
@pytest.mark.asyncio
|
|
161
|
-
async def
|
|
161
|
+
async def test_summaries_retriever(setup_test_environment_with_summaries):
|
|
162
162
|
"""Integration test: verify SummariesRetriever can retrieve summary context."""
|
|
163
163
|
retriever = SummariesRetriever(top_k=20)
|
|
164
|
+
query = "Christina"
|
|
165
|
+
summaries = await retriever.get_retrieved_objects(query)
|
|
166
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=summaries)
|
|
164
167
|
|
|
165
|
-
|
|
168
|
+
completion = await retriever.get_completion_from_context(
|
|
169
|
+
query=query, retrieved_objects=summaries, context=context
|
|
170
|
+
)
|
|
166
171
|
|
|
167
|
-
assert isinstance(
|
|
168
|
-
assert len(
|
|
169
|
-
assert
|
|
172
|
+
assert isinstance(completion, list), "Context should be a list"
|
|
173
|
+
assert len(completion) > 0, "Context should not be empty"
|
|
174
|
+
assert completion[0]["text"] == "C.M.", "Failed to get Christina Mayer"
|
|
170
175
|
|
|
171
176
|
|
|
172
177
|
@pytest.mark.asyncio
|
|
173
|
-
async def
|
|
178
|
+
async def test_summaries_retriever_on_empty_graph(setup_test_environment_empty):
|
|
174
179
|
"""Integration test: verify SummariesRetriever handles empty graph correctly."""
|
|
175
180
|
retriever = SummariesRetriever()
|
|
181
|
+
query = "Christina Mayer"
|
|
176
182
|
|
|
177
183
|
with pytest.raises(NoDataError):
|
|
178
|
-
await retriever.
|
|
184
|
+
await retriever.get_retrieved_objects(query)
|
|
179
185
|
|
|
180
186
|
vector_engine = get_vector_engine()
|
|
181
187
|
await vector_engine.create_collection("TextSummary_text", payload_schema=TextSummary)
|
|
182
188
|
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
summaries = await retriever.get_retrieved_objects(query)
|
|
190
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=summaries)
|
|
191
|
+
completion = await retriever.get_completion_from_context(
|
|
192
|
+
query=query, retrieved_objects=summaries, context=context
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
assert completion == [], "Returned context should be empty on an empty graph"
|
|
@@ -197,8 +197,11 @@ async def setup_test_environment_empty():
|
|
|
197
197
|
async def test_temporal_retriever_context_with_time_range(setup_test_environment_with_events):
|
|
198
198
|
"""Integration test: verify TemporalRetriever can retrieve events within time range."""
|
|
199
199
|
retriever = TemporalRetriever(top_k=5)
|
|
200
|
+
query = "What happened in January 2021?"
|
|
200
201
|
|
|
201
|
-
|
|
202
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
203
|
+
|
|
204
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
202
205
|
|
|
203
206
|
assert isinstance(context, str), "Context should be a string"
|
|
204
207
|
assert len(context) > 0, "Context should not be empty"
|
|
@@ -211,8 +214,11 @@ async def test_temporal_retriever_context_with_time_range(setup_test_environment
|
|
|
211
214
|
async def test_temporal_retriever_context_with_single_time(setup_test_environment_with_events):
|
|
212
215
|
"""Integration test: verify TemporalRetriever can retrieve events at specific time."""
|
|
213
216
|
retriever = TemporalRetriever(top_k=5)
|
|
217
|
+
query = "What happened in July 2021?"
|
|
218
|
+
|
|
219
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
214
220
|
|
|
215
|
-
context = await retriever.
|
|
221
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
216
222
|
|
|
217
223
|
assert isinstance(context, str), "Context should be a string"
|
|
218
224
|
assert len(context) > 0, "Context should not be empty"
|
|
@@ -227,8 +233,11 @@ async def test_temporal_retriever_context_fallback_to_triplets(
|
|
|
227
233
|
):
|
|
228
234
|
"""Integration test: verify TemporalRetriever falls back to triplets when no time extracted."""
|
|
229
235
|
retriever = TemporalRetriever(top_k=5)
|
|
236
|
+
query = "Who works at Figma?"
|
|
237
|
+
|
|
238
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
230
239
|
|
|
231
|
-
context = await retriever.
|
|
240
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
232
241
|
|
|
233
242
|
assert isinstance(context, str), "Context should be a string"
|
|
234
243
|
assert len(context) > 0, "Context should not be empty"
|
|
@@ -241,8 +250,11 @@ async def test_temporal_retriever_context_fallback_to_triplets(
|
|
|
241
250
|
async def test_temporal_retriever_context_empty_graph(setup_test_environment_empty):
|
|
242
251
|
"""Integration test: verify TemporalRetriever handles empty graph correctly."""
|
|
243
252
|
retriever = TemporalRetriever()
|
|
253
|
+
query = "What happened?"
|
|
244
254
|
|
|
245
|
-
|
|
255
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
256
|
+
|
|
257
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
246
258
|
|
|
247
259
|
assert isinstance(context, str), "Context should be a string"
|
|
248
260
|
assert len(context) >= 0, "Context should be a string (possibly empty)"
|
|
@@ -252,8 +264,14 @@ async def test_temporal_retriever_context_empty_graph(setup_test_environment_emp
|
|
|
252
264
|
async def test_temporal_retriever_get_completion(setup_test_environment_with_events):
|
|
253
265
|
"""Integration test: verify TemporalRetriever can generate completions."""
|
|
254
266
|
retriever = TemporalRetriever()
|
|
267
|
+
query = "What happened in January 2021?"
|
|
268
|
+
|
|
269
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
270
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
255
271
|
|
|
256
|
-
completion = await retriever.
|
|
272
|
+
completion = await retriever.get_completion_from_context(
|
|
273
|
+
query=query, retrieved_objects=triplets, context=context
|
|
274
|
+
)
|
|
257
275
|
|
|
258
276
|
assert isinstance(completion, list), "Completion should be a list"
|
|
259
277
|
assert len(completion) > 0, "Completion should not be empty"
|
|
@@ -266,8 +284,14 @@ async def test_temporal_retriever_get_completion(setup_test_environment_with_eve
|
|
|
266
284
|
async def test_temporal_retriever_get_completion_fallback(setup_test_environment_with_graph_data):
|
|
267
285
|
"""Integration test: verify TemporalRetriever get_completion works with triplet fallback."""
|
|
268
286
|
retriever = TemporalRetriever()
|
|
287
|
+
query = "Who works at Figma?"
|
|
288
|
+
|
|
289
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
290
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
269
291
|
|
|
270
|
-
completion = await retriever.
|
|
292
|
+
completion = await retriever.get_completion_from_context(
|
|
293
|
+
query=query, retrieved_objects=triplets, context=context
|
|
294
|
+
)
|
|
271
295
|
|
|
272
296
|
assert isinstance(completion, list), "Completion should be a list"
|
|
273
297
|
assert len(completion) > 0, "Completion should not be empty"
|
|
@@ -280,8 +304,11 @@ async def test_temporal_retriever_get_completion_fallback(setup_test_environment
|
|
|
280
304
|
async def test_temporal_retriever_top_k_limit(setup_test_environment_with_events):
|
|
281
305
|
"""Integration test: verify TemporalRetriever respects top_k parameter."""
|
|
282
306
|
retriever = TemporalRetriever(top_k=2)
|
|
307
|
+
query = "What happened in 2021?"
|
|
283
308
|
|
|
284
|
-
|
|
309
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
310
|
+
|
|
311
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
285
312
|
|
|
286
313
|
assert isinstance(context, str), "Context should be a string"
|
|
287
314
|
separator_count = context.count("#####################")
|
|
@@ -292,8 +319,11 @@ async def test_temporal_retriever_top_k_limit(setup_test_environment_with_events
|
|
|
292
319
|
async def test_temporal_retriever_multiple_events(setup_test_environment_with_events):
|
|
293
320
|
"""Integration test: verify TemporalRetriever can retrieve multiple events."""
|
|
294
321
|
retriever = TemporalRetriever(top_k=10)
|
|
322
|
+
query = "What events occurred in 2021?"
|
|
323
|
+
|
|
324
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
295
325
|
|
|
296
|
-
context = await retriever.
|
|
326
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
297
327
|
|
|
298
328
|
assert isinstance(context, str), "Context should be a string"
|
|
299
329
|
assert len(context) > 0, "Context should not be empty"
|
|
@@ -78,8 +78,11 @@ async def setup_test_environment_empty():
|
|
|
78
78
|
async def test_triplet_retriever_context_simple(setup_test_environment_with_triplets):
|
|
79
79
|
"""Integration test: verify TripletRetriever can retrieve triplet context."""
|
|
80
80
|
retriever = TripletRetriever(top_k=5)
|
|
81
|
+
query = "Alice"
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
84
|
+
|
|
85
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
83
86
|
|
|
84
87
|
assert "Alice knows Bob" in context, "Failed to get Alice triplet"
|
|
85
88
|
assert isinstance(context, str), "Context should be a string"
|
|
@@ -90,8 +93,11 @@ async def test_triplet_retriever_context_simple(setup_test_environment_with_trip
|
|
|
90
93
|
async def test_triplet_retriever_context_multiple_triplets(setup_test_environment_with_triplets):
|
|
91
94
|
"""Integration test: verify TripletRetriever can retrieve multiple triplets."""
|
|
92
95
|
retriever = TripletRetriever(top_k=5)
|
|
96
|
+
query = "Bob"
|
|
97
|
+
|
|
98
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
93
99
|
|
|
94
|
-
context = await retriever.
|
|
100
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
95
101
|
|
|
96
102
|
assert "Alice knows Bob" in context or "Bob works at Tech Corp" in context, (
|
|
97
103
|
"Failed to get Bob-related triplets"
|
|
@@ -102,8 +108,11 @@ async def test_triplet_retriever_context_multiple_triplets(setup_test_environmen
|
|
|
102
108
|
async def test_triplet_retriever_top_k_limit(setup_test_environment_with_triplets):
|
|
103
109
|
"""Integration test: verify TripletRetriever respects top_k parameter."""
|
|
104
110
|
retriever = TripletRetriever(top_k=1)
|
|
111
|
+
query = "Alice"
|
|
112
|
+
|
|
113
|
+
triplets = await retriever.get_retrieved_objects(query)
|
|
105
114
|
|
|
106
|
-
context = await retriever.
|
|
115
|
+
context = await retriever.get_context_from_objects(query=query, retrieved_objects=triplets)
|
|
107
116
|
|
|
108
117
|
assert isinstance(context, str), "Context should be a string"
|
|
109
118
|
|
|
@@ -116,4 +125,4 @@ async def test_triplet_retriever_context_empty(setup_test_environment_empty):
|
|
|
116
125
|
retriever = TripletRetriever()
|
|
117
126
|
|
|
118
127
|
with pytest.raises(NoDataError):
|
|
119
|
-
await retriever.
|
|
128
|
+
await retriever.get_retrieved_objects("Alice")
|