cognee 0.5.1.dev0__py3-none-any.whl → 0.5.2.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognee/__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/cleanup/cleanup_unused_data.py +172 -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.dev0.dist-info}/METADATA +17 -10
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/RECORD +232 -144
- 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.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/entry_points.txt +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""Unit tests for usage logger core functions."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
from types import SimpleNamespace
|
|
7
|
+
|
|
8
|
+
from cognee.shared.usage_logger import (
|
|
9
|
+
_sanitize_value,
|
|
10
|
+
_sanitize_dict_key,
|
|
11
|
+
_get_param_names,
|
|
12
|
+
_get_param_defaults,
|
|
13
|
+
_extract_user_id,
|
|
14
|
+
_extract_parameters,
|
|
15
|
+
log_usage,
|
|
16
|
+
)
|
|
17
|
+
from cognee.shared.exceptions import UsageLoggerError
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestSanitizeValue:
|
|
21
|
+
"""Test _sanitize_value function."""
|
|
22
|
+
|
|
23
|
+
@pytest.mark.parametrize(
|
|
24
|
+
"value,expected",
|
|
25
|
+
[
|
|
26
|
+
(None, None),
|
|
27
|
+
("string", "string"),
|
|
28
|
+
(42, 42),
|
|
29
|
+
(3.14, 3.14),
|
|
30
|
+
(True, True),
|
|
31
|
+
(False, False),
|
|
32
|
+
],
|
|
33
|
+
)
|
|
34
|
+
def test_basic_types(self, value, expected):
|
|
35
|
+
assert _sanitize_value(value) == expected
|
|
36
|
+
|
|
37
|
+
def test_uuid_and_datetime(self):
|
|
38
|
+
"""Test UUID and datetime serialization."""
|
|
39
|
+
uuid_val = UUID("123e4567-e89b-12d3-a456-426614174000")
|
|
40
|
+
dt = datetime(2024, 1, 15, 12, 30, 45, tzinfo=timezone.utc)
|
|
41
|
+
|
|
42
|
+
assert _sanitize_value(uuid_val) == "123e4567-e89b-12d3-a456-426614174000"
|
|
43
|
+
assert _sanitize_value(dt) == "2024-01-15T12:30:45+00:00"
|
|
44
|
+
|
|
45
|
+
def test_collections(self):
|
|
46
|
+
"""Test list, tuple, and dict serialization."""
|
|
47
|
+
assert _sanitize_value(
|
|
48
|
+
[1, "string", UUID("123e4567-e89b-12d3-a456-426614174000"), None]
|
|
49
|
+
) == [1, "string", "123e4567-e89b-12d3-a456-426614174000", None]
|
|
50
|
+
assert _sanitize_value((1, "string", True)) == [1, "string", True]
|
|
51
|
+
assert _sanitize_value({"key": UUID("123e4567-e89b-12d3-a456-426614174000")}) == {
|
|
52
|
+
"key": "123e4567-e89b-12d3-a456-426614174000"
|
|
53
|
+
}
|
|
54
|
+
assert _sanitize_value([]) == []
|
|
55
|
+
assert _sanitize_value({}) == {}
|
|
56
|
+
|
|
57
|
+
def test_nested_and_complex(self):
|
|
58
|
+
"""Test nested structures and non-serializable types."""
|
|
59
|
+
# Nested structure
|
|
60
|
+
nested = {"level1": {"level2": {"level3": [1, 2, {"nested": "value"}]}}}
|
|
61
|
+
assert _sanitize_value(nested)["level1"]["level2"]["level3"][2]["nested"] == "value"
|
|
62
|
+
|
|
63
|
+
# Non-serializable
|
|
64
|
+
class CustomObject:
|
|
65
|
+
def __str__(self):
|
|
66
|
+
return "<CustomObject instance>"
|
|
67
|
+
|
|
68
|
+
result = _sanitize_value(CustomObject())
|
|
69
|
+
assert isinstance(result, str)
|
|
70
|
+
assert "<cannot be serialized" in result or "<CustomObject" in result
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TestSanitizeDictKey:
|
|
74
|
+
"""Test _sanitize_dict_key function."""
|
|
75
|
+
|
|
76
|
+
@pytest.mark.parametrize(
|
|
77
|
+
"key,expected_contains",
|
|
78
|
+
[
|
|
79
|
+
("simple_key", "simple_key"),
|
|
80
|
+
(UUID("123e4567-e89b-12d3-a456-426614174000"), "123e4567-e89b-12d3-a456-426614174000"),
|
|
81
|
+
((1, 2, 3), ["1", "2"]),
|
|
82
|
+
],
|
|
83
|
+
)
|
|
84
|
+
def test_key_types(self, key, expected_contains):
|
|
85
|
+
result = _sanitize_dict_key(key)
|
|
86
|
+
assert isinstance(result, str)
|
|
87
|
+
if isinstance(expected_contains, list):
|
|
88
|
+
assert all(item in result for item in expected_contains)
|
|
89
|
+
else:
|
|
90
|
+
assert expected_contains in result
|
|
91
|
+
|
|
92
|
+
def test_non_serializable_key(self):
|
|
93
|
+
class BadKey:
|
|
94
|
+
def __str__(self):
|
|
95
|
+
return "<BadKey instance>"
|
|
96
|
+
|
|
97
|
+
result = _sanitize_dict_key(BadKey())
|
|
98
|
+
assert isinstance(result, str)
|
|
99
|
+
assert "<key:" in result or "<BadKey" in result
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class TestGetParamNames:
|
|
103
|
+
"""Test _get_param_names function."""
|
|
104
|
+
|
|
105
|
+
@pytest.mark.parametrize(
|
|
106
|
+
"func_def,expected",
|
|
107
|
+
[
|
|
108
|
+
(lambda a, b, c: None, ["a", "b", "c"]),
|
|
109
|
+
(lambda a, b=42, c="default": None, ["a", "b", "c"]),
|
|
110
|
+
(lambda a, **kwargs: None, ["a", "kwargs"]),
|
|
111
|
+
(lambda *args: None, ["args"]),
|
|
112
|
+
],
|
|
113
|
+
)
|
|
114
|
+
def test_param_extraction(self, func_def, expected):
|
|
115
|
+
assert _get_param_names(func_def) == expected
|
|
116
|
+
|
|
117
|
+
def test_async_function(self):
|
|
118
|
+
async def func(a, b):
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
assert _get_param_names(func) == ["a", "b"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class TestGetParamDefaults:
|
|
125
|
+
"""Test _get_param_defaults function."""
|
|
126
|
+
|
|
127
|
+
@pytest.mark.parametrize(
|
|
128
|
+
"func_def,expected",
|
|
129
|
+
[
|
|
130
|
+
(lambda a, b=42, c="default", d=None: None, {"b": 42, "c": "default", "d": None}),
|
|
131
|
+
(lambda a, b, c: None, {}),
|
|
132
|
+
(lambda a, b=10, c="test", d=None: None, {"b": 10, "c": "test", "d": None}),
|
|
133
|
+
],
|
|
134
|
+
)
|
|
135
|
+
def test_default_extraction(self, func_def, expected):
|
|
136
|
+
assert _get_param_defaults(func_def) == expected
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class TestExtractUserId:
|
|
140
|
+
"""Test _extract_user_id function."""
|
|
141
|
+
|
|
142
|
+
def test_user_extraction(self):
|
|
143
|
+
"""Test extracting user_id from kwargs and args."""
|
|
144
|
+
user1 = SimpleNamespace(id=UUID("123e4567-e89b-12d3-a456-426614174000"))
|
|
145
|
+
user2 = SimpleNamespace(id="user-123")
|
|
146
|
+
|
|
147
|
+
# From kwargs
|
|
148
|
+
assert (
|
|
149
|
+
_extract_user_id((), {"user": user1}, ["user", "other"])
|
|
150
|
+
== "123e4567-e89b-12d3-a456-426614174000"
|
|
151
|
+
)
|
|
152
|
+
# From args
|
|
153
|
+
assert _extract_user_id((user2, "other"), {}, ["user", "other"]) == "user-123"
|
|
154
|
+
# Not present
|
|
155
|
+
assert _extract_user_id(("arg1",), {}, ["param1"]) is None
|
|
156
|
+
# None value
|
|
157
|
+
assert _extract_user_id((None,), {}, ["user"]) is None
|
|
158
|
+
# No id attribute
|
|
159
|
+
assert _extract_user_id((SimpleNamespace(name="test"),), {}, ["user"]) is None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class TestExtractParameters:
|
|
163
|
+
"""Test _extract_parameters function."""
|
|
164
|
+
|
|
165
|
+
def test_parameter_extraction(self):
|
|
166
|
+
"""Test parameter extraction with various scenarios."""
|
|
167
|
+
|
|
168
|
+
def func1(param1, param2, user=None):
|
|
169
|
+
pass
|
|
170
|
+
|
|
171
|
+
def func2(param1, param2=42, param3="default", user=None):
|
|
172
|
+
pass
|
|
173
|
+
|
|
174
|
+
def func3():
|
|
175
|
+
pass
|
|
176
|
+
|
|
177
|
+
def func4(param1, user):
|
|
178
|
+
pass
|
|
179
|
+
|
|
180
|
+
# Kwargs only
|
|
181
|
+
result = _extract_parameters(
|
|
182
|
+
(), {"param1": "v1", "param2": 42}, _get_param_names(func1), func1
|
|
183
|
+
)
|
|
184
|
+
assert result == {"param1": "v1", "param2": 42}
|
|
185
|
+
assert "user" not in result
|
|
186
|
+
|
|
187
|
+
# Args only
|
|
188
|
+
result = _extract_parameters(("v1", 42), {}, _get_param_names(func1), func1)
|
|
189
|
+
assert result == {"param1": "v1", "param2": 42}
|
|
190
|
+
|
|
191
|
+
# Mixed args/kwargs
|
|
192
|
+
result = _extract_parameters(("v1",), {"param3": "v3"}, _get_param_names(func2), func2)
|
|
193
|
+
assert result["param1"] == "v1" and result["param3"] == "v3"
|
|
194
|
+
|
|
195
|
+
# Defaults included
|
|
196
|
+
result = _extract_parameters(("v1",), {}, _get_param_names(func2), func2)
|
|
197
|
+
assert result["param1"] == "v1" and result["param2"] == 42 and result["param3"] == "default"
|
|
198
|
+
|
|
199
|
+
# No parameters
|
|
200
|
+
assert _extract_parameters((), {}, _get_param_names(func3), func3) == {}
|
|
201
|
+
|
|
202
|
+
# User excluded
|
|
203
|
+
user = SimpleNamespace(id="user-123")
|
|
204
|
+
result = _extract_parameters(("v1", user), {}, _get_param_names(func4), func4)
|
|
205
|
+
assert result == {"param1": "v1"} and "user" not in result
|
|
206
|
+
|
|
207
|
+
# Fallback when inspection fails
|
|
208
|
+
class BadFunc:
|
|
209
|
+
pass
|
|
210
|
+
|
|
211
|
+
result = _extract_parameters(("arg1", "arg2"), {}, [], BadFunc())
|
|
212
|
+
assert "arg_0" in result or "arg_1" in result
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class TestDecoratorValidation:
|
|
216
|
+
"""Test decorator validation and behavior."""
|
|
217
|
+
|
|
218
|
+
def test_decorator_validation(self):
|
|
219
|
+
"""Test decorator validation and metadata preservation."""
|
|
220
|
+
# Sync function raises error
|
|
221
|
+
with pytest.raises(UsageLoggerError, match="requires an async function"):
|
|
222
|
+
|
|
223
|
+
@log_usage()
|
|
224
|
+
def sync_func():
|
|
225
|
+
pass
|
|
226
|
+
|
|
227
|
+
# Async function accepted
|
|
228
|
+
@log_usage()
|
|
229
|
+
async def async_func():
|
|
230
|
+
pass
|
|
231
|
+
|
|
232
|
+
assert callable(async_func)
|
|
233
|
+
|
|
234
|
+
# Metadata preserved
|
|
235
|
+
@log_usage(function_name="test_func", log_type="test")
|
|
236
|
+
async def test_func(param1: str, param2: int = 42):
|
|
237
|
+
"""Test docstring."""
|
|
238
|
+
return param1
|
|
239
|
+
|
|
240
|
+
assert test_func.__name__ == "test_func"
|
|
241
|
+
assert "Test docstring" in test_func.__doc__
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
from cognee.modules.users.permissions.methods.has_user_management_permission import (
|
|
5
|
+
has_user_management_permission,
|
|
6
|
+
)
|
|
7
|
+
from cognee.modules.users.exceptions import PermissionDeniedError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FakeTenant:
|
|
11
|
+
def __init__(self, owner_id):
|
|
12
|
+
self.owner_id = owner_id
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.asyncio
|
|
16
|
+
async def test_has_user_management_permission_owner_allowed(monkeypatch):
|
|
17
|
+
requester_id = uuid4()
|
|
18
|
+
tenant_id = uuid4()
|
|
19
|
+
|
|
20
|
+
async def fake_get_tenant(_):
|
|
21
|
+
return FakeTenant(owner_id=requester_id)
|
|
22
|
+
|
|
23
|
+
monkeypatch.setattr(
|
|
24
|
+
"cognee.modules.users.permissions.methods.has_user_management_permission.get_tenant",
|
|
25
|
+
fake_get_tenant,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
result = await has_user_management_permission(requester_id, tenant_id)
|
|
29
|
+
assert result is True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.asyncio
|
|
33
|
+
async def test_has_user_management_permission_non_owner_denied(monkeypatch):
|
|
34
|
+
requester_id = uuid4()
|
|
35
|
+
tenant_id = uuid4()
|
|
36
|
+
|
|
37
|
+
async def fake_get_tenant(_):
|
|
38
|
+
return FakeTenant(owner_id=uuid4())
|
|
39
|
+
|
|
40
|
+
monkeypatch.setattr(
|
|
41
|
+
"cognee.modules.users.permissions.methods.has_user_management_permission.get_tenant",
|
|
42
|
+
fake_get_tenant,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
with pytest.raises(PermissionDeniedError):
|
|
46
|
+
await has_user_management_permission(requester_id, tenant_id)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognee
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2.dev0
|
|
4
4
|
Summary: Cognee - is a library for enriching LLM context with a semantic layer for better understanding and reasoning.
|
|
5
5
|
Project-URL: Homepage, https://www.cognee.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/topoteretes/cognee
|
|
@@ -17,10 +17,11 @@ Classifier: Operating System :: POSIX :: Linux
|
|
|
17
17
|
Classifier: Topic :: Software Development :: Libraries
|
|
18
18
|
Requires-Python: <3.14,>=3.10
|
|
19
19
|
Requires-Dist: aiofiles>=23.2.1
|
|
20
|
-
Requires-Dist: aiohttp<4.0.0,>=3.
|
|
20
|
+
Requires-Dist: aiohttp<4.0.0,>=3.13.3
|
|
21
21
|
Requires-Dist: aiolimiter>=1.2.1
|
|
22
22
|
Requires-Dist: aiosqlite<1.0.0,>=0.20.0
|
|
23
23
|
Requires-Dist: alembic<2,>=1.13.3
|
|
24
|
+
Requires-Dist: cbor2>=5.8.0
|
|
24
25
|
Requires-Dist: diskcache>=5.6.3
|
|
25
26
|
Requires-Dist: fakeredis[lua]>=2.32.0
|
|
26
27
|
Requires-Dist: fastapi-users[sqlalchemy]<15.0.0,>=14.0.1
|
|
@@ -32,6 +33,7 @@ Requires-Dist: instructor<2.0.0,>=1.9.1
|
|
|
32
33
|
Requires-Dist: jinja2<4,>=3.1.3
|
|
33
34
|
Requires-Dist: kuzu==0.11.3
|
|
34
35
|
Requires-Dist: lancedb<1.0.0,>=0.24.0
|
|
36
|
+
Requires-Dist: langdetect>=1.0.9
|
|
35
37
|
Requires-Dist: limits<5,>=4.4.1
|
|
36
38
|
Requires-Dist: litellm>=1.76.0
|
|
37
39
|
Requires-Dist: mistralai>=1.9.10
|
|
@@ -41,7 +43,7 @@ Requires-Dist: numpy<=4.0.0,>=1.26.4
|
|
|
41
43
|
Requires-Dist: onnxruntime<=1.22.1
|
|
42
44
|
Requires-Dist: openai>=1.80.1
|
|
43
45
|
Requires-Dist: pydantic-settings<3,>=2.2.1
|
|
44
|
-
Requires-Dist: pydantic
|
|
46
|
+
Requires-Dist: pydantic>=2.10.5
|
|
45
47
|
Requires-Dist: pylance<=0.36.0,>=0.22.0
|
|
46
48
|
Requires-Dist: pympler<2.0.0,>=1.1
|
|
47
49
|
Requires-Dist: pypdf<7.0.0,>=4.1.0
|
|
@@ -54,6 +56,7 @@ Requires-Dist: structlog<26,>=25.2.0
|
|
|
54
56
|
Requires-Dist: tenacity>=9.0.0
|
|
55
57
|
Requires-Dist: tiktoken<1.0.0,>=0.8.0
|
|
56
58
|
Requires-Dist: typing-extensions<5.0.0,>=4.12.2
|
|
59
|
+
Requires-Dist: urllib3>=2.6.0
|
|
57
60
|
Requires-Dist: uvicorn<1.0.0,>=0.34.0
|
|
58
61
|
Requires-Dist: websockets<16.0.0,>=15.0.1
|
|
59
62
|
Provides-Extra: anthropic
|
|
@@ -115,8 +118,11 @@ Requires-Dist: groq<1.0.0,>=0.8.0; extra == 'groq'
|
|
|
115
118
|
Provides-Extra: huggingface
|
|
116
119
|
Requires-Dist: transformers<5,>=4.46.3; extra == 'huggingface'
|
|
117
120
|
Provides-Extra: langchain
|
|
121
|
+
Requires-Dist: langchain-core>=1.2.5; extra == 'langchain'
|
|
118
122
|
Requires-Dist: langchain-text-splitters<1.0.0,>=0.3.2; extra == 'langchain'
|
|
119
123
|
Requires-Dist: langsmith<1.0.0,>=0.2.3; extra == 'langchain'
|
|
124
|
+
Provides-Extra: llama-cpp
|
|
125
|
+
Requires-Dist: llama-cpp-python[server]<1.0.0,>=0.3.0; extra == 'llama-cpp'
|
|
120
126
|
Provides-Extra: llama-index
|
|
121
127
|
Requires-Dist: llama-index-core<0.13,>=0.12.11; extra == 'llama-index'
|
|
122
128
|
Provides-Extra: mistral
|
|
@@ -221,12 +227,12 @@ Use your data to build personalized and dynamic memory for AI Agents. Cognee let
|
|
|
221
227
|
|
|
222
228
|
## About Cognee
|
|
223
229
|
|
|
224
|
-
Cognee is an open-source tool and platform that transforms your raw data into persistent and dynamic AI memory for Agents. It combines vector search with graph databases to make your documents both searchable by meaning and connected by relationships.
|
|
230
|
+
Cognee is an open-source tool and platform that transforms your raw data into persistent and dynamic AI memory for Agents. It combines vector search with graph databases to make your documents both searchable by meaning and connected by relationships.
|
|
225
231
|
|
|
226
232
|
You can use Cognee in two ways:
|
|
227
233
|
|
|
228
234
|
1. [Self-host Cognee Open Source](https://docs.cognee.ai/getting-started/installation), which stores all data locally by default.
|
|
229
|
-
2. [Connect to Cognee Cloud](https://platform.cognee.ai/), and get the same OSS stack on managed infrastructure for easier development and productionization.
|
|
235
|
+
2. [Connect to Cognee Cloud](https://platform.cognee.ai/), and get the same OSS stack on managed infrastructure for easier development and productionization.
|
|
230
236
|
|
|
231
237
|
### Cognee Open Source (self-hosted):
|
|
232
238
|
|
|
@@ -237,8 +243,8 @@ You can use Cognee in two ways:
|
|
|
237
243
|
- Offers high customizability through user-defined tasks, modular pipelines, and built-in search endpoints
|
|
238
244
|
|
|
239
245
|
### Cognee Cloud (managed):
|
|
240
|
-
- Hosted web UI dashboard
|
|
241
|
-
- Automatic version updates
|
|
246
|
+
- Hosted web UI dashboard
|
|
247
|
+
- Automatic version updates
|
|
242
248
|
- Resource usage analytics
|
|
243
249
|
- GDPR compliant, enterprise-grade security
|
|
244
250
|
|
|
@@ -275,13 +281,14 @@ To integrate other LLM providers, see our [LLM Provider Documentation](https://d
|
|
|
275
281
|
|
|
276
282
|
### Step 3: Run the Pipeline
|
|
277
283
|
|
|
278
|
-
Cognee will take your documents, generate a knowledge graph from them and then query the graph based on combined relationships.
|
|
284
|
+
Cognee will take your documents, generate a knowledge graph from them and then query the graph based on combined relationships.
|
|
279
285
|
|
|
280
286
|
Now, run a minimal pipeline:
|
|
281
287
|
|
|
282
288
|
```python
|
|
283
289
|
import cognee
|
|
284
290
|
import asyncio
|
|
291
|
+
from pprint import pprint
|
|
285
292
|
|
|
286
293
|
|
|
287
294
|
async def main():
|
|
@@ -299,7 +306,7 @@ async def main():
|
|
|
299
306
|
|
|
300
307
|
# Display the results
|
|
301
308
|
for result in results:
|
|
302
|
-
|
|
309
|
+
pprint(result)
|
|
303
310
|
|
|
304
311
|
|
|
305
312
|
if __name__ == '__main__':
|
|
@@ -313,7 +320,7 @@ As you can see, the output is generated from the document we previously stored i
|
|
|
313
320
|
Cognee turns documents into AI memory.
|
|
314
321
|
```
|
|
315
322
|
|
|
316
|
-
### Use the Cognee CLI
|
|
323
|
+
### Use the Cognee CLI
|
|
317
324
|
|
|
318
325
|
As an alternative, you can get started with these essential commands:
|
|
319
326
|
|