cognee 0.2.3.dev0__py3-none-any.whl → 0.2.4__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.
Files changed (179) hide show
  1. cognee/__main__.py +4 -0
  2. cognee/api/v1/add/add.py +18 -11
  3. cognee/api/v1/cognify/code_graph_pipeline.py +7 -1
  4. cognee/api/v1/cognify/cognify.py +22 -115
  5. cognee/api/v1/cognify/routers/get_cognify_router.py +11 -3
  6. cognee/api/v1/config/config.py +5 -13
  7. cognee/api/v1/datasets/routers/get_datasets_router.py +2 -2
  8. cognee/api/v1/delete/delete.py +1 -1
  9. cognee/api/v1/exceptions/__init__.py +13 -0
  10. cognee/api/v1/{delete → exceptions}/exceptions.py +15 -12
  11. cognee/api/v1/responses/default_tools.py +4 -0
  12. cognee/api/v1/responses/dispatch_function.py +6 -1
  13. cognee/api/v1/responses/models.py +1 -1
  14. cognee/api/v1/search/search.py +6 -7
  15. cognee/cli/__init__.py +10 -0
  16. cognee/cli/_cognee.py +180 -0
  17. cognee/cli/commands/__init__.py +1 -0
  18. cognee/cli/commands/add_command.py +80 -0
  19. cognee/cli/commands/cognify_command.py +128 -0
  20. cognee/cli/commands/config_command.py +225 -0
  21. cognee/cli/commands/delete_command.py +80 -0
  22. cognee/cli/commands/search_command.py +149 -0
  23. cognee/cli/config.py +33 -0
  24. cognee/cli/debug.py +21 -0
  25. cognee/cli/echo.py +45 -0
  26. cognee/cli/exceptions.py +23 -0
  27. cognee/cli/minimal_cli.py +97 -0
  28. cognee/cli/reference.py +26 -0
  29. cognee/cli/suppress_logging.py +12 -0
  30. cognee/eval_framework/corpus_builder/corpus_builder_executor.py +2 -2
  31. cognee/eval_framework/eval_config.py +1 -1
  32. cognee/exceptions/__init__.py +5 -5
  33. cognee/exceptions/exceptions.py +37 -17
  34. cognee/infrastructure/data/exceptions/__init__.py +7 -0
  35. cognee/infrastructure/data/exceptions/exceptions.py +22 -0
  36. cognee/infrastructure/data/utils/extract_keywords.py +3 -3
  37. cognee/infrastructure/databases/exceptions/__init__.py +3 -0
  38. cognee/infrastructure/databases/exceptions/exceptions.py +57 -9
  39. cognee/infrastructure/databases/graph/get_graph_engine.py +4 -9
  40. cognee/infrastructure/databases/graph/kuzu/adapter.py +64 -2
  41. cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +49 -0
  42. cognee/infrastructure/databases/graph/neptune_driver/exceptions.py +15 -10
  43. cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py +2 -2
  44. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +4 -5
  45. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -2
  46. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +5 -3
  47. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +17 -8
  48. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +5 -5
  49. cognee/infrastructure/databases/vector/embeddings/config.py +2 -2
  50. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +6 -6
  51. cognee/infrastructure/databases/vector/exceptions/exceptions.py +3 -3
  52. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +2 -2
  53. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +4 -3
  54. cognee/infrastructure/files/utils/get_data_file_path.py +14 -9
  55. cognee/infrastructure/files/utils/get_file_metadata.py +2 -1
  56. cognee/infrastructure/llm/LLMGateway.py +14 -5
  57. cognee/infrastructure/llm/config.py +5 -5
  58. cognee/infrastructure/llm/exceptions.py +30 -2
  59. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +16 -5
  60. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_content_graph.py +19 -15
  61. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +5 -5
  62. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +6 -6
  63. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +2 -2
  64. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +24 -15
  65. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +6 -4
  66. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +9 -7
  67. cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +2 -2
  68. cognee/infrastructure/llm/tokenizer/HuggingFace/adapter.py +3 -3
  69. cognee/infrastructure/llm/tokenizer/Mistral/adapter.py +3 -3
  70. cognee/infrastructure/llm/tokenizer/TikToken/adapter.py +6 -6
  71. cognee/infrastructure/llm/utils.py +7 -7
  72. cognee/modules/data/exceptions/exceptions.py +18 -5
  73. cognee/modules/data/methods/__init__.py +2 -0
  74. cognee/modules/data/methods/create_authorized_dataset.py +19 -0
  75. cognee/modules/data/methods/delete_data.py +2 -4
  76. cognee/modules/data/methods/get_authorized_dataset.py +11 -5
  77. cognee/modules/data/methods/get_authorized_dataset_by_name.py +16 -0
  78. cognee/modules/data/methods/load_or_create_datasets.py +2 -20
  79. cognee/modules/data/processing/document_types/exceptions/exceptions.py +2 -2
  80. cognee/modules/graph/cognee_graph/CogneeGraph.py +6 -4
  81. cognee/modules/graph/cognee_graph/CogneeGraphElements.py +5 -10
  82. cognee/modules/graph/exceptions/__init__.py +2 -0
  83. cognee/modules/graph/exceptions/exceptions.py +25 -3
  84. cognee/modules/graph/methods/get_formatted_graph_data.py +3 -2
  85. cognee/modules/ingestion/exceptions/exceptions.py +2 -2
  86. cognee/modules/ontology/exceptions/exceptions.py +4 -4
  87. cognee/modules/pipelines/__init__.py +1 -1
  88. cognee/modules/pipelines/exceptions/exceptions.py +2 -2
  89. cognee/modules/pipelines/exceptions/tasks.py +18 -0
  90. cognee/modules/pipelines/layers/__init__.py +1 -0
  91. cognee/modules/pipelines/layers/check_pipeline_run_qualification.py +59 -0
  92. cognee/modules/pipelines/layers/pipeline_execution_mode.py +127 -0
  93. cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +12 -0
  94. cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +34 -0
  95. cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +55 -0
  96. cognee/modules/pipelines/layers/setup_and_check_environment.py +41 -0
  97. cognee/modules/pipelines/layers/validate_pipeline_tasks.py +20 -0
  98. cognee/modules/pipelines/methods/__init__.py +2 -0
  99. cognee/modules/pipelines/methods/get_pipeline_runs_by_dataset.py +34 -0
  100. cognee/modules/pipelines/methods/reset_pipeline_run_status.py +16 -0
  101. cognee/modules/pipelines/operations/__init__.py +0 -1
  102. cognee/modules/pipelines/operations/log_pipeline_run_initiated.py +1 -1
  103. cognee/modules/pipelines/operations/pipeline.py +23 -138
  104. cognee/modules/retrieval/base_feedback.py +11 -0
  105. cognee/modules/retrieval/cypher_search_retriever.py +1 -9
  106. cognee/modules/retrieval/exceptions/exceptions.py +12 -6
  107. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +9 -2
  108. cognee/modules/retrieval/graph_completion_cot_retriever.py +13 -6
  109. cognee/modules/retrieval/graph_completion_retriever.py +89 -5
  110. cognee/modules/retrieval/graph_summary_completion_retriever.py +2 -0
  111. cognee/modules/retrieval/natural_language_retriever.py +0 -4
  112. cognee/modules/retrieval/user_qa_feedback.py +83 -0
  113. cognee/modules/retrieval/utils/extract_uuid_from_node.py +18 -0
  114. cognee/modules/retrieval/utils/models.py +40 -0
  115. cognee/modules/search/exceptions/__init__.py +7 -0
  116. cognee/modules/search/exceptions/exceptions.py +15 -0
  117. cognee/modules/search/methods/search.py +47 -7
  118. cognee/modules/search/types/SearchType.py +1 -0
  119. cognee/modules/settings/get_settings.py +2 -2
  120. cognee/modules/users/exceptions/exceptions.py +6 -6
  121. cognee/shared/CodeGraphEntities.py +1 -0
  122. cognee/shared/exceptions/exceptions.py +2 -2
  123. cognee/shared/logging_utils.py +142 -31
  124. cognee/shared/utils.py +0 -1
  125. cognee/tasks/completion/exceptions/exceptions.py +3 -3
  126. cognee/tasks/documents/classify_documents.py +4 -0
  127. cognee/tasks/documents/exceptions/__init__.py +11 -0
  128. cognee/tasks/documents/exceptions/exceptions.py +36 -0
  129. cognee/tasks/documents/extract_chunks_from_documents.py +8 -2
  130. cognee/tasks/graph/exceptions/__init__.py +12 -0
  131. cognee/tasks/graph/exceptions/exceptions.py +41 -0
  132. cognee/tasks/graph/extract_graph_from_data.py +34 -2
  133. cognee/tasks/ingestion/exceptions/__init__.py +8 -0
  134. cognee/tasks/ingestion/exceptions/exceptions.py +12 -0
  135. cognee/tasks/ingestion/resolve_data_directories.py +5 -0
  136. cognee/tasks/repo_processor/get_local_dependencies.py +2 -0
  137. cognee/tasks/repo_processor/get_repo_file_dependencies.py +120 -48
  138. cognee/tasks/storage/add_data_points.py +41 -3
  139. cognee/tasks/storage/exceptions/__init__.py +9 -0
  140. cognee/tasks/storage/exceptions/exceptions.py +13 -0
  141. cognee/tasks/storage/index_data_points.py +1 -1
  142. cognee/tasks/summarization/exceptions/__init__.py +9 -0
  143. cognee/tasks/summarization/exceptions/exceptions.py +14 -0
  144. cognee/tasks/summarization/summarize_text.py +8 -1
  145. cognee/tests/integration/cli/__init__.py +3 -0
  146. cognee/tests/integration/cli/test_cli_integration.py +331 -0
  147. cognee/tests/integration/documents/PdfDocument_test.py +2 -2
  148. cognee/tests/integration/documents/TextDocument_test.py +2 -4
  149. cognee/tests/integration/documents/UnstructuredDocument_test.py +5 -8
  150. cognee/tests/test_delete_by_id.py +1 -1
  151. cognee/tests/{test_deletion.py → test_delete_hard.py} +0 -37
  152. cognee/tests/test_delete_soft.py +85 -0
  153. cognee/tests/test_kuzu.py +2 -2
  154. cognee/tests/test_neo4j.py +2 -2
  155. cognee/tests/test_search_db.py +126 -7
  156. cognee/tests/unit/cli/__init__.py +3 -0
  157. cognee/tests/unit/cli/test_cli_commands.py +483 -0
  158. cognee/tests/unit/cli/test_cli_edge_cases.py +625 -0
  159. cognee/tests/unit/cli/test_cli_main.py +173 -0
  160. cognee/tests/unit/cli/test_cli_runner.py +62 -0
  161. cognee/tests/unit/cli/test_cli_utils.py +127 -0
  162. cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +5 -5
  163. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +3 -3
  164. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +3 -3
  165. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +3 -3
  166. cognee/tests/unit/modules/search/search_methods_test.py +4 -2
  167. {cognee-0.2.3.dev0.dist-info → cognee-0.2.4.dist-info}/METADATA +7 -5
  168. {cognee-0.2.3.dev0.dist-info → cognee-0.2.4.dist-info}/RECORD +172 -121
  169. cognee-0.2.4.dist-info/entry_points.txt +2 -0
  170. cognee/infrastructure/databases/exceptions/EmbeddingException.py +0 -20
  171. cognee/infrastructure/databases/graph/networkx/__init__.py +0 -0
  172. cognee/infrastructure/databases/graph/networkx/adapter.py +0 -1017
  173. cognee/infrastructure/pipeline/models/Operation.py +0 -60
  174. cognee/infrastructure/pipeline/models/__init__.py +0 -0
  175. cognee/notebooks/github_analysis_step_by_step.ipynb +0 -37
  176. cognee/tests/tasks/descriptive_metrics/networkx_metrics_test.py +0 -7
  177. {cognee-0.2.3.dev0.dist-info → cognee-0.2.4.dist-info}/WHEEL +0 -0
  178. {cognee-0.2.3.dev0.dist-info → cognee-0.2.4.dist-info}/licenses/LICENSE +0 -0
  179. {cognee-0.2.3.dev0.dist-info → cognee-0.2.4.dist-info}/licenses/NOTICE.md +0 -0
