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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import List
|
|
3
|
+
import pytest
|
|
4
|
+
import pathlib
|
|
5
|
+
import pytest_asyncio
|
|
6
|
+
import cognee
|
|
7
|
+
|
|
8
|
+
from cognee.low_level import setup
|
|
9
|
+
from cognee.tasks.storage import add_data_points
|
|
10
|
+
from cognee.infrastructure.databases.vector import get_vector_engine
|
|
11
|
+
from cognee.modules.chunking.models import DocumentChunk
|
|
12
|
+
from cognee.modules.data.processing.document_types import TextDocument
|
|
13
|
+
from cognee.modules.retrieval.exceptions.exceptions import NoDataError
|
|
14
|
+
from cognee.modules.retrieval.completion_retriever import CompletionRetriever
|
|
15
|
+
from cognee.infrastructure.engine import DataPoint
|
|
16
|
+
from cognee.modules.data.processing.document_types import Document
|
|
17
|
+
from cognee.modules.engine.models import Entity
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DocumentChunkWithEntities(DataPoint):
|
|
21
|
+
text: str
|
|
22
|
+
chunk_size: int
|
|
23
|
+
chunk_index: int
|
|
24
|
+
cut_type: str
|
|
25
|
+
is_part_of: Document
|
|
26
|
+
contains: List[Entity] = None
|
|
27
|
+
|
|
28
|
+
metadata: dict = {"index_fields": ["text"]}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest_asyncio.fixture
|
|
32
|
+
async def setup_test_environment_with_chunks_simple():
|
|
33
|
+
"""Set up a clean test environment with simple chunks."""
|
|
34
|
+
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
|
|
35
|
+
system_directory_path = str(base_dir / ".cognee_system/test_rag_completion_context_simple")
|
|
36
|
+
data_directory_path = str(base_dir / ".data_storage/test_rag_completion_context_simple")
|
|
37
|
+
|
|
38
|
+
cognee.config.system_root_directory(system_directory_path)
|
|
39
|
+
cognee.config.data_root_directory(data_directory_path)
|
|
40
|
+
|
|
41
|
+
await cognee.prune.prune_data()
|
|
42
|
+
await cognee.prune.prune_system(metadata=True)
|
|
43
|
+
await setup()
|
|
44
|
+
|
|
45
|
+
document = TextDocument(
|
|
46
|
+
name="Steve Rodger's career",
|
|
47
|
+
raw_data_location="somewhere",
|
|
48
|
+
external_metadata="",
|
|
49
|
+
mime_type="text/plain",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
chunk1 = DocumentChunk(
|
|
53
|
+
text="Steve Rodger",
|
|
54
|
+
chunk_size=2,
|
|
55
|
+
chunk_index=0,
|
|
56
|
+
cut_type="sentence_end",
|
|
57
|
+
is_part_of=document,
|
|
58
|
+
contains=[],
|
|
59
|
+
)
|
|
60
|
+
chunk2 = DocumentChunk(
|
|
61
|
+
text="Mike Broski",
|
|
62
|
+
chunk_size=2,
|
|
63
|
+
chunk_index=1,
|
|
64
|
+
cut_type="sentence_end",
|
|
65
|
+
is_part_of=document,
|
|
66
|
+
contains=[],
|
|
67
|
+
)
|
|
68
|
+
chunk3 = DocumentChunk(
|
|
69
|
+
text="Christina Mayer",
|
|
70
|
+
chunk_size=2,
|
|
71
|
+
chunk_index=2,
|
|
72
|
+
cut_type="sentence_end",
|
|
73
|
+
is_part_of=document,
|
|
74
|
+
contains=[],
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
entities = [chunk1, chunk2, chunk3]
|
|
78
|
+
|
|
79
|
+
await add_data_points(entities)
|
|
80
|
+
|
|
81
|
+
yield
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
await cognee.prune.prune_data()
|
|
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()
|
|
98
|
+
except Exception:
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest_asyncio.fixture
|
|
103
|
+
async def setup_test_environment_with_chunks_complex():
|
|
104
|
+
"""Set up a clean test environment with complex chunks."""
|
|
105
|
+
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
|
|
106
|
+
system_directory_path = str(base_dir / ".cognee_system/test_rag_completion_context_complex")
|
|
107
|
+
data_directory_path = str(base_dir / ".data_storage/test_rag_completion_context_complex")
|
|
108
|
+
|
|
109
|
+
cognee.config.system_root_directory(system_directory_path)
|
|
110
|
+
cognee.config.data_root_directory(data_directory_path)
|
|
111
|
+
|
|
112
|
+
await cognee.prune.prune_data()
|
|
113
|
+
await cognee.prune.prune_system(metadata=True)
|
|
114
|
+
await setup()
|
|
115
|
+
|
|
116
|
+
document1 = TextDocument(
|
|
117
|
+
name="Employee List",
|
|
118
|
+
raw_data_location="somewhere",
|
|
119
|
+
external_metadata="",
|
|
120
|
+
mime_type="text/plain",
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
document2 = TextDocument(
|
|
124
|
+
name="Car List",
|
|
125
|
+
raw_data_location="somewhere",
|
|
126
|
+
external_metadata="",
|
|
127
|
+
mime_type="text/plain",
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
chunk1 = DocumentChunk(
|
|
131
|
+
text="Steve Rodger",
|
|
132
|
+
chunk_size=2,
|
|
133
|
+
chunk_index=0,
|
|
134
|
+
cut_type="sentence_end",
|
|
135
|
+
is_part_of=document1,
|
|
136
|
+
contains=[],
|
|
137
|
+
)
|
|
138
|
+
chunk2 = DocumentChunk(
|
|
139
|
+
text="Mike Broski",
|
|
140
|
+
chunk_size=2,
|
|
141
|
+
chunk_index=1,
|
|
142
|
+
cut_type="sentence_end",
|
|
143
|
+
is_part_of=document1,
|
|
144
|
+
contains=[],
|
|
145
|
+
)
|
|
146
|
+
chunk3 = DocumentChunk(
|
|
147
|
+
text="Christina Mayer",
|
|
148
|
+
chunk_size=2,
|
|
149
|
+
chunk_index=2,
|
|
150
|
+
cut_type="sentence_end",
|
|
151
|
+
is_part_of=document1,
|
|
152
|
+
contains=[],
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
chunk4 = DocumentChunk(
|
|
156
|
+
text="Range Rover",
|
|
157
|
+
chunk_size=2,
|
|
158
|
+
chunk_index=0,
|
|
159
|
+
cut_type="sentence_end",
|
|
160
|
+
is_part_of=document2,
|
|
161
|
+
contains=[],
|
|
162
|
+
)
|
|
163
|
+
chunk5 = DocumentChunk(
|
|
164
|
+
text="Hyundai",
|
|
165
|
+
chunk_size=2,
|
|
166
|
+
chunk_index=1,
|
|
167
|
+
cut_type="sentence_end",
|
|
168
|
+
is_part_of=document2,
|
|
169
|
+
contains=[],
|
|
170
|
+
)
|
|
171
|
+
chunk6 = DocumentChunk(
|
|
172
|
+
text="Chrysler",
|
|
173
|
+
chunk_size=2,
|
|
174
|
+
chunk_index=2,
|
|
175
|
+
cut_type="sentence_end",
|
|
176
|
+
is_part_of=document2,
|
|
177
|
+
contains=[],
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
entities = [chunk1, chunk2, chunk3, chunk4, chunk5, chunk6]
|
|
181
|
+
|
|
182
|
+
await add_data_points(entities)
|
|
183
|
+
|
|
184
|
+
yield
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
await cognee.prune.prune_data()
|
|
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()
|
|
201
|
+
except Exception:
|
|
202
|
+
pass
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@pytest_asyncio.fixture
|
|
206
|
+
async def setup_test_environment_empty():
|
|
207
|
+
"""Set up a clean test environment without chunks."""
|
|
208
|
+
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
|
|
209
|
+
system_directory_path = str(
|
|
210
|
+
base_dir / ".cognee_system/test_get_rag_completion_context_on_empty_graph"
|
|
211
|
+
)
|
|
212
|
+
data_directory_path = str(
|
|
213
|
+
base_dir / ".data_storage/test_get_rag_completion_context_on_empty_graph"
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
cognee.config.system_root_directory(system_directory_path)
|
|
217
|
+
cognee.config.data_root_directory(data_directory_path)
|
|
218
|
+
|
|
219
|
+
await cognee.prune.prune_data()
|
|
220
|
+
await cognee.prune.prune_system(metadata=True)
|
|
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
|
+
|
|
232
|
+
yield
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
await cognee.prune.prune_data()
|
|
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()
|
|
249
|
+
except Exception:
|
|
250
|
+
pass
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
@pytest.mark.asyncio
|
|
254
|
+
async def test_rag_completion_context_simple(setup_test_environment_with_chunks_simple):
|
|
255
|
+
"""Integration test: verify CompletionRetriever can retrieve context (simple)."""
|
|
256
|
+
retriever = CompletionRetriever()
|
|
257
|
+
query = "Mike"
|
|
258
|
+
|
|
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
|
+
)
|
|
264
|
+
|
|
265
|
+
assert isinstance(context, str), "Context should be a string"
|
|
266
|
+
assert "Mike Broski" in context, "Failed to get Mike Broski"
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@pytest.mark.asyncio
|
|
270
|
+
async def test_rag_completion_context_multiple_chunks(setup_test_environment_with_chunks_simple):
|
|
271
|
+
"""Integration test: verify CompletionRetriever can retrieve context from multiple chunks."""
|
|
272
|
+
retriever = CompletionRetriever()
|
|
273
|
+
query = "Steve"
|
|
274
|
+
|
|
275
|
+
retrieved_objects = await retriever.get_retrieved_objects(query)
|
|
276
|
+
|
|
277
|
+
context = await retriever.get_context_from_objects(
|
|
278
|
+
query=query, retrieved_objects=retrieved_objects
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
assert isinstance(context, str), "Context should be a string"
|
|
282
|
+
assert "Steve Rodger" in context, "Failed to get Steve Rodger"
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
@pytest.mark.asyncio
|
|
286
|
+
async def test_rag_completion_context_complex(setup_test_environment_with_chunks_complex):
|
|
287
|
+
"""Integration test: verify CompletionRetriever can retrieve context (complex)."""
|
|
288
|
+
# TODO: top_k doesn't affect the output, it should be fixed.
|
|
289
|
+
retriever = CompletionRetriever(top_k=20)
|
|
290
|
+
query = "Christina"
|
|
291
|
+
|
|
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
|
+
)
|
|
297
|
+
|
|
298
|
+
assert context[0:15] == "Christina Mayer", "Failed to get Christina Mayer"
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@pytest.mark.asyncio
|
|
302
|
+
async def test_get_rag_completion_context_on_empty_graph(setup_test_environment_empty):
|
|
303
|
+
"""Integration test: verify CompletionRetriever handles empty graph correctly."""
|
|
304
|
+
retriever = CompletionRetriever()
|
|
305
|
+
query = "Christina Mayer"
|
|
306
|
+
|
|
307
|
+
with pytest.raises(NoDataError):
|
|
308
|
+
await retriever.get_retrieved_objects(query)
|
|
309
|
+
|
|
310
|
+
vector_engine = get_vector_engine()
|
|
311
|
+
await vector_engine.create_collection(
|
|
312
|
+
"DocumentChunk_text", payload_schema=DocumentChunkWithEntities
|
|
313
|
+
)
|
|
314
|
+
|
|
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
|
+
)
|
|
319
|
+
assert context == "", "Returned context should be empty on an empty graph"
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
import pytest
|
|
4
|
+
import pathlib
|
|
5
|
+
import pytest_asyncio
|
|
6
|
+
import cognee
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
from cognee.low_level import setup, DataPoint
|
|
10
|
+
from cognee.tasks.storage import add_data_points
|
|
11
|
+
from cognee.modules.chunking.models import DocumentChunk
|
|
12
|
+
from cognee.modules.data.processing.document_types import TextDocument
|
|
13
|
+
from cognee.modules.engine.models import Entity, EntityType
|
|
14
|
+
from cognee.modules.retrieval.entity_extractors.DummyEntityExtractor import DummyEntityExtractor
|
|
15
|
+
from cognee.modules.retrieval.context_providers.DummyContextProvider import DummyContextProvider
|
|
16
|
+
from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever
|
|
17
|
+
from cognee.modules.retrieval.graph_completion_retriever import GraphCompletionRetriever
|
|
18
|
+
from cognee.modules.retrieval.graph_completion_context_extension_retriever import (
|
|
19
|
+
GraphCompletionContextExtensionRetriever,
|
|
20
|
+
)
|
|
21
|
+
from cognee.modules.retrieval.EntityCompletionRetriever import EntityCompletionRetriever
|
|
22
|
+
from cognee.modules.retrieval.temporal_retriever import TemporalRetriever
|
|
23
|
+
from cognee.modules.retrieval.completion_retriever import CompletionRetriever
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TestAnswer(BaseModel):
|
|
27
|
+
answer: str
|
|
28
|
+
explanation: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _assert_string_answer(answer: list[str]):
|
|
32
|
+
assert isinstance(answer, list), f"Expected str, got {type(answer).__name__}"
|
|
33
|
+
assert all(isinstance(item, str) and item.strip() for item in answer), "Items should be strings"
|
|
34
|
+
assert all(item.strip() for item in answer), "Items should not be empty"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _assert_structured_answer(answer: list[TestAnswer]):
|
|
38
|
+
assert isinstance(answer, list), f"Expected list, got {type(answer).__name__}"
|
|
39
|
+
assert all(isinstance(x, TestAnswer) for x in answer), "Items should be TestAnswer"
|
|
40
|
+
assert all(x.answer.strip() for x in answer), "Answer text should not be empty"
|
|
41
|
+
assert all(x.explanation.strip() for x in answer), "Explanation should not be empty"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def _test_get_structured_graph_completion_cot():
|
|
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)
|
|
50
|
+
|
|
51
|
+
# Test with string response model (default)
|
|
52
|
+
string_answer = await retriever.get_completion_from_context(
|
|
53
|
+
query=query, retrieved_objects=triplets, context=context
|
|
54
|
+
)
|
|
55
|
+
_assert_string_answer(string_answer)
|
|
56
|
+
|
|
57
|
+
retriever.response_model = TestAnswer
|
|
58
|
+
# Test with structured response model
|
|
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
|
|
62
|
+
)
|
|
63
|
+
_assert_structured_answer(structured_answer)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def _test_get_structured_graph_completion():
|
|
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)
|
|
72
|
+
|
|
73
|
+
# Test with string response model (default)
|
|
74
|
+
string_answer = await retriever.get_completion_from_context(
|
|
75
|
+
query=query, retrieved_objects=triplets, context=context
|
|
76
|
+
)
|
|
77
|
+
_assert_string_answer(string_answer)
|
|
78
|
+
|
|
79
|
+
retriever.response_model = TestAnswer
|
|
80
|
+
# Test with structured response model
|
|
81
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
82
|
+
query=query, retrieved_objects=triplets, context=context
|
|
83
|
+
)
|
|
84
|
+
_assert_structured_answer(structured_answer)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async def _test_get_structured_graph_completion_temporal():
|
|
88
|
+
retriever = TemporalRetriever()
|
|
89
|
+
query = "When did Steve start working at Figma?"
|
|
90
|
+
|
|
91
|
+
# Test with string response model (default)
|
|
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
|
+
)
|
|
99
|
+
_assert_string_answer(string_answer)
|
|
100
|
+
|
|
101
|
+
retriever.response_model = TestAnswer
|
|
102
|
+
# Test with structured response model
|
|
103
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
104
|
+
query=query, retrieved_objects=triplets, context=context
|
|
105
|
+
)
|
|
106
|
+
_assert_structured_answer(structured_answer)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def _test_get_structured_graph_completion_rag():
|
|
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)
|
|
115
|
+
|
|
116
|
+
# Test with string response model (default)
|
|
117
|
+
string_answer = await retriever.get_completion_from_context(
|
|
118
|
+
query=query, retrieved_objects=triplets, context=context
|
|
119
|
+
)
|
|
120
|
+
_assert_string_answer(string_answer)
|
|
121
|
+
|
|
122
|
+
retriever.response_model = TestAnswer
|
|
123
|
+
# Test with structured response model
|
|
124
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
125
|
+
query=query, retrieved_objects=triplets, context=context
|
|
126
|
+
)
|
|
127
|
+
_assert_structured_answer(structured_answer)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def _test_get_structured_graph_completion_context_extension():
|
|
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)
|
|
136
|
+
|
|
137
|
+
# Test with string response model (default)
|
|
138
|
+
string_answer = await retriever.get_completion_from_context(
|
|
139
|
+
query=query, retrieved_objects=triplets, context=context
|
|
140
|
+
)
|
|
141
|
+
_assert_string_answer(string_answer)
|
|
142
|
+
|
|
143
|
+
retriever.response_model = TestAnswer
|
|
144
|
+
# Test with structured response model
|
|
145
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
146
|
+
query=query, retrieved_objects=triplets, context=context
|
|
147
|
+
)
|
|
148
|
+
_assert_structured_answer(structured_answer)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
async def _test_get_structured_entity_completion():
|
|
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)
|
|
157
|
+
|
|
158
|
+
# Test with string response model (default)
|
|
159
|
+
string_answer = await retriever.get_completion_from_context(
|
|
160
|
+
query=query, retrieved_objects=entities, context=context
|
|
161
|
+
)
|
|
162
|
+
_assert_string_answer(string_answer)
|
|
163
|
+
|
|
164
|
+
retriever.response_model = TestAnswer
|
|
165
|
+
# Test with structured response model
|
|
166
|
+
structured_answer = await retriever.get_completion_from_context(
|
|
167
|
+
query=query, retrieved_objects=entities, context=context
|
|
168
|
+
)
|
|
169
|
+
_assert_structured_answer(structured_answer)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@pytest_asyncio.fixture
|
|
173
|
+
async def setup_test_environment():
|
|
174
|
+
"""Set up a clean test environment with graph and document data."""
|
|
175
|
+
base_dir = pathlib.Path(__file__).parent.parent.parent.parent
|
|
176
|
+
system_directory_path = str(base_dir / ".cognee_system/test_get_structured_completion")
|
|
177
|
+
data_directory_path = str(base_dir / ".data_storage/test_get_structured_completion")
|
|
178
|
+
|
|
179
|
+
cognee.config.system_root_directory(system_directory_path)
|
|
180
|
+
cognee.config.data_root_directory(data_directory_path)
|
|
181
|
+
|
|
182
|
+
await cognee.prune.prune_data()
|
|
183
|
+
await cognee.prune.prune_system(metadata=True)
|
|
184
|
+
await setup()
|
|
185
|
+
|
|
186
|
+
class Company(DataPoint):
|
|
187
|
+
name: str
|
|
188
|
+
|
|
189
|
+
class Person(DataPoint):
|
|
190
|
+
name: str
|
|
191
|
+
works_for: Company
|
|
192
|
+
works_since: int
|
|
193
|
+
|
|
194
|
+
company1 = Company(name="Figma")
|
|
195
|
+
person1 = Person(name="Steve Rodger", works_for=company1, works_since=2015)
|
|
196
|
+
|
|
197
|
+
entities = [company1, person1]
|
|
198
|
+
await add_data_points(entities)
|
|
199
|
+
|
|
200
|
+
document = TextDocument(
|
|
201
|
+
name="Steve Rodger's career",
|
|
202
|
+
raw_data_location="somewhere",
|
|
203
|
+
external_metadata="",
|
|
204
|
+
mime_type="text/plain",
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
chunk1 = DocumentChunk(
|
|
208
|
+
text="Steve Rodger",
|
|
209
|
+
chunk_size=2,
|
|
210
|
+
chunk_index=0,
|
|
211
|
+
cut_type="sentence_end",
|
|
212
|
+
is_part_of=document,
|
|
213
|
+
contains=[],
|
|
214
|
+
)
|
|
215
|
+
chunk2 = DocumentChunk(
|
|
216
|
+
text="Mike Broski",
|
|
217
|
+
chunk_size=2,
|
|
218
|
+
chunk_index=1,
|
|
219
|
+
cut_type="sentence_end",
|
|
220
|
+
is_part_of=document,
|
|
221
|
+
contains=[],
|
|
222
|
+
)
|
|
223
|
+
chunk3 = DocumentChunk(
|
|
224
|
+
text="Christina Mayer",
|
|
225
|
+
chunk_size=2,
|
|
226
|
+
chunk_index=2,
|
|
227
|
+
cut_type="sentence_end",
|
|
228
|
+
is_part_of=document,
|
|
229
|
+
contains=[],
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
entities = [chunk1, chunk2, chunk3]
|
|
233
|
+
await add_data_points(entities)
|
|
234
|
+
|
|
235
|
+
entity_type = EntityType(name="Person", description="A human individual")
|
|
236
|
+
entity = Entity(name="Albert Einstein", is_a=entity_type, description="A famous physicist")
|
|
237
|
+
|
|
238
|
+
entities = [entity]
|
|
239
|
+
await add_data_points(entities)
|
|
240
|
+
|
|
241
|
+
yield
|
|
242
|
+
|
|
243
|
+
try:
|
|
244
|
+
await cognee.prune.prune_data()
|
|
245
|
+
await cognee.prune.prune_system(metadata=True)
|
|
246
|
+
except Exception:
|
|
247
|
+
pass
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@pytest.mark.asyncio
|
|
251
|
+
async def test_get_structured_completion(setup_test_environment):
|
|
252
|
+
"""Integration test: verify structured output completion for all retrievers."""
|
|
253
|
+
await _test_get_structured_graph_completion_cot()
|
|
254
|
+
await _test_get_structured_graph_completion()
|
|
255
|
+
await _test_get_structured_graph_completion_temporal()
|
|
256
|
+
await _test_get_structured_graph_completion_rag()
|
|
257
|
+
await _test_get_structured_graph_completion_context_extension()
|
|
258
|
+
await _test_get_structured_entity_completion()
|