cognee 0.2.3.dev1__py3-none-any.whl → 0.3.0.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 +1 -0
- cognee/__main__.py +4 -0
- cognee/api/client.py +28 -3
- cognee/api/health.py +10 -13
- cognee/api/v1/add/add.py +20 -6
- cognee/api/v1/add/routers/get_add_router.py +12 -37
- cognee/api/v1/cloud/routers/__init__.py +1 -0
- cognee/api/v1/cloud/routers/get_checks_router.py +23 -0
- cognee/api/v1/cognify/code_graph_pipeline.py +14 -3
- cognee/api/v1/cognify/cognify.py +67 -105
- cognee/api/v1/cognify/routers/get_cognify_router.py +11 -3
- cognee/api/v1/datasets/routers/get_datasets_router.py +16 -5
- cognee/api/v1/memify/routers/__init__.py +1 -0
- cognee/api/v1/memify/routers/get_memify_router.py +100 -0
- cognee/api/v1/notebooks/routers/__init__.py +1 -0
- cognee/api/v1/notebooks/routers/get_notebooks_router.py +96 -0
- cognee/api/v1/responses/default_tools.py +4 -0
- cognee/api/v1/responses/dispatch_function.py +6 -1
- cognee/api/v1/responses/models.py +1 -1
- cognee/api/v1/search/routers/get_search_router.py +20 -1
- cognee/api/v1/search/search.py +17 -4
- cognee/api/v1/sync/__init__.py +17 -0
- cognee/api/v1/sync/routers/__init__.py +3 -0
- cognee/api/v1/sync/routers/get_sync_router.py +241 -0
- cognee/api/v1/sync/sync.py +877 -0
- cognee/api/v1/users/routers/get_auth_router.py +13 -1
- cognee/base_config.py +10 -1
- cognee/cli/__init__.py +10 -0
- cognee/cli/_cognee.py +180 -0
- cognee/cli/commands/__init__.py +1 -0
- cognee/cli/commands/add_command.py +80 -0
- cognee/cli/commands/cognify_command.py +128 -0
- cognee/cli/commands/config_command.py +225 -0
- cognee/cli/commands/delete_command.py +80 -0
- cognee/cli/commands/search_command.py +149 -0
- cognee/cli/config.py +33 -0
- cognee/cli/debug.py +21 -0
- cognee/cli/echo.py +45 -0
- cognee/cli/exceptions.py +23 -0
- cognee/cli/minimal_cli.py +97 -0
- cognee/cli/reference.py +26 -0
- cognee/cli/suppress_logging.py +12 -0
- cognee/eval_framework/corpus_builder/corpus_builder_executor.py +2 -2
- cognee/eval_framework/eval_config.py +1 -1
- cognee/infrastructure/databases/graph/config.py +10 -4
- cognee/infrastructure/databases/graph/get_graph_engine.py +4 -9
- cognee/infrastructure/databases/graph/kuzu/adapter.py +199 -2
- cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +138 -0
- cognee/infrastructure/databases/relational/__init__.py +2 -0
- cognee/infrastructure/databases/relational/get_async_session.py +15 -0
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +6 -1
- cognee/infrastructure/databases/relational/with_async_session.py +25 -0
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +1 -1
- cognee/infrastructure/databases/vector/config.py +13 -6
- cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +6 -4
- cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +16 -7
- cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +5 -5
- cognee/infrastructure/databases/vector/embeddings/config.py +2 -2
- cognee/infrastructure/databases/vector/embeddings/embedding_rate_limiter.py +2 -6
- cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +10 -7
- cognee/infrastructure/files/storage/LocalFileStorage.py +9 -0
- cognee/infrastructure/files/storage/S3FileStorage.py +5 -0
- cognee/infrastructure/files/storage/StorageManager.py +7 -1
- cognee/infrastructure/files/storage/storage.py +16 -0
- cognee/infrastructure/files/utils/get_data_file_path.py +14 -9
- cognee/infrastructure/files/utils/get_file_metadata.py +2 -1
- cognee/infrastructure/llm/LLMGateway.py +32 -5
- cognee/infrastructure/llm/config.py +6 -4
- cognee/infrastructure/llm/prompts/extract_query_time.txt +15 -0
- cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +25 -0
- cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +30 -0
- cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +16 -5
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +2 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_event_entities.py +44 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/__init__.py +1 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_content_graph.py +19 -15
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_event_graph.py +46 -0
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +3 -3
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +3 -3
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +2 -2
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +14 -8
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +6 -4
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +28 -4
- cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +2 -2
- cognee/infrastructure/llm/tokenizer/HuggingFace/adapter.py +3 -3
- cognee/infrastructure/llm/tokenizer/Mistral/adapter.py +3 -3
- cognee/infrastructure/llm/tokenizer/TikToken/adapter.py +6 -6
- cognee/infrastructure/llm/utils.py +7 -7
- cognee/infrastructure/utils/run_sync.py +8 -1
- cognee/modules/chunking/models/DocumentChunk.py +4 -3
- cognee/modules/cloud/exceptions/CloudApiKeyMissingError.py +15 -0
- cognee/modules/cloud/exceptions/CloudConnectionError.py +15 -0
- cognee/modules/cloud/exceptions/__init__.py +2 -0
- cognee/modules/cloud/operations/__init__.py +1 -0
- cognee/modules/cloud/operations/check_api_key.py +25 -0
- cognee/modules/data/deletion/prune_system.py +1 -1
- cognee/modules/data/methods/__init__.py +2 -0
- cognee/modules/data/methods/check_dataset_name.py +1 -1
- cognee/modules/data/methods/create_authorized_dataset.py +19 -0
- cognee/modules/data/methods/get_authorized_dataset.py +11 -5
- cognee/modules/data/methods/get_authorized_dataset_by_name.py +16 -0
- cognee/modules/data/methods/get_dataset_data.py +1 -1
- cognee/modules/data/methods/load_or_create_datasets.py +2 -20
- cognee/modules/engine/models/Event.py +16 -0
- cognee/modules/engine/models/Interval.py +8 -0
- cognee/modules/engine/models/Timestamp.py +13 -0
- cognee/modules/engine/models/__init__.py +3 -0
- cognee/modules/engine/utils/__init__.py +2 -0
- cognee/modules/engine/utils/generate_event_datapoint.py +46 -0
- cognee/modules/engine/utils/generate_timestamp_datapoint.py +51 -0
- cognee/modules/graph/cognee_graph/CogneeGraph.py +2 -2
- cognee/modules/graph/methods/get_formatted_graph_data.py +3 -2
- cognee/modules/graph/utils/__init__.py +1 -0
- cognee/modules/graph/utils/resolve_edges_to_text.py +71 -0
- cognee/modules/memify/__init__.py +1 -0
- cognee/modules/memify/memify.py +118 -0
- cognee/modules/notebooks/methods/__init__.py +5 -0
- cognee/modules/notebooks/methods/create_notebook.py +26 -0
- cognee/modules/notebooks/methods/delete_notebook.py +13 -0
- cognee/modules/notebooks/methods/get_notebook.py +21 -0
- cognee/modules/notebooks/methods/get_notebooks.py +18 -0
- cognee/modules/notebooks/methods/update_notebook.py +17 -0
- cognee/modules/notebooks/models/Notebook.py +53 -0
- cognee/modules/notebooks/models/__init__.py +1 -0
- cognee/modules/notebooks/operations/__init__.py +1 -0
- cognee/modules/notebooks/operations/run_in_local_sandbox.py +55 -0
- cognee/modules/pipelines/__init__.py +1 -1
- cognee/modules/pipelines/exceptions/tasks.py +18 -0
- cognee/modules/pipelines/layers/__init__.py +1 -0
- cognee/modules/pipelines/layers/check_pipeline_run_qualification.py +59 -0
- cognee/modules/pipelines/layers/pipeline_execution_mode.py +127 -0
- cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +28 -0
- cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +34 -0
- cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +55 -0
- cognee/modules/pipelines/layers/setup_and_check_environment.py +41 -0
- cognee/modules/pipelines/layers/validate_pipeline_tasks.py +20 -0
- cognee/modules/pipelines/methods/__init__.py +2 -0
- cognee/modules/pipelines/methods/get_pipeline_runs_by_dataset.py +34 -0
- cognee/modules/pipelines/methods/reset_pipeline_run_status.py +16 -0
- cognee/modules/pipelines/operations/__init__.py +0 -1
- cognee/modules/pipelines/operations/log_pipeline_run_initiated.py +1 -1
- cognee/modules/pipelines/operations/pipeline.py +24 -138
- cognee/modules/pipelines/operations/run_tasks.py +17 -41
- cognee/modules/retrieval/base_feedback.py +11 -0
- cognee/modules/retrieval/base_graph_retriever.py +18 -0
- cognee/modules/retrieval/base_retriever.py +1 -1
- cognee/modules/retrieval/code_retriever.py +8 -0
- cognee/modules/retrieval/coding_rules_retriever.py +31 -0
- cognee/modules/retrieval/completion_retriever.py +9 -3
- cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -0
- cognee/modules/retrieval/cypher_search_retriever.py +1 -9
- cognee/modules/retrieval/graph_completion_context_extension_retriever.py +29 -13
- cognee/modules/retrieval/graph_completion_cot_retriever.py +30 -13
- cognee/modules/retrieval/graph_completion_retriever.py +107 -56
- cognee/modules/retrieval/graph_summary_completion_retriever.py +5 -1
- cognee/modules/retrieval/insights_retriever.py +14 -3
- cognee/modules/retrieval/natural_language_retriever.py +0 -4
- cognee/modules/retrieval/summaries_retriever.py +1 -1
- cognee/modules/retrieval/temporal_retriever.py +152 -0
- cognee/modules/retrieval/user_qa_feedback.py +83 -0
- cognee/modules/retrieval/utils/brute_force_triplet_search.py +7 -32
- cognee/modules/retrieval/utils/completion.py +10 -3
- cognee/modules/retrieval/utils/extract_uuid_from_node.py +18 -0
- cognee/modules/retrieval/utils/models.py +40 -0
- cognee/modules/search/methods/get_search_type_tools.py +168 -0
- cognee/modules/search/methods/no_access_control_search.py +47 -0
- cognee/modules/search/methods/search.py +239 -118
- cognee/modules/search/types/SearchResult.py +21 -0
- cognee/modules/search/types/SearchType.py +3 -0
- cognee/modules/search/types/__init__.py +1 -0
- cognee/modules/search/utils/__init__.py +2 -0
- cognee/modules/search/utils/prepare_search_result.py +41 -0
- cognee/modules/search/utils/transform_context_to_graph.py +38 -0
- cognee/modules/settings/get_settings.py +2 -2
- cognee/modules/sync/__init__.py +1 -0
- cognee/modules/sync/methods/__init__.py +23 -0
- cognee/modules/sync/methods/create_sync_operation.py +53 -0
- cognee/modules/sync/methods/get_sync_operation.py +107 -0
- cognee/modules/sync/methods/update_sync_operation.py +248 -0
- cognee/modules/sync/models/SyncOperation.py +142 -0
- cognee/modules/sync/models/__init__.py +3 -0
- cognee/modules/users/__init__.py +0 -1
- cognee/modules/users/methods/__init__.py +4 -1
- cognee/modules/users/methods/create_user.py +26 -1
- cognee/modules/users/methods/get_authenticated_user.py +36 -42
- cognee/modules/users/methods/get_default_user.py +3 -1
- cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +2 -1
- cognee/root_dir.py +19 -0
- cognee/shared/CodeGraphEntities.py +1 -0
- cognee/shared/logging_utils.py +143 -32
- cognee/shared/utils.py +0 -1
- cognee/tasks/codingagents/coding_rule_associations.py +127 -0
- cognee/tasks/graph/extract_graph_from_data.py +6 -2
- cognee/tasks/ingestion/save_data_item_to_storage.py +23 -0
- cognee/tasks/memify/__init__.py +2 -0
- cognee/tasks/memify/extract_subgraph.py +7 -0
- cognee/tasks/memify/extract_subgraph_chunks.py +11 -0
- cognee/tasks/repo_processor/get_local_dependencies.py +2 -0
- cognee/tasks/repo_processor/get_repo_file_dependencies.py +144 -47
- cognee/tasks/storage/add_data_points.py +33 -3
- cognee/tasks/temporal_graph/__init__.py +1 -0
- cognee/tasks/temporal_graph/add_entities_to_event.py +85 -0
- cognee/tasks/temporal_graph/enrich_events.py +34 -0
- cognee/tasks/temporal_graph/extract_events_and_entities.py +32 -0
- cognee/tasks/temporal_graph/extract_knowledge_graph_from_events.py +41 -0
- cognee/tasks/temporal_graph/models.py +49 -0
- cognee/tests/integration/cli/__init__.py +3 -0
- cognee/tests/integration/cli/test_cli_integration.py +331 -0
- cognee/tests/integration/documents/PdfDocument_test.py +2 -2
- cognee/tests/integration/documents/TextDocument_test.py +2 -4
- cognee/tests/integration/documents/UnstructuredDocument_test.py +5 -8
- cognee/tests/{test_deletion.py → test_delete_hard.py} +0 -37
- cognee/tests/test_delete_soft.py +85 -0
- cognee/tests/test_kuzu.py +2 -2
- cognee/tests/test_neo4j.py +2 -2
- cognee/tests/test_permissions.py +3 -3
- cognee/tests/test_relational_db_migration.py +7 -5
- cognee/tests/test_search_db.py +136 -23
- cognee/tests/test_temporal_graph.py +167 -0
- cognee/tests/unit/api/__init__.py +1 -0
- cognee/tests/unit/api/test_conditional_authentication_endpoints.py +246 -0
- cognee/tests/unit/cli/__init__.py +3 -0
- cognee/tests/unit/cli/test_cli_commands.py +483 -0
- cognee/tests/unit/cli/test_cli_edge_cases.py +625 -0
- cognee/tests/unit/cli/test_cli_main.py +173 -0
- cognee/tests/unit/cli/test_cli_runner.py +62 -0
- cognee/tests/unit/cli/test_cli_utils.py +127 -0
- cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +18 -2
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +12 -15
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +10 -15
- cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +4 -3
- cognee/tests/unit/modules/retrieval/insights_retriever_test.py +4 -2
- cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +18 -2
- cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +225 -0
- cognee/tests/unit/modules/users/__init__.py +1 -0
- cognee/tests/unit/modules/users/test_conditional_authentication.py +277 -0
- cognee/tests/unit/processing/utils/utils_test.py +20 -1
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/METADATA +13 -9
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/RECORD +245 -135
- cognee-0.3.0.dev0.dist-info/entry_points.txt +2 -0
- cognee/infrastructure/databases/graph/networkx/adapter.py +0 -1017
- cognee/infrastructure/pipeline/models/Operation.py +0 -60
- cognee/notebooks/github_analysis_step_by_step.ipynb +0 -37
- cognee/tests/tasks/descriptive_metrics/networkx_metrics_test.py +0 -7
- cognee/tests/unit/modules/search/search_methods_test.py +0 -223
- /cognee/{infrastructure/databases/graph/networkx → api/v1/memify}/__init__.py +0 -0
- /cognee/{infrastructure/pipeline/models → tasks/codingagents}/__init__.py +0 -0
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/WHEEL +0 -0
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from cognee.cli.reference import SupportsCliCommand
|
|
6
|
+
from cognee.cli import DEFAULT_DOCS_URL
|
|
7
|
+
import cognee.cli.echo as fmt
|
|
8
|
+
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DeleteCommand(SupportsCliCommand):
|
|
12
|
+
command_string = "delete"
|
|
13
|
+
help_string = "Delete data from cognee knowledge base"
|
|
14
|
+
docs_url = DEFAULT_DOCS_URL
|
|
15
|
+
description = """
|
|
16
|
+
The `cognee delete` command removes data from your knowledge base.
|
|
17
|
+
|
|
18
|
+
You can delete:
|
|
19
|
+
- Specific datasets by name
|
|
20
|
+
- All data (with confirmation)
|
|
21
|
+
- Data for specific users
|
|
22
|
+
|
|
23
|
+
Be careful with deletion operations as they are irreversible.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
27
|
+
parser.add_argument("--dataset-name", "-d", help="Specific dataset to delete")
|
|
28
|
+
parser.add_argument("--user-id", "-u", help="User ID to delete data for")
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--all", action="store_true", help="Delete all data (requires confirmation)"
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument("--force", "-f", action="store_true", help="Skip confirmation prompts")
|
|
33
|
+
|
|
34
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
35
|
+
try:
|
|
36
|
+
# Import cognee here to avoid circular imports
|
|
37
|
+
import cognee
|
|
38
|
+
|
|
39
|
+
# Validate arguments
|
|
40
|
+
if not any([args.dataset_name, args.user_id, args.all]):
|
|
41
|
+
fmt.error("Please specify what to delete: --dataset-name, --user-id, or --all")
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
# Build confirmation message
|
|
45
|
+
if args.all:
|
|
46
|
+
confirm_msg = "Delete ALL data from cognee?"
|
|
47
|
+
operation = "all data"
|
|
48
|
+
elif args.dataset_name:
|
|
49
|
+
confirm_msg = f"Delete dataset '{args.dataset_name}'?"
|
|
50
|
+
operation = f"dataset '{args.dataset_name}'"
|
|
51
|
+
elif args.user_id:
|
|
52
|
+
confirm_msg = f"Delete all data for user '{args.user_id}'?"
|
|
53
|
+
operation = f"data for user '{args.user_id}'"
|
|
54
|
+
|
|
55
|
+
# Confirm deletion unless forced
|
|
56
|
+
if not args.force:
|
|
57
|
+
fmt.warning("This operation is irreversible!")
|
|
58
|
+
if not fmt.confirm(confirm_msg):
|
|
59
|
+
fmt.echo("Deletion cancelled.")
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
fmt.echo(f"Deleting {operation}...")
|
|
63
|
+
|
|
64
|
+
# Run the async delete function
|
|
65
|
+
async def run_delete():
|
|
66
|
+
try:
|
|
67
|
+
if args.all:
|
|
68
|
+
await cognee.delete(dataset_name=None, user_id=args.user_id)
|
|
69
|
+
else:
|
|
70
|
+
await cognee.delete(dataset_name=args.dataset_name, user_id=args.user_id)
|
|
71
|
+
except Exception as e:
|
|
72
|
+
raise CliCommandInnerException(f"Failed to delete: {str(e)}")
|
|
73
|
+
|
|
74
|
+
asyncio.run(run_delete())
|
|
75
|
+
fmt.success(f"Successfully deleted {operation}")
|
|
76
|
+
|
|
77
|
+
except Exception as e:
|
|
78
|
+
if isinstance(e, CliCommandInnerException):
|
|
79
|
+
raise CliCommandException(str(e), error_code=1)
|
|
80
|
+
raise CliCommandException(f"Error deleting data: {str(e)}", error_code=1)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
import json
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from cognee.cli.reference import SupportsCliCommand
|
|
7
|
+
from cognee.cli import DEFAULT_DOCS_URL
|
|
8
|
+
from cognee.cli.config import SEARCH_TYPE_CHOICES, OUTPUT_FORMAT_CHOICES
|
|
9
|
+
import cognee.cli.echo as fmt
|
|
10
|
+
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SearchCommand(SupportsCliCommand):
|
|
14
|
+
command_string = "search"
|
|
15
|
+
help_string = "Search and query the knowledge graph for insights, information, and connections"
|
|
16
|
+
docs_url = DEFAULT_DOCS_URL
|
|
17
|
+
description = """
|
|
18
|
+
Search and query the knowledge graph for insights, information, and connections.
|
|
19
|
+
|
|
20
|
+
This is the final step in the Cognee workflow that retrieves information from the
|
|
21
|
+
processed knowledge graph. It supports multiple search modes optimized for different
|
|
22
|
+
use cases - from simple fact retrieval to complex reasoning and code analysis.
|
|
23
|
+
|
|
24
|
+
Search Types & Use Cases:
|
|
25
|
+
|
|
26
|
+
**GRAPH_COMPLETION** (Default - Recommended):
|
|
27
|
+
Natural language Q&A using full graph context and LLM reasoning.
|
|
28
|
+
Best for: Complex questions, analysis, summaries, insights.
|
|
29
|
+
|
|
30
|
+
**RAG_COMPLETION**:
|
|
31
|
+
Traditional RAG using document chunks without graph structure.
|
|
32
|
+
Best for: Direct document retrieval, specific fact-finding.
|
|
33
|
+
|
|
34
|
+
**INSIGHTS**:
|
|
35
|
+
Structured entity relationships and semantic connections.
|
|
36
|
+
Best for: Understanding concept relationships, knowledge mapping.
|
|
37
|
+
|
|
38
|
+
**CHUNKS**:
|
|
39
|
+
Raw text segments that match the query semantically.
|
|
40
|
+
Best for: Finding specific passages, citations, exact content.
|
|
41
|
+
|
|
42
|
+
**SUMMARIES**:
|
|
43
|
+
Pre-generated hierarchical summaries of content.
|
|
44
|
+
Best for: Quick overviews, document abstracts, topic summaries.
|
|
45
|
+
|
|
46
|
+
**CODE**:
|
|
47
|
+
Code-specific search with syntax and semantic understanding.
|
|
48
|
+
Best for: Finding functions, classes, implementation patterns.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
52
|
+
parser.add_argument("query_text", help="Your question or search query in natural language")
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"--query-type",
|
|
55
|
+
"-t",
|
|
56
|
+
choices=SEARCH_TYPE_CHOICES,
|
|
57
|
+
default="GRAPH_COMPLETION",
|
|
58
|
+
help="Search mode (default: GRAPH_COMPLETION for conversational AI responses)",
|
|
59
|
+
)
|
|
60
|
+
parser.add_argument(
|
|
61
|
+
"--datasets",
|
|
62
|
+
"-d",
|
|
63
|
+
nargs="*",
|
|
64
|
+
help="Dataset name(s) to search within. Searches all accessible datasets if not specified",
|
|
65
|
+
)
|
|
66
|
+
parser.add_argument(
|
|
67
|
+
"--top-k",
|
|
68
|
+
"-k",
|
|
69
|
+
type=int,
|
|
70
|
+
default=10,
|
|
71
|
+
help="Maximum number of results to return (default: 10, max: 100)",
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--system-prompt",
|
|
75
|
+
help="Custom system prompt file for LLM-based search types (default: answer_simple_question.txt)",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument(
|
|
78
|
+
"--output-format",
|
|
79
|
+
"-f",
|
|
80
|
+
choices=OUTPUT_FORMAT_CHOICES,
|
|
81
|
+
default="pretty",
|
|
82
|
+
help="Output format (default: pretty)",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
86
|
+
try:
|
|
87
|
+
# Import cognee here to avoid circular imports
|
|
88
|
+
import cognee
|
|
89
|
+
from cognee.modules.search.types import SearchType
|
|
90
|
+
|
|
91
|
+
# Convert string to SearchType enum
|
|
92
|
+
query_type = SearchType[args.query_type]
|
|
93
|
+
|
|
94
|
+
datasets_msg = (
|
|
95
|
+
f" in datasets {args.datasets}" if args.datasets else " across all datasets"
|
|
96
|
+
)
|
|
97
|
+
fmt.echo(f"Searching for: '{args.query_text}' (type: {args.query_type}){datasets_msg}")
|
|
98
|
+
|
|
99
|
+
# Run the async search function
|
|
100
|
+
async def run_search():
|
|
101
|
+
try:
|
|
102
|
+
results = await cognee.search(
|
|
103
|
+
query_text=args.query_text,
|
|
104
|
+
query_type=query_type,
|
|
105
|
+
datasets=args.datasets,
|
|
106
|
+
system_prompt_path=args.system_prompt or "answer_simple_question.txt",
|
|
107
|
+
top_k=args.top_k,
|
|
108
|
+
)
|
|
109
|
+
return results
|
|
110
|
+
except Exception as e:
|
|
111
|
+
raise CliCommandInnerException(f"Failed to search: {str(e)}")
|
|
112
|
+
|
|
113
|
+
results = asyncio.run(run_search())
|
|
114
|
+
|
|
115
|
+
# Format and display results
|
|
116
|
+
if args.output_format == "json":
|
|
117
|
+
fmt.echo(json.dumps(results, indent=2, default=str))
|
|
118
|
+
elif args.output_format == "simple":
|
|
119
|
+
for i, result in enumerate(results, 1):
|
|
120
|
+
fmt.echo(f"{i}. {result}")
|
|
121
|
+
else: # pretty format
|
|
122
|
+
if not results:
|
|
123
|
+
fmt.warning("No results found for your query.")
|
|
124
|
+
return
|
|
125
|
+
|
|
126
|
+
fmt.echo(f"\nFound {len(results)} result(s) using {args.query_type}:")
|
|
127
|
+
fmt.echo("=" * 60)
|
|
128
|
+
|
|
129
|
+
if args.query_type in ["GRAPH_COMPLETION", "RAG_COMPLETION"]:
|
|
130
|
+
# These return conversational responses
|
|
131
|
+
for i, result in enumerate(results, 1):
|
|
132
|
+
fmt.echo(f"{fmt.bold('Response:')} {result}")
|
|
133
|
+
if i < len(results):
|
|
134
|
+
fmt.echo("-" * 40)
|
|
135
|
+
elif args.query_type == "CHUNKS":
|
|
136
|
+
# These return text chunks
|
|
137
|
+
for i, result in enumerate(results, 1):
|
|
138
|
+
fmt.echo(f"{fmt.bold(f'Chunk {i}:')} {result}")
|
|
139
|
+
fmt.echo()
|
|
140
|
+
else:
|
|
141
|
+
# Generic formatting for other types
|
|
142
|
+
for i, result in enumerate(results, 1):
|
|
143
|
+
fmt.echo(f"{fmt.bold(f'Result {i}:')} {result}")
|
|
144
|
+
fmt.echo()
|
|
145
|
+
|
|
146
|
+
except Exception as e:
|
|
147
|
+
if isinstance(e, CliCommandInnerException):
|
|
148
|
+
raise CliCommandException(str(e), error_code=1)
|
|
149
|
+
raise CliCommandException(f"Error searching: {str(e)}", error_code=1)
|
cognee/cli/config.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI configuration and constants to avoid hardcoded values
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# CLI Constants
|
|
6
|
+
CLI_DESCRIPTION = "Cognee CLI - Manage your knowledge graphs and cognitive processing pipelines."
|
|
7
|
+
DEFAULT_DOCS_URL = "https://docs.cognee.ai"
|
|
8
|
+
|
|
9
|
+
# Command descriptions - these should match the actual command implementations
|
|
10
|
+
COMMAND_DESCRIPTIONS = {
|
|
11
|
+
"add": "Add data to Cognee for knowledge graph processing",
|
|
12
|
+
"search": "Search and query the knowledge graph for insights, information, and connections",
|
|
13
|
+
"cognify": "Transform ingested data into a structured knowledge graph",
|
|
14
|
+
"delete": "Delete data from cognee knowledge base",
|
|
15
|
+
"config": "Manage cognee configuration settings",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# Search type choices
|
|
19
|
+
SEARCH_TYPE_CHOICES = [
|
|
20
|
+
"GRAPH_COMPLETION",
|
|
21
|
+
"RAG_COMPLETION",
|
|
22
|
+
"INSIGHTS",
|
|
23
|
+
"CHUNKS",
|
|
24
|
+
"SUMMARIES",
|
|
25
|
+
"CODE",
|
|
26
|
+
"CYPHER",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
# Chunker choices
|
|
30
|
+
CHUNKER_CHOICES = ["TextChunker", "LangchainChunker"]
|
|
31
|
+
|
|
32
|
+
# Output format choices
|
|
33
|
+
OUTPUT_FORMAT_CHOICES = ["json", "pretty", "simple"]
|
cognee/cli/debug.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Provides a global debug setting for the CLI - following dlt patterns"""
|
|
2
|
+
|
|
3
|
+
_DEBUG_FLAG = False
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def enable_debug() -> None:
|
|
7
|
+
"""Enable debug mode for CLI"""
|
|
8
|
+
global _DEBUG_FLAG
|
|
9
|
+
_DEBUG_FLAG = True
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def disable_debug() -> None:
|
|
13
|
+
"""Disable debug mode for CLI"""
|
|
14
|
+
global _DEBUG_FLAG
|
|
15
|
+
_DEBUG_FLAG = False
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def is_debug_enabled() -> bool:
|
|
19
|
+
"""Check if debug mode is enabled"""
|
|
20
|
+
global _DEBUG_FLAG
|
|
21
|
+
return _DEBUG_FLAG
|
cognee/cli/echo.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""CLI output formatting utilities"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import click
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def echo(message: str = "", color: str = None, err: bool = False) -> None:
|
|
9
|
+
"""Echo a message to stdout or stderr with optional color"""
|
|
10
|
+
click.secho(message, fg=color, err=err)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def note(message: str) -> None:
|
|
14
|
+
"""Print a note in blue"""
|
|
15
|
+
echo(f"Note: {message}", color="blue")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def warning(message: str) -> None:
|
|
19
|
+
"""Print a warning in yellow"""
|
|
20
|
+
echo(f"Warning: {message}", color="yellow")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def error(message: str) -> None:
|
|
24
|
+
"""Print an error in red"""
|
|
25
|
+
echo(f"Error: {message}", color="red", err=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def success(message: str) -> None:
|
|
29
|
+
"""Print a success message in green"""
|
|
30
|
+
echo(f"Success: {message}", color="green")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def bold(text: str) -> str:
|
|
34
|
+
"""Make text bold"""
|
|
35
|
+
return click.style(text, bold=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def confirm(message: str, default: bool = False) -> bool:
|
|
39
|
+
"""Ask for user confirmation"""
|
|
40
|
+
return click.confirm(message, default=default)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def prompt(message: str, default: Any = None) -> str:
|
|
44
|
+
"""Prompt user for input"""
|
|
45
|
+
return click.prompt(message, default=default)
|
cognee/cli/exceptions.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CliCommandException(Exception):
|
|
5
|
+
"""Exception raised by CLI commands with additional context"""
|
|
6
|
+
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
message: str,
|
|
10
|
+
error_code: int = -1,
|
|
11
|
+
docs_url: Optional[str] = None,
|
|
12
|
+
raiseable_exception: Optional[Exception] = None,
|
|
13
|
+
) -> None:
|
|
14
|
+
super().__init__(message)
|
|
15
|
+
self.error_code = error_code
|
|
16
|
+
self.docs_url = docs_url
|
|
17
|
+
self.raiseable_exception = raiseable_exception
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CliCommandInnerException(Exception):
|
|
21
|
+
"""Inner exception for wrapping other exceptions in CLI context"""
|
|
22
|
+
|
|
23
|
+
pass
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Minimal CLI entry point for cognee that avoids early initialization
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
from typing import Any, Sequence
|
|
9
|
+
|
|
10
|
+
# CRITICAL: Prevent verbose logging initialization for CLI-only usage
|
|
11
|
+
# This must be set before any cognee imports to be effective
|
|
12
|
+
os.environ["COGNEE_MINIMAL_LOGGING"] = "true"
|
|
13
|
+
os.environ["COGNEE_CLI_MODE"] = "true"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_version() -> str:
|
|
17
|
+
"""Get cognee version without importing the main package"""
|
|
18
|
+
try:
|
|
19
|
+
# Try to get version from pyproject.toml first (for development)
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
|
|
23
|
+
if pyproject_path.exists():
|
|
24
|
+
with open(pyproject_path, encoding="utf-8") as f:
|
|
25
|
+
for line in f:
|
|
26
|
+
if line.startswith("version"):
|
|
27
|
+
version = line.split("=")[1].strip("'\"\n ")
|
|
28
|
+
return f"{version}-local"
|
|
29
|
+
|
|
30
|
+
# Fallback to installed package version
|
|
31
|
+
import importlib.metadata
|
|
32
|
+
|
|
33
|
+
return importlib.metadata.version("cognee")
|
|
34
|
+
except Exception:
|
|
35
|
+
return "unknown"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_command_info() -> dict:
|
|
39
|
+
"""Get command information without importing cognee"""
|
|
40
|
+
return {
|
|
41
|
+
"add": "Add data to Cognee for knowledge graph processing",
|
|
42
|
+
"search": "Search and query the knowledge graph for insights, information, and connections",
|
|
43
|
+
"cognify": "Transform ingested data into a structured knowledge graph",
|
|
44
|
+
"delete": "Delete data from cognee knowledge base",
|
|
45
|
+
"config": "Manage cognee configuration settings",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def print_help() -> None:
|
|
50
|
+
"""Print help message with dynamic command descriptions"""
|
|
51
|
+
commands = get_command_info()
|
|
52
|
+
command_list = "\n".join(f" {cmd:<12} {desc}" for cmd, desc in commands.items())
|
|
53
|
+
|
|
54
|
+
print(f"""
|
|
55
|
+
usage: cognee [-h] [--version] [--debug] {{{"|".join(commands.keys())}}} ...
|
|
56
|
+
|
|
57
|
+
Cognee CLI - Manage your knowledge graphs and cognitive processing pipelines.
|
|
58
|
+
|
|
59
|
+
options:
|
|
60
|
+
-h, --help show this help message and exit
|
|
61
|
+
--version show program's version number and exit
|
|
62
|
+
--debug Enable debug mode to show full stack traces on exceptions
|
|
63
|
+
|
|
64
|
+
Available commands:
|
|
65
|
+
{{{",".join(commands.keys())}}}
|
|
66
|
+
{command_list}
|
|
67
|
+
|
|
68
|
+
For more information on each command, use: cognee <command> --help
|
|
69
|
+
""")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main() -> int:
|
|
73
|
+
"""Minimal CLI main function"""
|
|
74
|
+
# Handle help and version without any imports - purely static
|
|
75
|
+
if len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] in ["-h", "--help"]):
|
|
76
|
+
print_help()
|
|
77
|
+
return 0
|
|
78
|
+
|
|
79
|
+
if len(sys.argv) == 2 and sys.argv[1] == "--version":
|
|
80
|
+
print(f"cognee {get_version()}")
|
|
81
|
+
return 0
|
|
82
|
+
|
|
83
|
+
# For actual commands, import the full CLI with minimal logging
|
|
84
|
+
try:
|
|
85
|
+
from cognee.cli._cognee import main as full_main
|
|
86
|
+
|
|
87
|
+
return full_main()
|
|
88
|
+
except Exception as e:
|
|
89
|
+
if "--debug" in sys.argv:
|
|
90
|
+
raise
|
|
91
|
+
print(f"Error: {e}")
|
|
92
|
+
print("Use --debug for full stack trace")
|
|
93
|
+
return 1
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
sys.exit(main())
|
cognee/cli/reference.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Protocol, Optional
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SupportsCliCommand(Protocol):
|
|
7
|
+
"""Protocol for defining one cognee cli command"""
|
|
8
|
+
|
|
9
|
+
command_string: str
|
|
10
|
+
"""name of the command"""
|
|
11
|
+
help_string: str
|
|
12
|
+
"""the help string for argparse"""
|
|
13
|
+
description: Optional[str]
|
|
14
|
+
"""the more detailed description for argparse, may include markdown for the docs"""
|
|
15
|
+
docs_url: Optional[str]
|
|
16
|
+
"""the default docs url to be printed in case of an exception"""
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
20
|
+
"""Configures the parser for the given argument"""
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
25
|
+
"""Executes the command with the given arguments"""
|
|
26
|
+
...
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module to suppress verbose logging before any cognee imports.
|
|
3
|
+
This must be imported before any other cognee modules.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
# Set CLI mode to suppress verbose logging
|
|
9
|
+
os.environ["COGNEE_CLI_MODE"] = "true"
|
|
10
|
+
|
|
11
|
+
# Also set log level to ERROR for extra safety
|
|
12
|
+
os.environ["LOG_LEVEL"] = "ERROR"
|
|
@@ -5,7 +5,7 @@ from typing import Optional, Tuple, List, Dict, Union, Any, Callable, Awaitable
|
|
|
5
5
|
from cognee.eval_framework.benchmark_adapters.benchmark_adapters import BenchmarkAdapter
|
|
6
6
|
from cognee.modules.chunking.TextChunker import TextChunker
|
|
7
7
|
from cognee.modules.pipelines.tasks.task import Task
|
|
8
|
-
from cognee.modules.pipelines import
|
|
8
|
+
from cognee.modules.pipelines import run_pipeline
|
|
9
9
|
|
|
10
10
|
logger = get_logger(level=ERROR)
|
|
11
11
|
|
|
@@ -61,7 +61,7 @@ class CorpusBuilderExecutor:
|
|
|
61
61
|
await cognee.add(self.raw_corpus)
|
|
62
62
|
|
|
63
63
|
tasks = await self.task_getter(chunk_size=chunk_size, chunker=chunker)
|
|
64
|
-
pipeline_run =
|
|
64
|
+
pipeline_run = run_pipeline(tasks=tasks)
|
|
65
65
|
|
|
66
66
|
async for run_info in pipeline_run:
|
|
67
67
|
print(run_info)
|
|
@@ -6,6 +6,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
6
6
|
import pydantic
|
|
7
7
|
from pydantic import Field
|
|
8
8
|
from cognee.base_config import get_base_config
|
|
9
|
+
from cognee.root_dir import ensure_absolute_path
|
|
9
10
|
from cognee.shared.data_models import KnowledgeGraph
|
|
10
11
|
|
|
11
12
|
|
|
@@ -51,15 +52,20 @@ class GraphConfig(BaseSettings):
|
|
|
51
52
|
@pydantic.model_validator(mode="after")
|
|
52
53
|
def fill_derived(cls, values):
|
|
53
54
|
provider = values.graph_database_provider.lower()
|
|
55
|
+
base_config = get_base_config()
|
|
54
56
|
|
|
55
57
|
# Set default filename if no filename is provided
|
|
56
58
|
if not values.graph_filename:
|
|
57
59
|
values.graph_filename = f"cognee_graph_{provider}"
|
|
58
60
|
|
|
59
|
-
#
|
|
60
|
-
if
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
# Handle graph file path
|
|
62
|
+
if values.graph_file_path:
|
|
63
|
+
# Check if absolute path is provided
|
|
64
|
+
values.graph_file_path = ensure_absolute_path(
|
|
65
|
+
os.path.join(values.graph_file_path, values.graph_filename)
|
|
66
|
+
)
|
|
67
|
+
else:
|
|
68
|
+
# Default path
|
|
63
69
|
databases_directory_path = os.path.join(base_config.system_root_directory, "databases")
|
|
64
70
|
values.graph_file_path = os.path.join(databases_directory_path, values.graph_filename)
|
|
65
71
|
|
|
@@ -21,10 +21,6 @@ async def get_graph_engine() -> GraphDBInterface:
|
|
|
21
21
|
if hasattr(graph_client, "initialize"):
|
|
22
22
|
await graph_client.initialize()
|
|
23
23
|
|
|
24
|
-
# Handle loading of graph for NetworkX
|
|
25
|
-
if config["graph_database_provider"].lower() == "networkx" and graph_client.graph is None:
|
|
26
|
-
await graph_client.load_graph_from_file()
|
|
27
|
-
|
|
28
24
|
return graph_client
|
|
29
25
|
|
|
30
26
|
|
|
@@ -181,8 +177,7 @@ def create_graph_engine(
|
|
|
181
177
|
graph_id=graph_identifier,
|
|
182
178
|
)
|
|
183
179
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return graph_client
|
|
180
|
+
raise EnvironmentError(
|
|
181
|
+
f"Unsupported graph database provider: {graph_database_provider}. "
|
|
182
|
+
f"Supported providers are: {', '.join(list(supported_databases.keys()) + ['neo4j', 'falkordb', 'kuzu', 'kuzu-remote', 'memgraph', 'neptune', 'neptune_analytics'])}"
|
|
183
|
+
)
|