cognee/cli/_cognee.py ADDED
@@ -0,0 +1,180 @@
1
+ import sys
2
+ import os
3
+ import argparse
4
+ from typing import Any, Sequence, Dict, Type, cast, List
5
+ import click
6
+
7
+ try:
8
+ import rich_argparse
9
+ from rich.markdown import Markdown
10
+
11
+ HAS_RICH = True
12
+ except ImportError:
13
+ HAS_RICH = False
14
+
15
+ from cognee.cli import SupportsCliCommand, DEFAULT_DOCS_URL
16
+ from cognee.cli.config import CLI_DESCRIPTION
17
+ from cognee.cli import debug
18
+ import cognee.cli.echo as fmt
19
+ from cognee.cli.exceptions import CliCommandException
20
+
21
+
22
+ ACTION_EXECUTED = False
23
+
24
+
25
+ def print_help(parser: argparse.ArgumentParser) -> None:
26
+ if not ACTION_EXECUTED:
27
+ parser.print_help()
28
+
29
+
30
+ class DebugAction(argparse.Action):
31
+ def __init__(
32
+ self,
33
+ option_strings: Sequence[str],
34
+ dest: Any = argparse.SUPPRESS,
35
+ default: Any = argparse.SUPPRESS,
36
+ help: str = None,
37
+ ) -> None:
38
+ super(DebugAction, self).__init__(
39
+ option_strings=option_strings, dest=dest, default=default, nargs=0, help=help
40
+ )
41
+
42
+ def __call__(
43
+ self,
44
+ parser: argparse.ArgumentParser,
45
+ namespace: argparse.Namespace,
46
+ values: Any,
47
+ option_string: str = None,
48
+ ) -> None:
49
+ # Enable debug mode for stack traces
50
+ debug.enable_debug()
51
+ fmt.note("Debug mode enabled. Full stack traces will be shown.")
52
+
53
+
54
+ # Debug functionality is now in cognee.cli.debug module
55
+
56
+
57
+ def _discover_commands() -> List[Type[SupportsCliCommand]]:
58
+ """Discover all available CLI commands"""
59
+ # Import commands dynamically to avoid early cognee initialization
60
+ commands = []
61
+
62
+ command_modules = [
63
+ ("cognee.cli.commands.add_command", "AddCommand"),
64
+ ("cognee.cli.commands.search_command", "SearchCommand"),
65
+ ("cognee.cli.commands.cognify_command", "CognifyCommand"),
66
+ ("cognee.cli.commands.delete_command", "DeleteCommand"),
67
+ ("cognee.cli.commands.config_command", "ConfigCommand"),
68
+ ]
69
+
70
+ for module_path, class_name in command_modules:
71
+ try:
72
+ module = __import__(module_path, fromlist=[class_name])
73
+ command_class = getattr(module, class_name)
74
+ commands.append(command_class)
75
+ except (ImportError, AttributeError) as e:
76
+ fmt.warning(f"Failed to load command {class_name}: {e}")
77
+
78
+ return commands
79
+
80
+
81
+ def _create_parser() -> tuple[argparse.ArgumentParser, Dict[str, SupportsCliCommand]]:
82
+ parser = argparse.ArgumentParser(
83
+ description=f"{CLI_DESCRIPTION} Further help is available at {DEFAULT_DOCS_URL}."
84
+ )
85
+
86
+ # Get version dynamically
87
+ try:
88
+ from cognee.version import get_cognee_version
89
+
90
+ version = get_cognee_version()
91
+ except ImportError:
92
+ version = "unknown"
93
+
94
+ parser.add_argument("--version", action="version", version=f"cognee {version}")
95
+ parser.add_argument(
96
+ "--debug",
97
+ action=DebugAction,
98
+ help="Enable debug mode to show full stack traces on exceptions",
99
+ )
100
+
101
+ subparsers = parser.add_subparsers(title="Available commands", dest="command")
102
+
103
+ # Discover and install commands
104
+ command_classes = _discover_commands()
105
+ installed_commands: Dict[str, SupportsCliCommand] = {}
106
+
107
+ for command_class in command_classes:
108
+ command = command_class()
109
+ if command.command_string in installed_commands:
110
+ continue
111
+
112
+ command_parser = subparsers.add_parser(
113
+ command.command_string,
114
+ help=command.help_string,
115
+ description=command.description if hasattr(command, "description") else None,
116
+ )
117
+ command.configure_parser(command_parser)
118
+ installed_commands[command.command_string] = command
119
+
120
+ # Add rich formatting if available
121
+ if HAS_RICH:
122
+
123
+ def add_formatter_class(parser: argparse.ArgumentParser) -> None:
124
+ parser.formatter_class = rich_argparse.RichHelpFormatter
125
+
126
+ if parser.description:
127
+ parser.description = Markdown(parser.description, style="argparse.text")
128
+ for action in parser._actions:
129
+ if isinstance(action, argparse._SubParsersAction):
130
+ for _subcmd, subparser in action.choices.items():
131
+ add_formatter_class(subparser)
132
+
133
+ add_formatter_class(parser)
134
+
135
+ return parser, installed_commands
136
+
137
+
138
+ def main() -> int:
139
+ """Main CLI entry point"""
140
+ parser, installed_commands = _create_parser()
141
+ args = parser.parse_args()
142
+
143
+ if cmd := installed_commands.get(args.command):
144
+ try:
145
+ cmd.execute(args)
146
+ except Exception as ex:
147
+ docs_url = cmd.docs_url if hasattr(cmd, "docs_url") else DEFAULT_DOCS_URL
148
+ error_code = -1
149
+ raiseable_exception = ex
150
+
151
+ # Handle CLI-specific exceptions
152
+ if isinstance(ex, CliCommandException):
153
+ error_code = ex.error_code
154
+ docs_url = ex.docs_url or docs_url
155
+ raiseable_exception = ex.raiseable_exception
156
+
157
+ # Print exception
158
+ if raiseable_exception:
159
+ fmt.error(str(ex))
160
+
161
+ fmt.note(f"Please refer to our docs at '{docs_url}' for further assistance.")
162
+
163
+ if debug.is_debug_enabled() and raiseable_exception:
164
+ raise raiseable_exception
165
+
166
+ return error_code
167
+ else:
168
+ print_help(parser)
169
+ return -1
170
+
171
+ return 0
172
+
173
+
174
+ def _main() -> None:
175
+ """Script entry point"""
176
+ sys.exit(main())
177
+
178
+
179
+ if __name__ == "__main__":
180
+ 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)
@@ -0,0 +1,225 @@
1
+ import argparse
2
+ import json
3
+ from typing import Optional, Any
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 ConfigCommand(SupportsCliCommand):
12
+ command_string = "config"
13
+ help_string = "Manage cognee configuration settings"
14
+ docs_url = DEFAULT_DOCS_URL
15
+ description = """
16
+ The `cognee config` command allows you to view and modify configuration settings.
17
+
18
+ You can:
19
+ - View all current configuration settings
20
+ - Get specific configuration values
21
+ - Set configuration values
22
+ - Unset (reset to default) specific configuration values
23
+ - Reset all configuration to defaults
24
+
25
+ Configuration changes will affect how cognee processes and stores data.
26
+ """
27
+
28
+ def configure_parser(self, parser: argparse.ArgumentParser) -> None:
29
+ subparsers = parser.add_subparsers(dest="config_action", help="Configuration actions")
30
+
31
+ # Get command
32
+ get_parser = subparsers.add_parser("get", help="Get configuration value(s)")
33
+ get_parser.add_argument(
34
+ "key", nargs="?", help="Configuration key to retrieve (shows all if not specified)"
35
+ )
36
+
37
+ # Set command
38
+ set_parser = subparsers.add_parser("set", help="Set configuration value")
39
+ set_parser.add_argument("key", help="Configuration key to set")
40
+ set_parser.add_argument("value", help="Configuration value to set")
41
+
42
+ # List command
43
+ subparsers.add_parser("list", help="List all configuration keys")
44
+
45
+ # Unset command
46
+ unset_parser = subparsers.add_parser("unset", help="Remove/unset a configuration value")
47
+ unset_parser.add_argument("key", help="Configuration key to unset")
48
+ unset_parser.add_argument(
49
+ "--force", "-f", action="store_true", help="Skip confirmation prompt"
50
+ )
51
+
52
+ # Reset command
53
+ reset_parser = subparsers.add_parser("reset", help="Reset configuration to defaults")
54
+ reset_parser.add_argument(
55
+ "--force", "-f", action="store_true", help="Skip confirmation prompt"
56
+ )
57
+
58
+ def execute(self, args: argparse.Namespace) -> None:
59
+ try:
60
+ # Import cognee here to avoid circular imports
61
+ import cognee
62
+
63
+ if not hasattr(args, "config_action") or args.config_action is None:
64
+ fmt.error("Please specify a config action: get, set, unset, list, or reset")
65
+ return
66
+
67
+ if args.config_action == "get":
68
+ self._handle_get(args)
69
+ elif args.config_action == "set":
70
+ self._handle_set(args)
71
+ elif args.config_action == "unset":
72
+ self._handle_unset(args)
73
+ elif args.config_action == "list":
74
+ self._handle_list(args)
75
+ elif args.config_action == "reset":
76
+ self._handle_reset(args)
77
+ else:
78
+ fmt.error(f"Unknown config action: {args.config_action}")
79
+
80
+ except Exception as e:
81
+ if isinstance(e, CliCommandInnerException):
82
+ raise CliCommandException(str(e), error_code=1)
83
+ raise CliCommandException(f"Error managing configuration: {str(e)}", error_code=1)
84
+
85
+ def _handle_get(self, args: argparse.Namespace) -> None:
86
+ try:
87
+ import cognee
88
+
89
+ if args.key:
90
+ # Get specific key
91
+ try:
92
+ if hasattr(cognee.config, "get"):
93
+ value = cognee.config.get(args.key)
94
+ fmt.echo(f"{args.key}: {value}")
95
+ else:
96
+ fmt.error("Configuration retrieval not implemented yet")
97
+ fmt.note(
98
+ "The config system currently only supports setting values, not retrieving them"
99
+ )
100
+ fmt.note(f"To set this value: 'cognee config set {args.key} <value>'")
101
+ except Exception:
102
+ fmt.error(f"Configuration key '{args.key}' not found or retrieval failed")
103
+ else:
104
+ # Get all configuration
105
+ try:
106
+ if hasattr(cognee.config, "get_all"):
107
+ config_dict = cognee.config.get_all()
108
+ if config_dict:
109
+ fmt.echo("Current configuration:")
110
+ for key, value in config_dict.items():
111
+ fmt.echo(f" {key}: {value}")
112
+ else:
113
+ fmt.echo("No configuration settings found")
114
+ else:
115
+ fmt.error("Configuration viewing not implemented yet")
116
+ fmt.note(
117
+ "The config system currently only supports setting values, not retrieving them"
118
+ )
119
+ fmt.note("Available commands: 'cognee config set <key> <value>'")
120
+ except Exception:
121
+ fmt.error("Failed to retrieve configuration")
122
+ fmt.note("Configuration viewing not fully implemented yet")
123
+
124
+ except Exception as e:
125
+ raise CliCommandInnerException(f"Failed to get configuration: {str(e)}")
126
+
127
+ def _handle_set(self, args: argparse.Namespace) -> None:
128
+ try:
129
+ import cognee
130
+
131
+ # Try to parse value as JSON, otherwise treat as string
132
+ try:
133
+ value = json.loads(args.value)
134
+ except json.JSONDecodeError:
135
+ value = args.value
136
+
137
+ try:
138
+ cognee.config.set(args.key, value)
139
+ fmt.success(f"Set {args.key} = {value}")
140
+ except Exception:
141
+ fmt.error(f"Failed to set configuration key '{args.key}'")
142
+
143
+ except Exception as e:
144
+ raise CliCommandInnerException(f"Failed to set configuration: {str(e)}")
145
+
146
+ def _handle_unset(self, args: argparse.Namespace) -> None:
147
+ try:
148
+ import cognee
149
+
150
+ # Confirm unset unless forced
151
+ if not args.force:
152
+ if not fmt.confirm(f"Unset configuration key '{args.key}'?"):
153
+ fmt.echo("Unset cancelled.")
154
+ return
155
+
156
+ # Since the config system doesn't have explicit unset methods,
157
+ # we need to map config keys to their reset/default behaviors
158
+ config_key_mappings = {
159
+ # LLM configuration
160
+ "llm_provider": ("set_llm_provider", "openai"),
161
+ "llm_model": ("set_llm_model", "gpt-5-mini"),
162
+ "llm_api_key": ("set_llm_api_key", ""),
163
+ "llm_endpoint": ("set_llm_endpoint", ""),
164
+ # Database configuration
165
+ "graph_database_provider": ("set_graph_database_provider", "kuzu"),
166
+ "vector_db_provider": ("set_vector_db_provider", "lancedb"),
167
+ "vector_db_url": ("set_vector_db_url", ""),
168
+ "vector_db_key": ("set_vector_db_key", ""),
169
+ # Chunking configuration
170
+ "chunk_size": ("set_chunk_size", 1500),
171
+ "chunk_overlap": ("set_chunk_overlap", 10),
172
+ }
173
+
174
+ if args.key in config_key_mappings:
175
+ method_name, default_value = config_key_mappings[args.key]
176
+
177
+ try:
178
+ # Get the method and call it with the default value
179
+ method = getattr(cognee.config, method_name)
180
+ method(default_value)
181
+ fmt.success(f"Unset {args.key} (reset to default: {default_value})")
182
+ except AttributeError:
183
+ fmt.error(f"Configuration method '{method_name}' not found")
184
+ except Exception as e:
185
+ fmt.error(f"Failed to unset '{args.key}': {str(e)}")
186
+ else:
187
+ fmt.error(f"Unknown configuration key '{args.key}'")
188
+ fmt.note("Available keys: " + ", ".join(config_key_mappings.keys()))
189
+ fmt.note("Use 'cognee config list' to see all available configuration options")
190
+
191
+ except Exception as e:
192
+ raise CliCommandInnerException(f"Failed to unset configuration: {str(e)}")
193
+
194
+ def _handle_list(self, args: argparse.Namespace) -> None:
195
+ try:
196
+ import cognee
197
+
198
+ # This would need to be implemented in cognee.config
199
+ fmt.note("Available configuration keys:")
200
+ fmt.echo(" llm_provider, llm_model, llm_api_key, llm_endpoint")
201
+ fmt.echo(" graph_database_provider, vector_db_provider")
202
+ fmt.echo(" vector_db_url, vector_db_key")
203
+ fmt.echo(" chunk_size, chunk_overlap")
204
+ fmt.echo("")
205
+ fmt.echo("Commands:")
206
+ fmt.echo(" cognee config get [key] - View configuration")
207
+ fmt.echo(" cognee config set <key> <value> - Set configuration")
208
+ fmt.echo(" cognee config unset <key> - Reset key to default")
209
+ fmt.echo(" cognee config reset - Reset all to defaults")
210
+
211
+ except Exception as e:
212
+ raise CliCommandInnerException(f"Failed to list configuration: {str(e)}")
213
+
214
+ def _handle_reset(self, args: argparse.Namespace) -> None:
215
+ try:
216
+ if not args.force:
217
+ if not fmt.confirm("Reset all configuration to defaults?"):
218
+ fmt.echo("Reset cancelled.")
219
+ return
220
+
221
+ fmt.note("Configuration reset not fully implemented yet")
222
+ fmt.echo("This would reset all settings to their default values")
223
+
224
+ except Exception as e:
225
+ raise CliCommandInnerException(f"Failed to reset configuration: {str(e)}")