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
cognee/api/.env.example
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Comma-separated list of allowed origins for CORS (leave empty to block all cross-origin requests)
|
|
2
|
-
# Example:
|
|
3
|
-
# CORS_ALLOWED_ORIGINS="https://yourdomain.com,https://another.com"
|
|
4
|
-
# For local development, you might use:
|
|
5
|
-
# CORS_ALLOWED_ORIGINS="http://localhost:3000"
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from typing import Any, List, Optional, Type
|
|
2
|
-
from abc import ABC, abstractmethod
|
|
3
|
-
|
|
4
|
-
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class BaseGraphRetriever(ABC):
|
|
8
|
-
"""Base class for all graph based retrievers."""
|
|
9
|
-
|
|
10
|
-
@abstractmethod
|
|
11
|
-
async def get_context(self, query: str) -> List[Edge]:
|
|
12
|
-
"""Retrieves triplets based on the query."""
|
|
13
|
-
pass
|
|
14
|
-
|
|
15
|
-
@abstractmethod
|
|
16
|
-
async def get_completion(
|
|
17
|
-
self,
|
|
18
|
-
query: str,
|
|
19
|
-
context: Optional[List[Edge]] = None,
|
|
20
|
-
session_id: Optional[str] = None,
|
|
21
|
-
response_model: Type = str,
|
|
22
|
-
) -> List[Any]:
|
|
23
|
-
"""Generates a response using the query and optional context (triplets)."""
|
|
24
|
-
pass
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import Callable, List, Optional, Type
|
|
3
|
-
|
|
4
|
-
from cognee.modules.engine.models.node_set import NodeSet
|
|
5
|
-
from cognee.modules.retrieval.triplet_retriever import TripletRetriever
|
|
6
|
-
from cognee.modules.search.types import SearchType
|
|
7
|
-
from cognee.modules.search.operations import select_search_type
|
|
8
|
-
from cognee.modules.search.exceptions import UnsupportedSearchTypeError
|
|
9
|
-
|
|
10
|
-
# Retrievers
|
|
11
|
-
from cognee.modules.retrieval.user_qa_feedback import UserQAFeedback
|
|
12
|
-
from cognee.modules.retrieval.chunks_retriever import ChunksRetriever
|
|
13
|
-
from cognee.modules.retrieval.summaries_retriever import SummariesRetriever
|
|
14
|
-
from cognee.modules.retrieval.completion_retriever import CompletionRetriever
|
|
15
|
-
from cognee.modules.retrieval.graph_completion_retriever import GraphCompletionRetriever
|
|
16
|
-
from cognee.modules.retrieval.temporal_retriever import TemporalRetriever
|
|
17
|
-
from cognee.modules.retrieval.coding_rules_retriever import CodingRulesRetriever
|
|
18
|
-
from cognee.modules.retrieval.jaccard_retrival import JaccardChunksRetriever
|
|
19
|
-
from cognee.modules.retrieval.graph_summary_completion_retriever import (
|
|
20
|
-
GraphSummaryCompletionRetriever,
|
|
21
|
-
)
|
|
22
|
-
from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever
|
|
23
|
-
from cognee.modules.retrieval.graph_completion_context_extension_retriever import (
|
|
24
|
-
GraphCompletionContextExtensionRetriever,
|
|
25
|
-
)
|
|
26
|
-
from cognee.modules.retrieval.cypher_search_retriever import CypherSearchRetriever
|
|
27
|
-
from cognee.modules.retrieval.natural_language_retriever import NaturalLanguageRetriever
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async def get_search_type_tools(
|
|
31
|
-
query_type: SearchType,
|
|
32
|
-
query_text: str,
|
|
33
|
-
system_prompt_path: str = "answer_simple_question.txt",
|
|
34
|
-
system_prompt: Optional[str] = None,
|
|
35
|
-
top_k: int = 10,
|
|
36
|
-
node_type: Optional[Type] = NodeSet,
|
|
37
|
-
node_name: Optional[List[str]] = None,
|
|
38
|
-
save_interaction: bool = False,
|
|
39
|
-
last_k: Optional[int] = None,
|
|
40
|
-
wide_search_top_k: Optional[int] = 100,
|
|
41
|
-
triplet_distance_penalty: Optional[float] = 3.5,
|
|
42
|
-
) -> list:
|
|
43
|
-
search_tasks: dict[SearchType, List[Callable]] = {
|
|
44
|
-
SearchType.SUMMARIES: [
|
|
45
|
-
SummariesRetriever(top_k=top_k).get_completion,
|
|
46
|
-
SummariesRetriever(top_k=top_k).get_context,
|
|
47
|
-
],
|
|
48
|
-
SearchType.CHUNKS: [
|
|
49
|
-
ChunksRetriever(top_k=top_k).get_completion,
|
|
50
|
-
ChunksRetriever(top_k=top_k).get_context,
|
|
51
|
-
],
|
|
52
|
-
SearchType.RAG_COMPLETION: [
|
|
53
|
-
CompletionRetriever(
|
|
54
|
-
system_prompt_path=system_prompt_path,
|
|
55
|
-
top_k=top_k,
|
|
56
|
-
system_prompt=system_prompt,
|
|
57
|
-
).get_completion,
|
|
58
|
-
CompletionRetriever(
|
|
59
|
-
system_prompt_path=system_prompt_path,
|
|
60
|
-
top_k=top_k,
|
|
61
|
-
system_prompt=system_prompt,
|
|
62
|
-
).get_context,
|
|
63
|
-
],
|
|
64
|
-
SearchType.TRIPLET_COMPLETION: [
|
|
65
|
-
TripletRetriever(
|
|
66
|
-
system_prompt_path=system_prompt_path,
|
|
67
|
-
top_k=top_k,
|
|
68
|
-
system_prompt=system_prompt,
|
|
69
|
-
).get_completion,
|
|
70
|
-
TripletRetriever(
|
|
71
|
-
system_prompt_path=system_prompt_path,
|
|
72
|
-
top_k=top_k,
|
|
73
|
-
system_prompt=system_prompt,
|
|
74
|
-
).get_context,
|
|
75
|
-
],
|
|
76
|
-
SearchType.GRAPH_COMPLETION: [
|
|
77
|
-
GraphCompletionRetriever(
|
|
78
|
-
system_prompt_path=system_prompt_path,
|
|
79
|
-
top_k=top_k,
|
|
80
|
-
node_type=node_type,
|
|
81
|
-
node_name=node_name,
|
|
82
|
-
save_interaction=save_interaction,
|
|
83
|
-
system_prompt=system_prompt,
|
|
84
|
-
wide_search_top_k=wide_search_top_k,
|
|
85
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
86
|
-
).get_completion,
|
|
87
|
-
GraphCompletionRetriever(
|
|
88
|
-
system_prompt_path=system_prompt_path,
|
|
89
|
-
top_k=top_k,
|
|
90
|
-
node_type=node_type,
|
|
91
|
-
node_name=node_name,
|
|
92
|
-
save_interaction=save_interaction,
|
|
93
|
-
system_prompt=system_prompt,
|
|
94
|
-
wide_search_top_k=wide_search_top_k,
|
|
95
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
96
|
-
).get_context,
|
|
97
|
-
],
|
|
98
|
-
SearchType.GRAPH_COMPLETION_COT: [
|
|
99
|
-
GraphCompletionCotRetriever(
|
|
100
|
-
system_prompt_path=system_prompt_path,
|
|
101
|
-
top_k=top_k,
|
|
102
|
-
node_type=node_type,
|
|
103
|
-
node_name=node_name,
|
|
104
|
-
save_interaction=save_interaction,
|
|
105
|
-
system_prompt=system_prompt,
|
|
106
|
-
wide_search_top_k=wide_search_top_k,
|
|
107
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
108
|
-
).get_completion,
|
|
109
|
-
GraphCompletionCotRetriever(
|
|
110
|
-
system_prompt_path=system_prompt_path,
|
|
111
|
-
top_k=top_k,
|
|
112
|
-
node_type=node_type,
|
|
113
|
-
node_name=node_name,
|
|
114
|
-
save_interaction=save_interaction,
|
|
115
|
-
system_prompt=system_prompt,
|
|
116
|
-
wide_search_top_k=wide_search_top_k,
|
|
117
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
118
|
-
).get_context,
|
|
119
|
-
],
|
|
120
|
-
SearchType.GRAPH_COMPLETION_CONTEXT_EXTENSION: [
|
|
121
|
-
GraphCompletionContextExtensionRetriever(
|
|
122
|
-
system_prompt_path=system_prompt_path,
|
|
123
|
-
top_k=top_k,
|
|
124
|
-
node_type=node_type,
|
|
125
|
-
node_name=node_name,
|
|
126
|
-
save_interaction=save_interaction,
|
|
127
|
-
system_prompt=system_prompt,
|
|
128
|
-
wide_search_top_k=wide_search_top_k,
|
|
129
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
130
|
-
).get_completion,
|
|
131
|
-
GraphCompletionContextExtensionRetriever(
|
|
132
|
-
system_prompt_path=system_prompt_path,
|
|
133
|
-
top_k=top_k,
|
|
134
|
-
node_type=node_type,
|
|
135
|
-
node_name=node_name,
|
|
136
|
-
save_interaction=save_interaction,
|
|
137
|
-
system_prompt=system_prompt,
|
|
138
|
-
wide_search_top_k=wide_search_top_k,
|
|
139
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
140
|
-
).get_context,
|
|
141
|
-
],
|
|
142
|
-
SearchType.GRAPH_SUMMARY_COMPLETION: [
|
|
143
|
-
GraphSummaryCompletionRetriever(
|
|
144
|
-
system_prompt_path=system_prompt_path,
|
|
145
|
-
top_k=top_k,
|
|
146
|
-
node_type=node_type,
|
|
147
|
-
node_name=node_name,
|
|
148
|
-
save_interaction=save_interaction,
|
|
149
|
-
system_prompt=system_prompt,
|
|
150
|
-
wide_search_top_k=wide_search_top_k,
|
|
151
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
152
|
-
).get_completion,
|
|
153
|
-
GraphSummaryCompletionRetriever(
|
|
154
|
-
system_prompt_path=system_prompt_path,
|
|
155
|
-
top_k=top_k,
|
|
156
|
-
node_type=node_type,
|
|
157
|
-
node_name=node_name,
|
|
158
|
-
save_interaction=save_interaction,
|
|
159
|
-
system_prompt=system_prompt,
|
|
160
|
-
wide_search_top_k=wide_search_top_k,
|
|
161
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
162
|
-
).get_context,
|
|
163
|
-
],
|
|
164
|
-
SearchType.CYPHER: [
|
|
165
|
-
CypherSearchRetriever().get_completion,
|
|
166
|
-
CypherSearchRetriever().get_context,
|
|
167
|
-
],
|
|
168
|
-
SearchType.NATURAL_LANGUAGE: [
|
|
169
|
-
NaturalLanguageRetriever().get_completion,
|
|
170
|
-
NaturalLanguageRetriever().get_context,
|
|
171
|
-
],
|
|
172
|
-
SearchType.FEEDBACK: [UserQAFeedback(last_k=last_k).add_feedback],
|
|
173
|
-
SearchType.TEMPORAL: [
|
|
174
|
-
TemporalRetriever(
|
|
175
|
-
top_k=top_k,
|
|
176
|
-
wide_search_top_k=wide_search_top_k,
|
|
177
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
178
|
-
).get_completion,
|
|
179
|
-
TemporalRetriever(
|
|
180
|
-
top_k=top_k,
|
|
181
|
-
wide_search_top_k=wide_search_top_k,
|
|
182
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
183
|
-
).get_context,
|
|
184
|
-
],
|
|
185
|
-
SearchType.CHUNKS_LEXICAL: (
|
|
186
|
-
lambda _r=JaccardChunksRetriever(top_k=top_k): [
|
|
187
|
-
_r.get_completion,
|
|
188
|
-
_r.get_context,
|
|
189
|
-
]
|
|
190
|
-
)(),
|
|
191
|
-
SearchType.CODING_RULES: [
|
|
192
|
-
CodingRulesRetriever(rules_nodeset_name=node_name).get_existing_rules,
|
|
193
|
-
],
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
# If the query type is FEELING_LUCKY, select the search type intelligently
|
|
197
|
-
if query_type is SearchType.FEELING_LUCKY:
|
|
198
|
-
query_type = await select_search_type(query_text)
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
query_type in [SearchType.CYPHER, SearchType.NATURAL_LANGUAGE]
|
|
202
|
-
and os.getenv("ALLOW_CYPHER_QUERY", "true").lower() == "false"
|
|
203
|
-
):
|
|
204
|
-
raise UnsupportedSearchTypeError("Cypher query search types are disabled.")
|
|
205
|
-
|
|
206
|
-
from cognee.modules.retrieval.registered_community_retrievers import (
|
|
207
|
-
registered_community_retrievers,
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
if query_type in registered_community_retrievers:
|
|
211
|
-
retriever = registered_community_retrievers[query_type]
|
|
212
|
-
retriever_instance = retriever(top_k=top_k)
|
|
213
|
-
search_type_tools = [
|
|
214
|
-
retriever_instance.get_completion,
|
|
215
|
-
retriever_instance.get_context,
|
|
216
|
-
]
|
|
217
|
-
else:
|
|
218
|
-
search_type_tools = search_tasks.get(query_type)
|
|
219
|
-
|
|
220
|
-
if not search_type_tools:
|
|
221
|
-
raise UnsupportedSearchTypeError(str(query_type))
|
|
222
|
-
|
|
223
|
-
return search_type_tools
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
from typing import Any, List, Optional, Tuple, Type, Union
|
|
2
|
-
|
|
3
|
-
from cognee.infrastructure.databases.graph import get_graph_engine
|
|
4
|
-
from cognee.modules.data.models.Dataset import Dataset
|
|
5
|
-
from cognee.modules.engine.models.node_set import NodeSet
|
|
6
|
-
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge
|
|
7
|
-
from cognee.modules.search.types import SearchType
|
|
8
|
-
from cognee.shared.logging_utils import get_logger
|
|
9
|
-
|
|
10
|
-
from .get_search_type_tools import get_search_type_tools
|
|
11
|
-
|
|
12
|
-
logger = get_logger()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async def no_access_control_search(
|
|
16
|
-
query_type: SearchType,
|
|
17
|
-
query_text: str,
|
|
18
|
-
system_prompt_path: str = "answer_simple_question.txt",
|
|
19
|
-
system_prompt: Optional[str] = None,
|
|
20
|
-
top_k: int = 10,
|
|
21
|
-
node_type: Optional[Type] = NodeSet,
|
|
22
|
-
node_name: Optional[List[str]] = None,
|
|
23
|
-
save_interaction: bool = False,
|
|
24
|
-
last_k: Optional[int] = None,
|
|
25
|
-
only_context: bool = False,
|
|
26
|
-
session_id: Optional[str] = None,
|
|
27
|
-
wide_search_top_k: Optional[int] = 100,
|
|
28
|
-
triplet_distance_penalty: Optional[float] = 3.5,
|
|
29
|
-
) -> Tuple[Any, Union[str, List[Edge]], List[Dataset]]:
|
|
30
|
-
search_tools = await get_search_type_tools(
|
|
31
|
-
query_type=query_type,
|
|
32
|
-
query_text=query_text,
|
|
33
|
-
system_prompt_path=system_prompt_path,
|
|
34
|
-
system_prompt=system_prompt,
|
|
35
|
-
top_k=top_k,
|
|
36
|
-
node_type=node_type,
|
|
37
|
-
node_name=node_name,
|
|
38
|
-
save_interaction=save_interaction,
|
|
39
|
-
last_k=last_k,
|
|
40
|
-
wide_search_top_k=wide_search_top_k,
|
|
41
|
-
triplet_distance_penalty=triplet_distance_penalty,
|
|
42
|
-
)
|
|
43
|
-
graph_engine = await get_graph_engine()
|
|
44
|
-
is_empty = await graph_engine.is_empty()
|
|
45
|
-
|
|
46
|
-
if is_empty:
|
|
47
|
-
# TODO: we can log here, but not all search types use graph. Still keeping this here for reviewer input
|
|
48
|
-
logger.warning("Search attempt on an empty knowledge graph")
|
|
49
|
-
if len(search_tools) == 2:
|
|
50
|
-
[get_completion, get_context] = search_tools
|
|
51
|
-
|
|
52
|
-
if only_context:
|
|
53
|
-
return None, await get_context(query_text), []
|
|
54
|
-
|
|
55
|
-
context = await get_context(query_text)
|
|
56
|
-
result = await get_completion(query_text, context, session_id=session_id)
|
|
57
|
-
else:
|
|
58
|
-
unknown_tool = search_tools[0]
|
|
59
|
-
result = await unknown_tool(query_text)
|
|
60
|
-
context = ""
|
|
61
|
-
|
|
62
|
-
return result, context, []
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
from typing import List, cast
|
|
2
|
-
from uuid import uuid5, NAMESPACE_OID
|
|
3
|
-
|
|
4
|
-
from cognee.modules.graph.utils import resolve_edges_to_text
|
|
5
|
-
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge
|
|
6
|
-
from cognee.modules.search.types.SearchResult import SearchResultDataset
|
|
7
|
-
from cognee.modules.search.utils.transform_context_to_graph import transform_context_to_graph
|
|
8
|
-
from cognee.modules.search.utils.transform_insights_to_graph import transform_insights_to_graph
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async def prepare_search_result(search_result):
|
|
12
|
-
results, context, datasets = search_result
|
|
13
|
-
|
|
14
|
-
graphs = None
|
|
15
|
-
result_graph = None
|
|
16
|
-
context_texts = {}
|
|
17
|
-
|
|
18
|
-
if isinstance(datasets, list) and len(datasets) == 0:
|
|
19
|
-
datasets = [
|
|
20
|
-
SearchResultDataset(
|
|
21
|
-
id=uuid5(NAMESPACE_OID, "*"),
|
|
22
|
-
name="all available datasets",
|
|
23
|
-
)
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
isinstance(context, List)
|
|
28
|
-
and len(context) > 0
|
|
29
|
-
and isinstance(context[0], tuple)
|
|
30
|
-
and context[0][1].get("relationship_name")
|
|
31
|
-
):
|
|
32
|
-
context_graph = transform_insights_to_graph(context)
|
|
33
|
-
graphs = {
|
|
34
|
-
", ".join([dataset.name for dataset in datasets]): context_graph,
|
|
35
|
-
}
|
|
36
|
-
results = None
|
|
37
|
-
elif isinstance(context, List) and len(context) > 0 and isinstance(context[0], Edge):
|
|
38
|
-
context_graph = transform_context_to_graph(context)
|
|
39
|
-
|
|
40
|
-
graphs = {
|
|
41
|
-
", ".join([dataset.name for dataset in datasets]): context_graph,
|
|
42
|
-
}
|
|
43
|
-
context_texts = {
|
|
44
|
-
", ".join([dataset.name for dataset in datasets]): await resolve_edges_to_text(context),
|
|
45
|
-
}
|
|
46
|
-
elif isinstance(context, str):
|
|
47
|
-
context_texts = {
|
|
48
|
-
", ".join([dataset.name for dataset in datasets]): context,
|
|
49
|
-
}
|
|
50
|
-
elif isinstance(context, List) and len(context) > 0 and isinstance(context[0], str):
|
|
51
|
-
context_texts = {
|
|
52
|
-
", ".join([dataset.name for dataset in datasets]): "\n".join(cast(List[str], context)),
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if isinstance(results, List) and len(results) > 0 and isinstance(results[0], Edge):
|
|
56
|
-
result_graph = transform_context_to_graph(results)
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
"result": result_graph or results[0] if results and len(results) == 1 else results,
|
|
60
|
-
"graphs": graphs,
|
|
61
|
-
"context": context_texts,
|
|
62
|
-
"datasets": datasets,
|
|
63
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
End-to-end integration test for feedback enrichment feature.
|
|
3
|
-
|
|
4
|
-
Tests the complete feedback enrichment pipeline:
|
|
5
|
-
1. Add data and cognify
|
|
6
|
-
2. Run search with save_interaction=True to create CogneeUserInteraction nodes
|
|
7
|
-
3. Submit feedback to create CogneeUserFeedback nodes
|
|
8
|
-
4. Run memify with feedback enrichment tasks to create FeedbackEnrichment nodes
|
|
9
|
-
5. Verify all nodes and edges are properly created and linked in the graph
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
import os
|
|
13
|
-
import pathlib
|
|
14
|
-
from collections import Counter
|
|
15
|
-
|
|
16
|
-
import cognee
|
|
17
|
-
from cognee.infrastructure.databases.graph import get_graph_engine
|
|
18
|
-
from cognee.modules.pipelines.tasks.task import Task
|
|
19
|
-
from cognee.modules.search.types import SearchType
|
|
20
|
-
from cognee.shared.data_models import KnowledgeGraph
|
|
21
|
-
from cognee.shared.logging_utils import get_logger
|
|
22
|
-
from cognee.tasks.feedback.create_enrichments import create_enrichments
|
|
23
|
-
from cognee.tasks.feedback.extract_feedback_interactions import (
|
|
24
|
-
extract_feedback_interactions,
|
|
25
|
-
)
|
|
26
|
-
from cognee.tasks.feedback.generate_improved_answers import generate_improved_answers
|
|
27
|
-
from cognee.tasks.feedback.link_enrichments_to_feedback import (
|
|
28
|
-
link_enrichments_to_feedback,
|
|
29
|
-
)
|
|
30
|
-
from cognee.tasks.graph import extract_graph_from_data
|
|
31
|
-
from cognee.tasks.storage import add_data_points
|
|
32
|
-
|
|
33
|
-
logger = get_logger()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
async def main():
|
|
37
|
-
data_directory_path = str(
|
|
38
|
-
pathlib.Path(
|
|
39
|
-
os.path.join(
|
|
40
|
-
pathlib.Path(__file__).parent,
|
|
41
|
-
".data_storage/test_feedback_enrichment",
|
|
42
|
-
)
|
|
43
|
-
).resolve()
|
|
44
|
-
)
|
|
45
|
-
cognee_directory_path = str(
|
|
46
|
-
pathlib.Path(
|
|
47
|
-
os.path.join(
|
|
48
|
-
pathlib.Path(__file__).parent,
|
|
49
|
-
".cognee_system/test_feedback_enrichment",
|
|
50
|
-
)
|
|
51
|
-
).resolve()
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
cognee.config.data_root_directory(data_directory_path)
|
|
55
|
-
cognee.config.system_root_directory(cognee_directory_path)
|
|
56
|
-
|
|
57
|
-
await cognee.prune.prune_data()
|
|
58
|
-
await cognee.prune.prune_system(metadata=True)
|
|
59
|
-
|
|
60
|
-
dataset_name = "feedback_enrichment_test"
|
|
61
|
-
|
|
62
|
-
await cognee.add("Cognee turns documents into AI memory.", dataset_name)
|
|
63
|
-
await cognee.cognify([dataset_name])
|
|
64
|
-
|
|
65
|
-
question_text = "Say something."
|
|
66
|
-
result = await cognee.search(
|
|
67
|
-
query_type=SearchType.GRAPH_COMPLETION,
|
|
68
|
-
query_text=question_text,
|
|
69
|
-
save_interaction=True,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
assert len(result) > 0, "Search should return non-empty results"
|
|
73
|
-
|
|
74
|
-
feedback_text = "This answer was completely useless, my feedback is definitely negative."
|
|
75
|
-
await cognee.search(
|
|
76
|
-
query_type=SearchType.FEEDBACK,
|
|
77
|
-
query_text=feedback_text,
|
|
78
|
-
last_k=1,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
graph_engine = await get_graph_engine()
|
|
82
|
-
nodes_before, edges_before = await graph_engine.get_graph_data()
|
|
83
|
-
|
|
84
|
-
interaction_nodes_before = [
|
|
85
|
-
(node_id, props)
|
|
86
|
-
for node_id, props in nodes_before
|
|
87
|
-
if props.get("type") == "CogneeUserInteraction"
|
|
88
|
-
]
|
|
89
|
-
feedback_nodes_before = [
|
|
90
|
-
(node_id, props)
|
|
91
|
-
for node_id, props in nodes_before
|
|
92
|
-
if props.get("type") == "CogneeUserFeedback"
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
edge_types_before = Counter(edge[2] for edge in edges_before)
|
|
96
|
-
|
|
97
|
-
assert len(interaction_nodes_before) >= 1, (
|
|
98
|
-
f"Expected at least 1 CogneeUserInteraction node, found {len(interaction_nodes_before)}"
|
|
99
|
-
)
|
|
100
|
-
assert len(feedback_nodes_before) >= 1, (
|
|
101
|
-
f"Expected at least 1 CogneeUserFeedback node, found {len(feedback_nodes_before)}"
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
for node_id, props in feedback_nodes_before:
|
|
105
|
-
sentiment = props.get("sentiment", "")
|
|
106
|
-
score = props.get("score", 0)
|
|
107
|
-
feedback_text = props.get("feedback", "")
|
|
108
|
-
logger.info(
|
|
109
|
-
"Feedback node created",
|
|
110
|
-
feedback=feedback_text,
|
|
111
|
-
sentiment=sentiment,
|
|
112
|
-
score=score,
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
assert edge_types_before.get("gives_feedback_to", 0) >= 1, (
|
|
116
|
-
f"Expected at least 1 'gives_feedback_to' edge, found {edge_types_before.get('gives_feedback_to', 0)}"
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
extraction_tasks = [Task(extract_feedback_interactions, last_n=5)]
|
|
120
|
-
enrichment_tasks = [
|
|
121
|
-
Task(generate_improved_answers, top_k=20),
|
|
122
|
-
Task(create_enrichments),
|
|
123
|
-
Task(
|
|
124
|
-
extract_graph_from_data,
|
|
125
|
-
graph_model=KnowledgeGraph,
|
|
126
|
-
task_config={"batch_size": 10},
|
|
127
|
-
),
|
|
128
|
-
Task(add_data_points, task_config={"batch_size": 10}),
|
|
129
|
-
Task(link_enrichments_to_feedback),
|
|
130
|
-
]
|
|
131
|
-
|
|
132
|
-
await cognee.memify(
|
|
133
|
-
extraction_tasks=extraction_tasks,
|
|
134
|
-
enrichment_tasks=enrichment_tasks,
|
|
135
|
-
data=[{}],
|
|
136
|
-
dataset=dataset_name,
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
nodes_after, edges_after = await graph_engine.get_graph_data()
|
|
140
|
-
|
|
141
|
-
enrichment_nodes = [
|
|
142
|
-
(node_id, props)
|
|
143
|
-
for node_id, props in nodes_after
|
|
144
|
-
if props.get("type") == "FeedbackEnrichment"
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
assert len(enrichment_nodes) >= 1, (
|
|
148
|
-
f"Expected at least 1 FeedbackEnrichment node, found {len(enrichment_nodes)}"
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
for node_id, props in enrichment_nodes:
|
|
152
|
-
assert "text" in props, f"FeedbackEnrichment node {node_id} missing 'text' property"
|
|
153
|
-
|
|
154
|
-
enrichment_node_ids = {node_id for node_id, _ in enrichment_nodes}
|
|
155
|
-
edges_with_enrichments = [
|
|
156
|
-
edge
|
|
157
|
-
for edge in edges_after
|
|
158
|
-
if edge[0] in enrichment_node_ids or edge[1] in enrichment_node_ids
|
|
159
|
-
]
|
|
160
|
-
|
|
161
|
-
assert len(edges_with_enrichments) >= 1, (
|
|
162
|
-
f"Expected enrichment nodes to have at least 1 edge, found {len(edges_with_enrichments)}"
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
await cognee.prune.prune_data()
|
|
166
|
-
await cognee.prune.prune_system(metadata=True)
|
|
167
|
-
|
|
168
|
-
logger.info("All feedback enrichment tests passed successfully")
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if __name__ == "__main__":
|
|
172
|
-
import asyncio
|
|
173
|
-
|
|
174
|
-
asyncio.run(main())
|