cognee 0.2.3.dev1__py3-none-any.whl → 0.3.0__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/__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/ui/__init__.py +1 -0
- cognee/api/v1/ui/ui.py +529 -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 +273 -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.dist-info}/METADATA +13 -9
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dist-info}/RECORD +247 -135
- cognee-0.3.0.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.dist-info}/WHEEL +0 -0
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dist-info}/licenses/NOTICE.md +0 -0
cognee/cli/_cognee.py
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import argparse
|
|
4
|
+
import signal
|
|
5
|
+
import subprocess
|
|
6
|
+
from typing import Any, Sequence, Dict, Type, cast, List
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import rich_argparse
|
|
11
|
+
from rich.markdown import Markdown
|
|
12
|
+
|
|
13
|
+
HAS_RICH = True
|
|
14
|
+
except ImportError:
|
|
15
|
+
HAS_RICH = False
|
|
16
|
+
|
|
17
|
+
from cognee.cli import SupportsCliCommand, DEFAULT_DOCS_URL
|
|
18
|
+
from cognee.cli.config import CLI_DESCRIPTION
|
|
19
|
+
from cognee.cli import debug
|
|
20
|
+
import cognee.cli.echo as fmt
|
|
21
|
+
from cognee.cli.exceptions import CliCommandException
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
ACTION_EXECUTED = False
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def print_help(parser: argparse.ArgumentParser) -> None:
|
|
28
|
+
if not ACTION_EXECUTED:
|
|
29
|
+
parser.print_help()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DebugAction(argparse.Action):
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
option_strings: Sequence[str],
|
|
36
|
+
dest: Any = argparse.SUPPRESS,
|
|
37
|
+
default: Any = argparse.SUPPRESS,
|
|
38
|
+
help: str = None,
|
|
39
|
+
) -> None:
|
|
40
|
+
super(DebugAction, self).__init__(
|
|
41
|
+
option_strings=option_strings, dest=dest, default=default, nargs=0, help=help
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def __call__(
|
|
45
|
+
self,
|
|
46
|
+
parser: argparse.ArgumentParser,
|
|
47
|
+
namespace: argparse.Namespace,
|
|
48
|
+
values: Any,
|
|
49
|
+
option_string: str = None,
|
|
50
|
+
) -> None:
|
|
51
|
+
# Enable debug mode for stack traces
|
|
52
|
+
debug.enable_debug()
|
|
53
|
+
fmt.note("Debug mode enabled. Full stack traces will be shown.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class UiAction(argparse.Action):
|
|
57
|
+
def __init__(
|
|
58
|
+
self,
|
|
59
|
+
option_strings: Sequence[str],
|
|
60
|
+
dest: Any = argparse.SUPPRESS,
|
|
61
|
+
default: Any = argparse.SUPPRESS,
|
|
62
|
+
help: str = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
super(UiAction, self).__init__(
|
|
65
|
+
option_strings=option_strings, dest=dest, default=default, nargs=0, help=help
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def __call__(
|
|
69
|
+
self,
|
|
70
|
+
parser: argparse.ArgumentParser,
|
|
71
|
+
namespace: argparse.Namespace,
|
|
72
|
+
values: Any,
|
|
73
|
+
option_string: str = None,
|
|
74
|
+
) -> None:
|
|
75
|
+
# Set a flag to indicate UI should be started
|
|
76
|
+
global ACTION_EXECUTED
|
|
77
|
+
ACTION_EXECUTED = True
|
|
78
|
+
namespace.start_ui = True
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Debug functionality is now in cognee.cli.debug module
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _discover_commands() -> List[Type[SupportsCliCommand]]:
|
|
85
|
+
"""Discover all available CLI commands"""
|
|
86
|
+
# Import commands dynamically to avoid early cognee initialization
|
|
87
|
+
commands = []
|
|
88
|
+
|
|
89
|
+
command_modules = [
|
|
90
|
+
("cognee.cli.commands.add_command", "AddCommand"),
|
|
91
|
+
("cognee.cli.commands.search_command", "SearchCommand"),
|
|
92
|
+
("cognee.cli.commands.cognify_command", "CognifyCommand"),
|
|
93
|
+
("cognee.cli.commands.delete_command", "DeleteCommand"),
|
|
94
|
+
("cognee.cli.commands.config_command", "ConfigCommand"),
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
for module_path, class_name in command_modules:
|
|
98
|
+
try:
|
|
99
|
+
module = __import__(module_path, fromlist=[class_name])
|
|
100
|
+
command_class = getattr(module, class_name)
|
|
101
|
+
commands.append(command_class)
|
|
102
|
+
except (ImportError, AttributeError) as e:
|
|
103
|
+
fmt.warning(f"Failed to load command {class_name}: {e}")
|
|
104
|
+
|
|
105
|
+
return commands
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _create_parser() -> tuple[argparse.ArgumentParser, Dict[str, SupportsCliCommand]]:
|
|
109
|
+
parser = argparse.ArgumentParser(
|
|
110
|
+
description=f"{CLI_DESCRIPTION} Further help is available at {DEFAULT_DOCS_URL}."
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Get version dynamically
|
|
114
|
+
try:
|
|
115
|
+
from cognee.version import get_cognee_version
|
|
116
|
+
|
|
117
|
+
version = get_cognee_version()
|
|
118
|
+
except ImportError:
|
|
119
|
+
version = "unknown"
|
|
120
|
+
|
|
121
|
+
parser.add_argument("--version", action="version", version=f"cognee {version}")
|
|
122
|
+
parser.add_argument(
|
|
123
|
+
"--debug",
|
|
124
|
+
action=DebugAction,
|
|
125
|
+
help="Enable debug mode to show full stack traces on exceptions",
|
|
126
|
+
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"-ui",
|
|
129
|
+
action=UiAction,
|
|
130
|
+
help="Start the cognee web UI interface",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
subparsers = parser.add_subparsers(title="Available commands", dest="command")
|
|
134
|
+
|
|
135
|
+
# Discover and install commands
|
|
136
|
+
command_classes = _discover_commands()
|
|
137
|
+
installed_commands: Dict[str, SupportsCliCommand] = {}
|
|
138
|
+
|
|
139
|
+
for command_class in command_classes:
|
|
140
|
+
command = command_class()
|
|
141
|
+
if command.command_string in installed_commands:
|
|
142
|
+
continue
|
|
143
|
+
|
|
144
|
+
command_parser = subparsers.add_parser(
|
|
145
|
+
command.command_string,
|
|
146
|
+
help=command.help_string,
|
|
147
|
+
description=command.description if hasattr(command, "description") else None,
|
|
148
|
+
)
|
|
149
|
+
command.configure_parser(command_parser)
|
|
150
|
+
installed_commands[command.command_string] = command
|
|
151
|
+
|
|
152
|
+
# Add rich formatting if available
|
|
153
|
+
if HAS_RICH:
|
|
154
|
+
|
|
155
|
+
def add_formatter_class(parser: argparse.ArgumentParser) -> None:
|
|
156
|
+
parser.formatter_class = rich_argparse.RichHelpFormatter
|
|
157
|
+
|
|
158
|
+
if parser.description:
|
|
159
|
+
parser.description = Markdown(parser.description, style="argparse.text")
|
|
160
|
+
for action in parser._actions:
|
|
161
|
+
if isinstance(action, argparse._SubParsersAction):
|
|
162
|
+
for _subcmd, subparser in action.choices.items():
|
|
163
|
+
add_formatter_class(subparser)
|
|
164
|
+
|
|
165
|
+
add_formatter_class(parser)
|
|
166
|
+
|
|
167
|
+
return parser, installed_commands
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def main() -> int:
|
|
171
|
+
"""Main CLI entry point"""
|
|
172
|
+
parser, installed_commands = _create_parser()
|
|
173
|
+
args = parser.parse_args()
|
|
174
|
+
|
|
175
|
+
# Handle UI flag
|
|
176
|
+
if hasattr(args, "start_ui") and args.start_ui:
|
|
177
|
+
server_process = None
|
|
178
|
+
|
|
179
|
+
def signal_handler(signum, frame):
|
|
180
|
+
"""Handle Ctrl+C and other termination signals"""
|
|
181
|
+
nonlocal server_process
|
|
182
|
+
fmt.echo("\nShutting down UI server...")
|
|
183
|
+
if server_process:
|
|
184
|
+
try:
|
|
185
|
+
# Try graceful termination first
|
|
186
|
+
server_process.terminate()
|
|
187
|
+
try:
|
|
188
|
+
server_process.wait(timeout=5)
|
|
189
|
+
fmt.success("UI server stopped gracefully.")
|
|
190
|
+
except subprocess.TimeoutExpired:
|
|
191
|
+
# If graceful termination fails, force kill
|
|
192
|
+
fmt.echo("Force stopping UI server...")
|
|
193
|
+
server_process.kill()
|
|
194
|
+
server_process.wait()
|
|
195
|
+
fmt.success("UI server stopped.")
|
|
196
|
+
except Exception as e:
|
|
197
|
+
fmt.warning(f"Error stopping server: {e}")
|
|
198
|
+
sys.exit(0)
|
|
199
|
+
|
|
200
|
+
# Set up signal handlers
|
|
201
|
+
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
|
202
|
+
signal.signal(signal.SIGTERM, signal_handler) # Termination request
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
from cognee import start_ui
|
|
206
|
+
|
|
207
|
+
fmt.echo("Starting cognee UI...")
|
|
208
|
+
server_process = start_ui(host="localhost", port=3001, open_browser=True)
|
|
209
|
+
|
|
210
|
+
if server_process:
|
|
211
|
+
fmt.success("UI server started successfully!")
|
|
212
|
+
fmt.echo("The interface is available at: http://localhost:3001")
|
|
213
|
+
fmt.note("Press Ctrl+C to stop the server...")
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
# Keep the server running
|
|
217
|
+
import time
|
|
218
|
+
|
|
219
|
+
while server_process.poll() is None: # While process is still running
|
|
220
|
+
time.sleep(1)
|
|
221
|
+
except KeyboardInterrupt:
|
|
222
|
+
# This shouldn't happen now due to signal handler, but kept for safety
|
|
223
|
+
signal_handler(signal.SIGINT, None)
|
|
224
|
+
|
|
225
|
+
return 0
|
|
226
|
+
else:
|
|
227
|
+
fmt.error("Failed to start UI server. Check the logs above for details.")
|
|
228
|
+
return 1
|
|
229
|
+
|
|
230
|
+
except Exception as ex:
|
|
231
|
+
fmt.error(f"Error starting UI: {str(ex)}")
|
|
232
|
+
if debug.is_debug_enabled():
|
|
233
|
+
raise ex
|
|
234
|
+
return 1
|
|
235
|
+
|
|
236
|
+
if cmd := installed_commands.get(args.command):
|
|
237
|
+
try:
|
|
238
|
+
cmd.execute(args)
|
|
239
|
+
except Exception as ex:
|
|
240
|
+
docs_url = cmd.docs_url if hasattr(cmd, "docs_url") else DEFAULT_DOCS_URL
|
|
241
|
+
error_code = -1
|
|
242
|
+
raiseable_exception = ex
|
|
243
|
+
|
|
244
|
+
# Handle CLI-specific exceptions
|
|
245
|
+
if isinstance(ex, CliCommandException):
|
|
246
|
+
error_code = ex.error_code
|
|
247
|
+
docs_url = ex.docs_url or docs_url
|
|
248
|
+
raiseable_exception = ex.raiseable_exception
|
|
249
|
+
|
|
250
|
+
# Print exception
|
|
251
|
+
if raiseable_exception:
|
|
252
|
+
fmt.error(str(ex))
|
|
253
|
+
|
|
254
|
+
fmt.note(f"Please refer to our docs at '{docs_url}' for further assistance.")
|
|
255
|
+
|
|
256
|
+
if debug.is_debug_enabled() and raiseable_exception:
|
|
257
|
+
raise raiseable_exception
|
|
258
|
+
|
|
259
|
+
return error_code
|
|
260
|
+
else:
|
|
261
|
+
print_help(parser)
|
|
262
|
+
return -1
|
|
263
|
+
|
|
264
|
+
return 0
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _main() -> None:
|
|
268
|
+
"""Script entry point"""
|
|
269
|
+
sys.exit(main())
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
if __name__ == "__main__":
|
|
273
|
+
sys.exit(main())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# CLI Commands package
|
|
@@ -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 AddCommand(SupportsCliCommand):
|
|
12
|
+
command_string = "add"
|
|
13
|
+
help_string = "Add data to Cognee for knowledge graph processing"
|
|
14
|
+
docs_url = DEFAULT_DOCS_URL
|
|
15
|
+
description = """
|
|
16
|
+
Add data to Cognee for knowledge graph processing.
|
|
17
|
+
|
|
18
|
+
This is the first step in the Cognee workflow - it ingests raw data and prepares it
|
|
19
|
+
for processing. The function accepts various data formats including text, files, and
|
|
20
|
+
binary streams, then stores them in a specified dataset for further processing.
|
|
21
|
+
|
|
22
|
+
Supported Input Types:
|
|
23
|
+
- **Text strings**: Direct text content
|
|
24
|
+
- **File paths**: Local file paths (absolute paths starting with "/")
|
|
25
|
+
- **File URLs**: "file:///absolute/path" or "file://relative/path"
|
|
26
|
+
- **S3 paths**: "s3://bucket-name/path/to/file"
|
|
27
|
+
- **Lists**: Multiple files or text strings in a single call
|
|
28
|
+
|
|
29
|
+
Supported File Formats:
|
|
30
|
+
- Text files (.txt, .md, .csv)
|
|
31
|
+
- PDFs (.pdf)
|
|
32
|
+
- Images (.png, .jpg, .jpeg) - extracted via OCR/vision models
|
|
33
|
+
- Audio files (.mp3, .wav) - transcribed to text
|
|
34
|
+
- Code files (.py, .js, .ts, etc.) - parsed for structure and content
|
|
35
|
+
- Office documents (.docx, .pptx)
|
|
36
|
+
|
|
37
|
+
After adding data, use `cognee cognify` to process it into knowledge graphs.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
"data",
|
|
43
|
+
nargs="+",
|
|
44
|
+
help="Data to add: text content, file paths (/path/to/file), file URLs (file://path), S3 paths (s3://bucket/file), or mix of these",
|
|
45
|
+
)
|
|
46
|
+
parser.add_argument(
|
|
47
|
+
"--dataset-name",
|
|
48
|
+
"-d",
|
|
49
|
+
default="main_dataset",
|
|
50
|
+
help="Dataset name to organize your data (default: main_dataset)",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
54
|
+
try:
|
|
55
|
+
# Import cognee here to avoid circular imports
|
|
56
|
+
import cognee
|
|
57
|
+
|
|
58
|
+
fmt.echo(f"Adding {len(args.data)} item(s) to dataset '{args.dataset_name}'...")
|
|
59
|
+
|
|
60
|
+
# Run the async add function
|
|
61
|
+
async def run_add():
|
|
62
|
+
try:
|
|
63
|
+
# Pass all data items as a list to cognee.add if multiple items
|
|
64
|
+
if len(args.data) == 1:
|
|
65
|
+
data_to_add = args.data[0]
|
|
66
|
+
else:
|
|
67
|
+
data_to_add = args.data
|
|
68
|
+
|
|
69
|
+
fmt.echo("Processing data...")
|
|
70
|
+
await cognee.add(data=data_to_add, dataset_name=args.dataset_name)
|
|
71
|
+
fmt.success(f"Successfully added data to dataset '{args.dataset_name}'")
|
|
72
|
+
except Exception as e:
|
|
73
|
+
raise CliCommandInnerException(f"Failed to add data: {str(e)}")
|
|
74
|
+
|
|
75
|
+
asyncio.run(run_add())
|
|
76
|
+
|
|
77
|
+
except Exception as e:
|
|
78
|
+
if isinstance(e, CliCommandInnerException):
|
|
79
|
+
raise CliCommandException(str(e), error_code=1)
|
|
80
|
+
raise CliCommandException(f"Error adding data: {str(e)}", error_code=1)
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
from cognee.cli.config import CHUNKER_CHOICES
|
|
8
|
+
import cognee.cli.echo as fmt
|
|
9
|
+
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CognifyCommand(SupportsCliCommand):
|
|
13
|
+
command_string = "cognify"
|
|
14
|
+
help_string = "Transform ingested data into a structured knowledge graph"
|
|
15
|
+
docs_url = DEFAULT_DOCS_URL
|
|
16
|
+
description = """
|
|
17
|
+
Transform ingested data into a structured knowledge graph.
|
|
18
|
+
|
|
19
|
+
This is the core processing step in Cognee that converts raw text and documents
|
|
20
|
+
into an intelligent knowledge graph. It analyzes content, extracts entities and
|
|
21
|
+
relationships, and creates semantic connections for enhanced search and reasoning.
|
|
22
|
+
|
|
23
|
+
Processing Pipeline:
|
|
24
|
+
1. **Document Classification**: Identifies document types and structures
|
|
25
|
+
2. **Permission Validation**: Ensures user has processing rights
|
|
26
|
+
3. **Text Chunking**: Breaks content into semantically meaningful segments
|
|
27
|
+
4. **Entity Extraction**: Identifies key concepts, people, places, organizations
|
|
28
|
+
5. **Relationship Detection**: Discovers connections between entities
|
|
29
|
+
6. **Graph Construction**: Builds semantic knowledge graph with embeddings
|
|
30
|
+
7. **Content Summarization**: Creates hierarchical summaries for navigation
|
|
31
|
+
|
|
32
|
+
After successful cognify processing, use `cognee search` to query the knowledge graph.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def configure_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--datasets",
|
|
38
|
+
"-d",
|
|
39
|
+
nargs="*",
|
|
40
|
+
help="Dataset name(s) to process. Processes all available data if not specified. Can be multiple: --datasets dataset1 dataset2",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--chunk-size",
|
|
44
|
+
type=int,
|
|
45
|
+
help="Maximum tokens per chunk. Auto-calculated based on LLM if not specified (~512-8192 tokens)",
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--ontology-file", help="Path to RDF/OWL ontology file for domain-specific entity types"
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--chunker",
|
|
52
|
+
choices=CHUNKER_CHOICES,
|
|
53
|
+
default="TextChunker",
|
|
54
|
+
help="Text chunking strategy (default: TextChunker)",
|
|
55
|
+
)
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--background",
|
|
58
|
+
"-b",
|
|
59
|
+
action="store_true",
|
|
60
|
+
help="Run processing in background and return immediately (recommended for large datasets)",
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--verbose", "-v", action="store_true", help="Show detailed progress information"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def execute(self, args: argparse.Namespace) -> None:
|
|
67
|
+
try:
|
|
68
|
+
# Import cognee here to avoid circular imports
|
|
69
|
+
import cognee
|
|
70
|
+
|
|
71
|
+
# Prepare datasets parameter
|
|
72
|
+
datasets = args.datasets if args.datasets else None
|
|
73
|
+
dataset_msg = f" for datasets {datasets}" if datasets else " for all available data"
|
|
74
|
+
fmt.echo(f"Starting cognification{dataset_msg}...")
|
|
75
|
+
|
|
76
|
+
if args.verbose:
|
|
77
|
+
fmt.note("This process will analyze your data and build knowledge graphs.")
|
|
78
|
+
fmt.note("Depending on data size, this may take several minutes.")
|
|
79
|
+
if args.background:
|
|
80
|
+
fmt.note(
|
|
81
|
+
"Running in background mode - the process will continue after this command exits."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Prepare chunker parameter - will be handled in the async function
|
|
85
|
+
|
|
86
|
+
# Run the async cognify function
|
|
87
|
+
async def run_cognify():
|
|
88
|
+
try:
|
|
89
|
+
# Import chunker classes here
|
|
90
|
+
from cognee.modules.chunking.TextChunker import TextChunker
|
|
91
|
+
|
|
92
|
+
chunker_class = TextChunker # Default
|
|
93
|
+
if args.chunker == "LangchainChunker":
|
|
94
|
+
try:
|
|
95
|
+
from cognee.modules.chunking.LangchainChunker import LangchainChunker
|
|
96
|
+
|
|
97
|
+
chunker_class = LangchainChunker
|
|
98
|
+
except ImportError:
|
|
99
|
+
fmt.warning("LangchainChunker not available, using TextChunker")
|
|
100
|
+
|
|
101
|
+
result = await cognee.cognify(
|
|
102
|
+
datasets=datasets,
|
|
103
|
+
chunker=chunker_class,
|
|
104
|
+
chunk_size=args.chunk_size,
|
|
105
|
+
ontology_file_path=args.ontology_file,
|
|
106
|
+
run_in_background=args.background,
|
|
107
|
+
)
|
|
108
|
+
return result
|
|
109
|
+
except Exception as e:
|
|
110
|
+
raise CliCommandInnerException(f"Failed to cognify: {str(e)}")
|
|
111
|
+
|
|
112
|
+
result = asyncio.run(run_cognify())
|
|
113
|
+
|
|
114
|
+
if args.background:
|
|
115
|
+
fmt.success("Cognification started in background!")
|
|
116
|
+
if args.verbose and result:
|
|
117
|
+
fmt.echo(
|
|
118
|
+
"Background processing initiated. Use pipeline monitoring to track progress."
|
|
119
|
+
)
|
|
120
|
+
else:
|
|
121
|
+
fmt.success("Cognification completed successfully!")
|
|
122
|
+
if args.verbose and result:
|
|
123
|
+
fmt.echo(f"Processing results: {result}")
|
|
124
|
+
|
|
125
|
+
except Exception as e:
|
|
126
|
+
if isinstance(e, CliCommandInnerException):
|
|
127
|
+
raise CliCommandException(str(e), error_code=1)
|
|
128
|
+
raise CliCommandException(f"Error during cognification: {str(e)}", error_code=1)
|