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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import uuid
|
|
3
|
+
from contextlib import asynccontextmanager
|
|
4
|
+
from types import SimpleNamespace
|
|
5
|
+
from unittest.mock import AsyncMock
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from fastapi import FastAPI
|
|
9
|
+
from fastapi.testclient import TestClient
|
|
10
|
+
|
|
11
|
+
from cognee.modules.users.methods import get_authenticated_user
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(scope="session")
|
|
15
|
+
def test_client():
|
|
16
|
+
from cognee.api.v1.datasets.routers.get_datasets_router import get_datasets_router
|
|
17
|
+
|
|
18
|
+
app = FastAPI()
|
|
19
|
+
app.include_router(get_datasets_router(), prefix="/api/v1/datasets")
|
|
20
|
+
|
|
21
|
+
with TestClient(app) as c:
|
|
22
|
+
yield c
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.fixture
|
|
26
|
+
def client(test_client):
|
|
27
|
+
async def override_get_authenticated_user():
|
|
28
|
+
return SimpleNamespace(
|
|
29
|
+
id=str(uuid.uuid4()),
|
|
30
|
+
email="default@example.com",
|
|
31
|
+
is_active=True,
|
|
32
|
+
tenant_id=str(uuid.uuid4()),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
import importlib
|
|
36
|
+
|
|
37
|
+
datasets_router_module = importlib.import_module(
|
|
38
|
+
"cognee.api.v1.datasets.routers.get_datasets_router"
|
|
39
|
+
)
|
|
40
|
+
datasets_router_module.send_telemetry = lambda *args, **kwargs: None
|
|
41
|
+
|
|
42
|
+
test_client.app.dependency_overrides[get_authenticated_user] = override_get_authenticated_user
|
|
43
|
+
yield test_client
|
|
44
|
+
test_client.app.dependency_overrides.pop(get_authenticated_user, None)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _patch_raw_download_dependencies(
|
|
48
|
+
monkeypatch, *, dataset_id, data_id, raw_data_location, name, mime_type
|
|
49
|
+
):
|
|
50
|
+
"""
|
|
51
|
+
Patch the internal dataset/data lookups used by GET /datasets/{dataset_id}/data/{data_id}/raw.
|
|
52
|
+
Keeps the test focused on response behavior (FileResponse vs StreamingResponse).
|
|
53
|
+
"""
|
|
54
|
+
import importlib
|
|
55
|
+
|
|
56
|
+
datasets_router_module = importlib.import_module(
|
|
57
|
+
"cognee.api.v1.datasets.routers.get_datasets_router"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
monkeypatch.setattr(
|
|
61
|
+
datasets_router_module,
|
|
62
|
+
"get_authorized_existing_datasets",
|
|
63
|
+
AsyncMock(return_value=[SimpleNamespace(id=dataset_id)]),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
import cognee.modules.data.methods as data_methods_module
|
|
67
|
+
|
|
68
|
+
monkeypatch.setattr(
|
|
69
|
+
data_methods_module,
|
|
70
|
+
"get_dataset_data",
|
|
71
|
+
AsyncMock(return_value=[SimpleNamespace(id=data_id)]),
|
|
72
|
+
)
|
|
73
|
+
monkeypatch.setattr(
|
|
74
|
+
data_methods_module,
|
|
75
|
+
"get_data",
|
|
76
|
+
AsyncMock(
|
|
77
|
+
return_value=SimpleNamespace(
|
|
78
|
+
id=data_id,
|
|
79
|
+
raw_data_location=raw_data_location,
|
|
80
|
+
name=name,
|
|
81
|
+
mime_type=mime_type,
|
|
82
|
+
)
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_get_raw_data_local_file_downloads_bytes(client, monkeypatch, tmp_path):
|
|
88
|
+
"""Downloads bytes from a file:// raw_data_location."""
|
|
89
|
+
dataset_id = uuid.uuid4()
|
|
90
|
+
data_id = uuid.uuid4()
|
|
91
|
+
|
|
92
|
+
file_path = tmp_path / "example.txt"
|
|
93
|
+
content = b"hello from disk"
|
|
94
|
+
file_path.write_bytes(content)
|
|
95
|
+
|
|
96
|
+
_patch_raw_download_dependencies(
|
|
97
|
+
monkeypatch,
|
|
98
|
+
dataset_id=dataset_id,
|
|
99
|
+
data_id=data_id,
|
|
100
|
+
raw_data_location=file_path.as_uri(),
|
|
101
|
+
name="example.txt",
|
|
102
|
+
mime_type="text/plain",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
response = client.get(f"/api/v1/datasets/{dataset_id}/data/{data_id}/raw")
|
|
106
|
+
assert response.status_code == 200
|
|
107
|
+
assert response.content == content
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_get_raw_data_s3_streams_bytes_without_s3_dependency(client, monkeypatch):
|
|
111
|
+
"""Streams bytes from an s3:// raw_data_location (mocked)."""
|
|
112
|
+
dataset_id = uuid.uuid4()
|
|
113
|
+
data_id = uuid.uuid4()
|
|
114
|
+
|
|
115
|
+
_patch_raw_download_dependencies(
|
|
116
|
+
monkeypatch,
|
|
117
|
+
dataset_id=dataset_id,
|
|
118
|
+
data_id=data_id,
|
|
119
|
+
raw_data_location="s3://bucket/path/to/file.txt",
|
|
120
|
+
name="file.txt",
|
|
121
|
+
mime_type="text/plain",
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
import cognee.infrastructure.files.utils.open_data_file as open_data_file_module
|
|
125
|
+
|
|
126
|
+
@asynccontextmanager
|
|
127
|
+
async def fake_open_data_file(_file_path: str, mode: str = "rb", **_kwargs):
|
|
128
|
+
assert mode == "rb"
|
|
129
|
+
yield io.BytesIO(b"hello from s3")
|
|
130
|
+
|
|
131
|
+
monkeypatch.setattr(open_data_file_module, "open_data_file", fake_open_data_file)
|
|
132
|
+
|
|
133
|
+
response = client.get(f"/api/v1/datasets/{dataset_id}/data/{data_id}/raw")
|
|
134
|
+
assert response.status_code == 200
|
|
135
|
+
assert response.content == b"hello from s3"
|
|
136
|
+
assert response.headers.get("content-disposition") == 'attachment; filename="file.txt"'
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_get_raw_data_unsupported_scheme_returns_501(client, monkeypatch):
|
|
140
|
+
"""Returns 501 for unsupported raw_data_location schemes (e.g., http://)."""
|
|
141
|
+
dataset_id = uuid.uuid4()
|
|
142
|
+
data_id = uuid.uuid4()
|
|
143
|
+
|
|
144
|
+
_patch_raw_download_dependencies(
|
|
145
|
+
monkeypatch,
|
|
146
|
+
dataset_id=dataset_id,
|
|
147
|
+
data_id=data_id,
|
|
148
|
+
raw_data_location="http://example.com/file.txt",
|
|
149
|
+
name="file.txt",
|
|
150
|
+
mime_type="text/plain",
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
response = client.get(f"/api/v1/datasets/{dataset_id}/data/{data_id}/raw")
|
|
154
|
+
assert response.status_code == 501
|
|
155
|
+
assert "Storage scheme 'http' not supported" in response.json()["detail"]
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_get_raw_data_plain_path_downloads_bytes(client, monkeypatch, tmp_path):
|
|
159
|
+
"""Downloads bytes from a plain local path (no scheme)."""
|
|
160
|
+
dataset_id = uuid.uuid4()
|
|
161
|
+
data_id = uuid.uuid4()
|
|
162
|
+
|
|
163
|
+
file_path = tmp_path / "plain.txt"
|
|
164
|
+
content = b"plain content"
|
|
165
|
+
file_path.write_bytes(content)
|
|
166
|
+
|
|
167
|
+
_patch_raw_download_dependencies(
|
|
168
|
+
monkeypatch,
|
|
169
|
+
dataset_id=dataset_id,
|
|
170
|
+
data_id=data_id,
|
|
171
|
+
raw_data_location=str(file_path),
|
|
172
|
+
name="plain.txt",
|
|
173
|
+
mime_type="text/plain",
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
response = client.get(f"/api/v1/datasets/{dataset_id}/data/{data_id}/raw")
|
|
177
|
+
assert response.status_code == 200
|
|
178
|
+
assert response.content == content
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_get_raw_data_encoded_path_downloads_bytes(client, monkeypatch, tmp_path):
|
|
182
|
+
"""Downloads bytes from a percent-encoded file URI (e.g. spaces)."""
|
|
183
|
+
dataset_id = uuid.uuid4()
|
|
184
|
+
data_id = uuid.uuid4()
|
|
185
|
+
|
|
186
|
+
file_name = "example file.txt"
|
|
187
|
+
file_path = tmp_path / file_name
|
|
188
|
+
content = b"content with spaces"
|
|
189
|
+
file_path.write_bytes(content)
|
|
190
|
+
|
|
191
|
+
# Convert to URI, which should encode space as %20
|
|
192
|
+
uri = file_path.as_uri()
|
|
193
|
+
assert "%20" in uri
|
|
194
|
+
|
|
195
|
+
_patch_raw_download_dependencies(
|
|
196
|
+
monkeypatch,
|
|
197
|
+
dataset_id=dataset_id,
|
|
198
|
+
data_id=data_id,
|
|
199
|
+
raw_data_location=uri,
|
|
200
|
+
name=file_name,
|
|
201
|
+
mime_type="text/plain",
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
response = client.get(f"/api/v1/datasets/{dataset_id}/data/{data_id}/raw")
|
|
205
|
+
assert response.status_code == 200
|
|
206
|
+
assert response.content == content
|
|
@@ -12,8 +12,9 @@ async def test_answer_generation():
|
|
|
12
12
|
corpus_list, qa_pairs = DummyAdapter().load_corpus(limit=limit)
|
|
13
13
|
|
|
14
14
|
mock_retriever = AsyncMock()
|
|
15
|
-
mock_retriever.
|
|
16
|
-
mock_retriever.
|
|
15
|
+
mock_retriever.get_retrieved_objects = AsyncMock(return_value=[])
|
|
16
|
+
mock_retriever.get_context_from_objects = AsyncMock(return_value="Mocked retrieval context")
|
|
17
|
+
mock_retriever.get_completion_from_context = AsyncMock(return_value=["Mocked answer"])
|
|
17
18
|
|
|
18
19
|
answer_generator = AnswerGeneratorExecutor()
|
|
19
20
|
answers = await answer_generator.question_answering_non_parallel(
|
|
@@ -21,7 +22,7 @@ async def test_answer_generation():
|
|
|
21
22
|
retriever=mock_retriever,
|
|
22
23
|
)
|
|
23
24
|
|
|
24
|
-
mock_retriever.
|
|
25
|
+
mock_retriever.get_context_from_objects.assert_any_await(qa_pairs[0]["question"], [])
|
|
25
26
|
|
|
26
27
|
assert len(answers) == len(qa_pairs)
|
|
27
28
|
assert answers[0]["question"] == qa_pairs[0]["question"], (
|
|
@@ -9,7 +9,7 @@ def test_node_initialization():
|
|
|
9
9
|
"""Test that a Node is initialized correctly."""
|
|
10
10
|
node = Node("node1", {"attr1": "value1"}, dimension=2)
|
|
11
11
|
assert node.id == "node1"
|
|
12
|
-
assert node.attributes == {"attr1": "value1", "vector_distance":
|
|
12
|
+
assert node.attributes == {"attr1": "value1", "vector_distance": None}
|
|
13
13
|
assert len(node.status) == 2
|
|
14
14
|
assert np.all(node.status == 1)
|
|
15
15
|
|
|
@@ -86,6 +86,46 @@ def test_node_hash():
|
|
|
86
86
|
assert hash(node) == hash("node1")
|
|
87
87
|
|
|
88
88
|
|
|
89
|
+
def test_node_vector_distance_stays_none():
|
|
90
|
+
"""Test that vector_distance remains None when no distances are passed."""
|
|
91
|
+
node = Node("node1")
|
|
92
|
+
assert node.attributes.get("vector_distance") is None
|
|
93
|
+
|
|
94
|
+
# Verify it stays None even after other operations
|
|
95
|
+
node.add_attribute("other_attr", "value")
|
|
96
|
+
assert node.attributes.get("vector_distance") is None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_node_vector_distance_with_custom_attributes():
|
|
100
|
+
"""Test that vector_distance is None even when node has custom attributes."""
|
|
101
|
+
node = Node("node1", {"custom": "value", "another": 42})
|
|
102
|
+
assert node.attributes.get("vector_distance") is None
|
|
103
|
+
assert node.attributes["custom"] == "value"
|
|
104
|
+
assert node.attributes["another"] == 42
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_edge_vector_distance_stays_none():
|
|
108
|
+
"""Test that vector_distance remains None when no distances are passed."""
|
|
109
|
+
node1 = Node("node1")
|
|
110
|
+
node2 = Node("node2")
|
|
111
|
+
edge = Edge(node1, node2)
|
|
112
|
+
assert edge.attributes.get("vector_distance") is None
|
|
113
|
+
|
|
114
|
+
# Verify it stays None even after other operations
|
|
115
|
+
edge.add_attribute("other_attr", "value")
|
|
116
|
+
assert edge.attributes.get("vector_distance") is None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_edge_vector_distance_with_custom_attributes():
|
|
120
|
+
"""Test that vector_distance is None even when edge has custom attributes."""
|
|
121
|
+
node1 = Node("node1")
|
|
122
|
+
node2 = Node("node2")
|
|
123
|
+
edge = Edge(node1, node2, {"weight": 5, "type": "test"})
|
|
124
|
+
assert edge.attributes.get("vector_distance") is None
|
|
125
|
+
assert edge.attributes["weight"] == 5
|
|
126
|
+
assert edge.attributes["type"] == "test"
|
|
127
|
+
|
|
128
|
+
|
|
89
129
|
### Tests for Edge ###
|
|
90
130
|
|
|
91
131
|
|
|
@@ -96,7 +136,7 @@ def test_edge_initialization():
|
|
|
96
136
|
edge = Edge(node1, node2, {"weight": 10}, directed=False, dimension=2)
|
|
97
137
|
assert edge.node1 == node1
|
|
98
138
|
assert edge.node2 == node2
|
|
99
|
-
assert edge.attributes == {"vector_distance":
|
|
139
|
+
assert edge.attributes == {"vector_distance": None, "weight": 10}
|
|
100
140
|
assert edge.directed is False
|
|
101
141
|
assert len(edge.status) == 2
|
|
102
142
|
assert np.all(edge.status == 1)
|