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.
Files changed (250) hide show
  1. cognee/__init__.py +1 -0
  2. cognee/__main__.py +4 -0
  3. cognee/api/client.py +28 -3
  4. cognee/api/health.py +10 -13
  5. cognee/api/v1/add/add.py +20 -6
  6. cognee/api/v1/add/routers/get_add_router.py +12 -37
  7. cognee/api/v1/cloud/routers/__init__.py +1 -0
  8. cognee/api/v1/cloud/routers/get_checks_router.py +23 -0
  9. cognee/api/v1/cognify/code_graph_pipeline.py +14 -3
  10. cognee/api/v1/cognify/cognify.py +67 -105
  11. cognee/api/v1/cognify/routers/get_cognify_router.py +11 -3
  12. cognee/api/v1/datasets/routers/get_datasets_router.py +16 -5
  13. cognee/api/v1/memify/routers/__init__.py +1 -0
  14. cognee/api/v1/memify/routers/get_memify_router.py +100 -0
  15. cognee/api/v1/notebooks/routers/__init__.py +1 -0
  16. cognee/api/v1/notebooks/routers/get_notebooks_router.py +96 -0
  17. cognee/api/v1/responses/default_tools.py +4 -0
  18. cognee/api/v1/responses/dispatch_function.py +6 -1
  19. cognee/api/v1/responses/models.py +1 -1
  20. cognee/api/v1/search/routers/get_search_router.py +20 -1
  21. cognee/api/v1/search/search.py +17 -4
  22. cognee/api/v1/sync/__init__.py +17 -0
  23. cognee/api/v1/sync/routers/__init__.py +3 -0
  24. cognee/api/v1/sync/routers/get_sync_router.py +241 -0
  25. cognee/api/v1/sync/sync.py +877 -0
  26. cognee/api/v1/users/routers/get_auth_router.py +13 -1
  27. cognee/base_config.py +10 -1
  28. cognee/cli/__init__.py +10 -0
  29. cognee/cli/_cognee.py +180 -0
  30. cognee/cli/commands/__init__.py +1 -0
  31. cognee/cli/commands/add_command.py +80 -0
  32. cognee/cli/commands/cognify_command.py +128 -0
  33. cognee/cli/commands/config_command.py +225 -0
  34. cognee/cli/commands/delete_command.py +80 -0
  35. cognee/cli/commands/search_command.py +149 -0
  36. cognee/cli/config.py +33 -0
  37. cognee/cli/debug.py +21 -0
  38. cognee/cli/echo.py +45 -0
  39. cognee/cli/exceptions.py +23 -0
  40. cognee/cli/minimal_cli.py +97 -0
  41. cognee/cli/reference.py +26 -0
  42. cognee/cli/suppress_logging.py +12 -0
  43. cognee/eval_framework/corpus_builder/corpus_builder_executor.py +2 -2
  44. cognee/eval_framework/eval_config.py +1 -1
  45. cognee/infrastructure/databases/graph/config.py +10 -4
  46. cognee/infrastructure/databases/graph/get_graph_engine.py +4 -9
  47. cognee/infrastructure/databases/graph/kuzu/adapter.py +199 -2
  48. cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +138 -0
  49. cognee/infrastructure/databases/relational/__init__.py +2 -0
  50. cognee/infrastructure/databases/relational/get_async_session.py +15 -0
  51. cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +6 -1
  52. cognee/infrastructure/databases/relational/with_async_session.py +25 -0
  53. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +1 -1
  54. cognee/infrastructure/databases/vector/config.py +13 -6
  55. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +6 -4
  56. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +16 -7
  57. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +5 -5
  58. cognee/infrastructure/databases/vector/embeddings/config.py +2 -2
  59. cognee/infrastructure/databases/vector/embeddings/embedding_rate_limiter.py +2 -6
  60. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +10 -7
  61. cognee/infrastructure/files/storage/LocalFileStorage.py +9 -0
  62. cognee/infrastructure/files/storage/S3FileStorage.py +5 -0
  63. cognee/infrastructure/files/storage/StorageManager.py +7 -1
  64. cognee/infrastructure/files/storage/storage.py +16 -0
  65. cognee/infrastructure/files/utils/get_data_file_path.py +14 -9
  66. cognee/infrastructure/files/utils/get_file_metadata.py +2 -1
  67. cognee/infrastructure/llm/LLMGateway.py +32 -5
  68. cognee/infrastructure/llm/config.py +6 -4
  69. cognee/infrastructure/llm/prompts/extract_query_time.txt +15 -0
  70. cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +25 -0
  71. cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +30 -0
  72. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +16 -5
  73. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +2 -0
  74. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_event_entities.py +44 -0
  75. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/__init__.py +1 -0
  76. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_content_graph.py +19 -15
  77. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_event_graph.py +46 -0
  78. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +3 -3
  79. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +3 -3
  80. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +2 -2
  81. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +14 -8
  82. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +6 -4
  83. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +28 -4
  84. cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +2 -2
  85. cognee/infrastructure/llm/tokenizer/HuggingFace/adapter.py +3 -3
  86. cognee/infrastructure/llm/tokenizer/Mistral/adapter.py +3 -3
  87. cognee/infrastructure/llm/tokenizer/TikToken/adapter.py +6 -6
  88. cognee/infrastructure/llm/utils.py +7 -7
  89. cognee/infrastructure/utils/run_sync.py +8 -1
  90. cognee/modules/chunking/models/DocumentChunk.py +4 -3
  91. cognee/modules/cloud/exceptions/CloudApiKeyMissingError.py +15 -0
  92. cognee/modules/cloud/exceptions/CloudConnectionError.py +15 -0
  93. cognee/modules/cloud/exceptions/__init__.py +2 -0
  94. cognee/modules/cloud/operations/__init__.py +1 -0
  95. cognee/modules/cloud/operations/check_api_key.py +25 -0
  96. cognee/modules/data/deletion/prune_system.py +1 -1
  97. cognee/modules/data/methods/__init__.py +2 -0
  98. cognee/modules/data/methods/check_dataset_name.py +1 -1
  99. cognee/modules/data/methods/create_authorized_dataset.py +19 -0
  100. cognee/modules/data/methods/get_authorized_dataset.py +11 -5
  101. cognee/modules/data/methods/get_authorized_dataset_by_name.py +16 -0
  102. cognee/modules/data/methods/get_dataset_data.py +1 -1
  103. cognee/modules/data/methods/load_or_create_datasets.py +2 -20
  104. cognee/modules/engine/models/Event.py +16 -0
  105. cognee/modules/engine/models/Interval.py +8 -0
  106. cognee/modules/engine/models/Timestamp.py +13 -0
  107. cognee/modules/engine/models/__init__.py +3 -0
  108. cognee/modules/engine/utils/__init__.py +2 -0
  109. cognee/modules/engine/utils/generate_event_datapoint.py +46 -0
  110. cognee/modules/engine/utils/generate_timestamp_datapoint.py +51 -0
  111. cognee/modules/graph/cognee_graph/CogneeGraph.py +2 -2
  112. cognee/modules/graph/methods/get_formatted_graph_data.py +3 -2
  113. cognee/modules/graph/utils/__init__.py +1 -0
  114. cognee/modules/graph/utils/resolve_edges_to_text.py +71 -0
  115. cognee/modules/memify/__init__.py +1 -0
  116. cognee/modules/memify/memify.py +118 -0
  117. cognee/modules/notebooks/methods/__init__.py +5 -0
  118. cognee/modules/notebooks/methods/create_notebook.py +26 -0
  119. cognee/modules/notebooks/methods/delete_notebook.py +13 -0
  120. cognee/modules/notebooks/methods/get_notebook.py +21 -0
  121. cognee/modules/notebooks/methods/get_notebooks.py +18 -0
  122. cognee/modules/notebooks/methods/update_notebook.py +17 -0
  123. cognee/modules/notebooks/models/Notebook.py +53 -0
  124. cognee/modules/notebooks/models/__init__.py +1 -0
  125. cognee/modules/notebooks/operations/__init__.py +1 -0
  126. cognee/modules/notebooks/operations/run_in_local_sandbox.py +55 -0
  127. cognee/modules/pipelines/__init__.py +1 -1
  128. cognee/modules/pipelines/exceptions/tasks.py +18 -0
  129. cognee/modules/pipelines/layers/__init__.py +1 -0
  130. cognee/modules/pipelines/layers/check_pipeline_run_qualification.py +59 -0
  131. cognee/modules/pipelines/layers/pipeline_execution_mode.py +127 -0
  132. cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +28 -0
  133. cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +34 -0
  134. cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +55 -0
  135. cognee/modules/pipelines/layers/setup_and_check_environment.py +41 -0
  136. cognee/modules/pipelines/layers/validate_pipeline_tasks.py +20 -0
  137. cognee/modules/pipelines/methods/__init__.py +2 -0
  138. cognee/modules/pipelines/methods/get_pipeline_runs_by_dataset.py +34 -0
  139. cognee/modules/pipelines/methods/reset_pipeline_run_status.py +16 -0
  140. cognee/modules/pipelines/operations/__init__.py +0 -1
  141. cognee/modules/pipelines/operations/log_pipeline_run_initiated.py +1 -1
  142. cognee/modules/pipelines/operations/pipeline.py +24 -138
  143. cognee/modules/pipelines/operations/run_tasks.py +17 -41
  144. cognee/modules/retrieval/base_feedback.py +11 -0
  145. cognee/modules/retrieval/base_graph_retriever.py +18 -0
  146. cognee/modules/retrieval/base_retriever.py +1 -1
  147. cognee/modules/retrieval/code_retriever.py +8 -0
  148. cognee/modules/retrieval/coding_rules_retriever.py +31 -0
  149. cognee/modules/retrieval/completion_retriever.py +9 -3
  150. cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -0
  151. cognee/modules/retrieval/cypher_search_retriever.py +1 -9
  152. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +29 -13
  153. cognee/modules/retrieval/graph_completion_cot_retriever.py +30 -13
  154. cognee/modules/retrieval/graph_completion_retriever.py +107 -56
  155. cognee/modules/retrieval/graph_summary_completion_retriever.py +5 -1
  156. cognee/modules/retrieval/insights_retriever.py +14 -3
  157. cognee/modules/retrieval/natural_language_retriever.py +0 -4
  158. cognee/modules/retrieval/summaries_retriever.py +1 -1
  159. cognee/modules/retrieval/temporal_retriever.py +152 -0
  160. cognee/modules/retrieval/user_qa_feedback.py +83 -0
  161. cognee/modules/retrieval/utils/brute_force_triplet_search.py +7 -32
  162. cognee/modules/retrieval/utils/completion.py +10 -3
  163. cognee/modules/retrieval/utils/extract_uuid_from_node.py +18 -0
  164. cognee/modules/retrieval/utils/models.py +40 -0
  165. cognee/modules/search/methods/get_search_type_tools.py +168 -0
  166. cognee/modules/search/methods/no_access_control_search.py +47 -0
  167. cognee/modules/search/methods/search.py +239 -118
  168. cognee/modules/search/types/SearchResult.py +21 -0
  169. cognee/modules/search/types/SearchType.py +3 -0
  170. cognee/modules/search/types/__init__.py +1 -0
  171. cognee/modules/search/utils/__init__.py +2 -0
  172. cognee/modules/search/utils/prepare_search_result.py +41 -0
  173. cognee/modules/search/utils/transform_context_to_graph.py +38 -0
  174. cognee/modules/settings/get_settings.py +2 -2
  175. cognee/modules/sync/__init__.py +1 -0
  176. cognee/modules/sync/methods/__init__.py +23 -0
  177. cognee/modules/sync/methods/create_sync_operation.py +53 -0
  178. cognee/modules/sync/methods/get_sync_operation.py +107 -0
  179. cognee/modules/sync/methods/update_sync_operation.py +248 -0
  180. cognee/modules/sync/models/SyncOperation.py +142 -0
  181. cognee/modules/sync/models/__init__.py +3 -0
  182. cognee/modules/users/__init__.py +0 -1
  183. cognee/modules/users/methods/__init__.py +4 -1
  184. cognee/modules/users/methods/create_user.py +26 -1
  185. cognee/modules/users/methods/get_authenticated_user.py +36 -42
  186. cognee/modules/users/methods/get_default_user.py +3 -1
  187. cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +2 -1
  188. cognee/root_dir.py +19 -0
  189. cognee/shared/CodeGraphEntities.py +1 -0
  190. cognee/shared/logging_utils.py +143 -32
  191. cognee/shared/utils.py +0 -1
  192. cognee/tasks/codingagents/coding_rule_associations.py +127 -0
  193. cognee/tasks/graph/extract_graph_from_data.py +6 -2
  194. cognee/tasks/ingestion/save_data_item_to_storage.py +23 -0
  195. cognee/tasks/memify/__init__.py +2 -0
  196. cognee/tasks/memify/extract_subgraph.py +7 -0
  197. cognee/tasks/memify/extract_subgraph_chunks.py +11 -0
  198. cognee/tasks/repo_processor/get_local_dependencies.py +2 -0
  199. cognee/tasks/repo_processor/get_repo_file_dependencies.py +144 -47
  200. cognee/tasks/storage/add_data_points.py +33 -3
  201. cognee/tasks/temporal_graph/__init__.py +1 -0
  202. cognee/tasks/temporal_graph/add_entities_to_event.py +85 -0
  203. cognee/tasks/temporal_graph/enrich_events.py +34 -0
  204. cognee/tasks/temporal_graph/extract_events_and_entities.py +32 -0
  205. cognee/tasks/temporal_graph/extract_knowledge_graph_from_events.py +41 -0
  206. cognee/tasks/temporal_graph/models.py +49 -0
  207. cognee/tests/integration/cli/__init__.py +3 -0
  208. cognee/tests/integration/cli/test_cli_integration.py +331 -0
  209. cognee/tests/integration/documents/PdfDocument_test.py +2 -2
  210. cognee/tests/integration/documents/TextDocument_test.py +2 -4
  211. cognee/tests/integration/documents/UnstructuredDocument_test.py +5 -8
  212. cognee/tests/{test_deletion.py → test_delete_hard.py} +0 -37
  213. cognee/tests/test_delete_soft.py +85 -0
  214. cognee/tests/test_kuzu.py +2 -2
  215. cognee/tests/test_neo4j.py +2 -2
  216. cognee/tests/test_permissions.py +3 -3
  217. cognee/tests/test_relational_db_migration.py +7 -5
  218. cognee/tests/test_search_db.py +136 -23
  219. cognee/tests/test_temporal_graph.py +167 -0
  220. cognee/tests/unit/api/__init__.py +1 -0
  221. cognee/tests/unit/api/test_conditional_authentication_endpoints.py +246 -0
  222. cognee/tests/unit/cli/__init__.py +3 -0
  223. cognee/tests/unit/cli/test_cli_commands.py +483 -0
  224. cognee/tests/unit/cli/test_cli_edge_cases.py +625 -0
  225. cognee/tests/unit/cli/test_cli_main.py +173 -0
  226. cognee/tests/unit/cli/test_cli_runner.py +62 -0
  227. cognee/tests/unit/cli/test_cli_utils.py +127 -0
  228. cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +18 -2
  229. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +12 -15
  230. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +10 -15
  231. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +4 -3
  232. cognee/tests/unit/modules/retrieval/insights_retriever_test.py +4 -2
  233. cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +18 -2
  234. cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +225 -0
  235. cognee/tests/unit/modules/users/__init__.py +1 -0
  236. cognee/tests/unit/modules/users/test_conditional_authentication.py +277 -0
  237. cognee/tests/unit/processing/utils/utils_test.py +20 -1
  238. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/METADATA +13 -9
  239. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/RECORD +245 -135
  240. cognee-0.3.0.dev0.dist-info/entry_points.txt +2 -0
  241. cognee/infrastructure/databases/graph/networkx/adapter.py +0 -1017
  242. cognee/infrastructure/pipeline/models/Operation.py +0 -60
  243. cognee/notebooks/github_analysis_step_by_step.ipynb +0 -37
  244. cognee/tests/tasks/descriptive_metrics/networkx_metrics_test.py +0 -7
  245. cognee/tests/unit/modules/search/search_methods_test.py +0 -223
  246. /cognee/{infrastructure/databases/graph/networkx → api/v1/memify}/__init__.py +0 -0
  247. /cognee/{infrastructure/pipeline/models → tasks/codingagents}/__init__.py +0 -0
  248. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/WHEEL +0 -0
  249. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/LICENSE +0 -0
  250. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/NOTICE.md +0 -0
@@ -5,6 +5,7 @@ from typing import List, Optional
5
5
  from typing_extensions import Annotated
6
6
  from fastapi import status
7
7
  from fastapi import APIRouter
8
+ from fastapi.encoders import jsonable_encoder
8
9
  from fastapi import HTTPException, Query, Depends
9
10
  from fastapi.responses import JSONResponse, FileResponse
10
11
 
@@ -47,6 +48,7 @@ class DataDTO(OutDTO):
47
48
  extension: str
48
49
  mime_type: str
49
50
  raw_data_location: str
51
+ dataset_id: UUID
50
52
 
51
53
 
52
54
  class GraphNodeDTO(OutDTO):
@@ -114,7 +116,8 @@ def get_datasets_router() -> APIRouter:
114
116
 
115
117
  @router.post("", response_model=DatasetDTO)
116
118
  async def create_new_dataset(
117
- dataset_data: DatasetCreationPayload, user: User = Depends(get_authenticated_user)
119
+ dataset_data: DatasetCreationPayload,
120
+ user: User = Depends(get_authenticated_user),
118
121
  ):
119
122
  """
120
123
  Create a new dataset or return existing dataset with the same name.
@@ -284,7 +287,7 @@ def get_datasets_router() -> APIRouter:
284
287
  - **500 Internal Server Error**: Error retrieving graph data
285
288
  """
286
289
 
287
- graph_data = await get_formatted_graph_data(dataset_id, user.id)
290
+ graph_data = await get_formatted_graph_data(dataset_id, user)
288
291
 
289
292
  return graph_data
290
293
 
@@ -327,7 +330,7 @@ def get_datasets_router() -> APIRouter:
327
330
  },
328
331
  )
329
332
 
330
- from cognee.modules.data.methods import get_dataset_data, get_dataset
333
+ from cognee.modules.data.methods import get_dataset_data
331
334
 
332
335
  # Verify user has permission to read dataset
333
336
  dataset = await get_authorized_existing_datasets([dataset_id], "read", user)
@@ -338,12 +341,20 @@ def get_datasets_router() -> APIRouter:
338
341
  content=ErrorResponseDTO(f"Dataset ({str(dataset_id)}) not found."),
339
342
  )
340
343
 
341
- dataset_data = await get_dataset_data(dataset_id=dataset[0].id)
344
+ dataset_id = dataset[0].id
345
+
346
+ dataset_data = await get_dataset_data(dataset_id=dataset_id)
342
347
 
343
348
  if dataset_data is None:
344
349
  return []
345
350
 
346
- return dataset_data
351
+ return [
352
+ dict(
353
+ **jsonable_encoder(data),
354
+ dataset_id=dataset_id,
355
+ )
356
+ for data in dataset_data
357
+ ]
347
358
 
348
359
  @router.get("/status", response_model=dict[str, PipelineRunStatus])
349
360
  async def get_dataset_status(
@@ -0,0 +1 @@
1
+ from .get_memify_router import get_memify_router
@@ -0,0 +1,100 @@
1
+ from uuid import UUID
2
+
3
+ from fastapi import APIRouter
4
+ from fastapi.responses import JSONResponse
5
+ from fastapi import Depends
6
+ from pydantic import Field
7
+ from typing import List, Optional, Union, Literal
8
+
9
+ from cognee.api.DTO import InDTO
10
+ from cognee.modules.users.models import User
11
+ from cognee.modules.users.methods import get_authenticated_user
12
+ from cognee.shared.utils import send_telemetry
13
+ from cognee.modules.pipelines.models import PipelineRunErrored
14
+ from cognee.shared.logging_utils import get_logger
15
+
16
+ logger = get_logger()
17
+
18
+
19
+ class MemifyPayloadDTO(InDTO):
20
+ extraction_tasks: Optional[List[str]] = Field(
21
+ default=None,
22
+ examples=[[]],
23
+ )
24
+ enrichment_tasks: Optional[List[str]] = Field(default=None, examples=[[]])
25
+ data: Optional[str] = Field(default="")
26
+ dataset_name: Optional[str] = Field(default=None)
27
+ # Note: Literal is needed for Swagger use
28
+ dataset_id: Union[UUID, Literal[""], None] = Field(default=None, examples=[""])
29
+ node_name: Optional[List[str]] = Field(default=None, examples=[[]])
30
+ run_in_background: Optional[bool] = Field(default=False)
31
+
32
+
33
+ def get_memify_router() -> APIRouter:
34
+ router = APIRouter()
35
+
36
+ @router.post("", response_model=dict)
37
+ async def memify(payload: MemifyPayloadDTO, user: User = Depends(get_authenticated_user)):
38
+ """
39
+ Enrichment pipeline in Cognee, can work with already built graphs. If no data is provided existing knowledge graph will be used as data,
40
+ custom data can also be provided instead which can be processed with provided extraction and enrichment tasks.
41
+
42
+ Provided tasks and data will be arranged to run the Cognee pipeline and execute graph enrichment/creation.
43
+
44
+ ## Request Parameters
45
+ - **extractionTasks** Optional[List[str]]: List of available Cognee Tasks to execute for graph/data extraction.
46
+ - **enrichmentTasks** Optional[List[str]]: List of available Cognee Tasks to handle enrichment of provided graph/data from extraction tasks.
47
+ - **data** Optional[List[str]]: The data to ingest. Can be any text data when custom extraction and enrichment tasks are used.
48
+ Data provided here will be forwarded to the first extraction task in the pipeline as input.
49
+ If no data is provided the whole graph (or subgraph if node_name/node_type is specified) will be forwarded
50
+ - **dataset_name** (Optional[str]): Name of the datasets to memify
51
+ - **dataset_id** (Optional[UUID]): List of UUIDs of an already existing dataset
52
+ - **node_name** (Optional[List[str]]): Filter graph to specific named entities (for targeted search). Used when no data is provided.
53
+ - **run_in_background** (Optional[bool]): Whether to execute processing asynchronously. Defaults to False (blocking).
54
+
55
+ Either datasetName or datasetId must be provided.
56
+
57
+ ## Response
58
+ Returns information about the add operation containing:
59
+ - Status of the operation
60
+ - Details about the processed data
61
+ - Any relevant metadata from the ingestion process
62
+
63
+ ## Error Codes
64
+ - **400 Bad Request**: Neither datasetId nor datasetName provided
65
+ - **409 Conflict**: Error during memify operation
66
+ - **403 Forbidden**: User doesn't have permission to use dataset
67
+
68
+ ## Notes
69
+ - To memify datasets not owned by the user, use dataset_id (when ENABLE_BACKEND_ACCESS_CONTROL is set to True)
70
+ - datasetId value can only be the UUID of an already existing dataset
71
+ """
72
+
73
+ send_telemetry(
74
+ "Memify API Endpoint Invoked",
75
+ user.id,
76
+ additional_properties={"endpoint": "POST /v1/memify"},
77
+ )
78
+
79
+ if not payload.dataset_id and not payload.dataset_name:
80
+ raise ValueError("Either datasetId or datasetName must be provided.")
81
+
82
+ try:
83
+ from cognee.modules.memify import memify as cognee_memify
84
+
85
+ memify_run = await cognee_memify(
86
+ extraction_tasks=payload.extraction_tasks,
87
+ enrichment_tasks=payload.enrichment_tasks,
88
+ data=payload.data,
89
+ dataset=payload.dataset_id if payload.dataset_id else payload.dataset_name,
90
+ node_name=payload.node_name,
91
+ user=user,
92
+ )
93
+
94
+ if isinstance(memify_run, PipelineRunErrored):
95
+ return JSONResponse(status_code=420, content=memify_run)
96
+ return memify_run
97
+ except Exception as error:
98
+ return JSONResponse(status_code=409, content={"error": str(error)})
99
+
100
+ return router
@@ -0,0 +1 @@
1
+ from .get_notebooks_router import get_notebooks_router
@@ -0,0 +1,96 @@
1
+ from uuid import UUID
2
+ from fastapi.encoders import jsonable_encoder
3
+ from fastapi.responses import JSONResponse
4
+ from pydantic import Field
5
+ from typing import List, Optional
6
+ from fastapi import APIRouter, Depends
7
+
8
+ from cognee.api.DTO import InDTO
9
+ from cognee.infrastructure.databases.relational import get_async_session
10
+ from cognee.infrastructure.utils.run_async import run_async
11
+ from cognee.modules.notebooks.models import Notebook, NotebookCell
12
+ from cognee.modules.notebooks.operations import run_in_local_sandbox
13
+ from cognee.modules.users.models import User
14
+ from cognee.modules.users.methods import get_authenticated_user
15
+ from cognee.modules.notebooks.methods import (
16
+ create_notebook,
17
+ delete_notebook,
18
+ get_notebook,
19
+ get_notebooks,
20
+ update_notebook,
21
+ )
22
+
23
+
24
+ class NotebookData(InDTO):
25
+ name: Optional[str] = Field(...)
26
+ cells: Optional[List[NotebookCell]] = Field(default=[])
27
+
28
+
29
+ def get_notebooks_router():
30
+ router = APIRouter()
31
+
32
+ @router.get("")
33
+ async def get_notebooks_endpoint(user: User = Depends(get_authenticated_user)):
34
+ return await get_notebooks(user.id)
35
+
36
+ @router.post("")
37
+ async def create_notebook_endpoint(
38
+ notebook_data: NotebookData, user: User = Depends(get_authenticated_user)
39
+ ):
40
+ return await create_notebook(
41
+ user.id, notebook_data.name, notebook_data.cells, deletable=True
42
+ )
43
+
44
+ @router.put("/{notebook_id}")
45
+ async def update_notebook_endpoint(
46
+ notebook_id: UUID, notebook_data: NotebookData, user: User = Depends(get_authenticated_user)
47
+ ):
48
+ async with get_async_session(auto_commit=True) as session:
49
+ notebook: Notebook = await get_notebook(notebook_id, user.id, session)
50
+
51
+ if notebook is None:
52
+ return JSONResponse(status_code=404, content={"error": "Notebook not found"})
53
+
54
+ if notebook_data.name and notebook_data.name != notebook.name:
55
+ notebook.name = notebook_data.name
56
+
57
+ if notebook_data.cells:
58
+ notebook.cells = notebook_data.cells
59
+
60
+ return await update_notebook(notebook, session)
61
+
62
+ class RunCodeData(InDTO):
63
+ content: str = Field(...)
64
+
65
+ @router.post("/{notebook_id}/{cell_id}/run")
66
+ async def run_notebook_cell_endpoint(
67
+ notebook_id: UUID,
68
+ cell_id: UUID,
69
+ run_code: RunCodeData,
70
+ user: User = Depends(get_authenticated_user),
71
+ ):
72
+ async with get_async_session() as session:
73
+ notebook: Notebook = await get_notebook(notebook_id, user.id, session)
74
+
75
+ if notebook is None:
76
+ return JSONResponse(status_code=404, content={"error": "Notebook not found"})
77
+
78
+ result, error = await run_async(run_in_local_sandbox, run_code.content)
79
+
80
+ return JSONResponse(
81
+ status_code=200, content={"result": jsonable_encoder(result), "error": error}
82
+ )
83
+
84
+ @router.delete("/{notebook_id}")
85
+ async def delete_notebook_endpoint(
86
+ notebook_id: UUID, user: User = Depends(get_authenticated_user)
87
+ ):
88
+ async with get_async_session(auto_commit=True) as session:
89
+ notebook: Notebook = await get_notebook(notebook_id, user.id, session)
90
+
91
+ if notebook is None:
92
+ return JSONResponse(status_code=404, content={"error": "Notebook not found"})
93
+
94
+ return await delete_notebook(notebook, session)
95
+
96
+ return router
@@ -49,6 +49,10 @@ DEFAULT_TOOLS = [
49
49
  "type": "string",
50
50
  "description": "Path to a custom ontology file",
51
51
  },
52
+ "custom_prompt": {
53
+ "type": "string",
54
+ "description": "Custom prompt for entity extraction and graph generation. If provided, this prompt will be used instead of the default prompts.",
55
+ },
52
56
  },
53
57
  "required": ["text"],
54
58
  },
@@ -88,11 +88,16 @@ async def handle_cognify(arguments: Dict[str, Any], user) -> str:
88
88
  """Handle cognify function call"""
89
89
  text = arguments.get("text")
90
90
  ontology_file_path = arguments.get("ontology_file_path")
91
+ custom_prompt = arguments.get("custom_prompt")
91
92
 
92
93
  if text:
93
94
  await add(data=text, user=user)
94
95
 
95
- await cognify(user=user, ontology_file_path=ontology_file_path if ontology_file_path else None)
96
+ await cognify(
97
+ user=user,
98
+ ontology_file_path=ontology_file_path if ontology_file_path else None,
99
+ custom_prompt=custom_prompt,
100
+ )
96
101
 
97
102
  return (
98
103
  "Text successfully converted into knowledge graph."
@@ -70,7 +70,7 @@ class ResponseRequest(InDTO):
70
70
  tool_choice: Optional[Union[str, Dict[str, Any]]] = "auto"
71
71
  user: Optional[str] = None
72
72
  temperature: Optional[float] = 1.0
73
- max_tokens: Optional[int] = None
73
+ max_completion_tokens: Optional[int] = None
74
74
 
75
75
 
76
76
  class ToolCallOutput(BaseModel):
@@ -4,6 +4,8 @@ from datetime import datetime
4
4
  from pydantic import Field
5
5
  from fastapi import Depends, APIRouter
6
6
  from fastapi.responses import JSONResponse
7
+ from fastapi.encoders import jsonable_encoder
8
+
7
9
  from cognee.modules.search.types import SearchType
8
10
  from cognee.api.DTO import InDTO, OutDTO
9
11
  from cognee.modules.users.exceptions.exceptions import PermissionDeniedError
@@ -20,7 +22,13 @@ class SearchPayloadDTO(InDTO):
20
22
  datasets: Optional[list[str]] = Field(default=None)
21
23
  dataset_ids: Optional[list[UUID]] = Field(default=None, examples=[[]])
22
24
  query: str = Field(default="What is in the document?")
25
+ system_prompt: Optional[str] = Field(
26
+ default="Answer the question using the provided context. Be as brief as possible."
27
+ )
28
+ node_name: Optional[list[str]] = Field(default=None, example=[])
23
29
  top_k: Optional[int] = Field(default=10)
30
+ only_context: bool = Field(default=False)
31
+ use_combined_context: bool = Field(default=False)
24
32
 
25
33
 
26
34
  def get_search_router() -> APIRouter:
@@ -79,7 +87,10 @@ def get_search_router() -> APIRouter:
79
87
  - **datasets** (Optional[List[str]]): List of dataset names to search within
80
88
  - **dataset_ids** (Optional[List[UUID]]): List of dataset UUIDs to search within
81
89
  - **query** (str): The search query string
90
+ - **system_prompt** Optional[str]: System prompt to be used for Completion type searches in Cognee
91
+ - **node_name** Optional[list[str]]: Filter results to specific node_sets defined in the add pipeline (for targeted search).
82
92
  - **top_k** (Optional[int]): Maximum number of results to return (default: 10)
93
+ - **only_context** bool: Set to true to only return context Cognee will be sending to LLM in Completion type searches. This will be returned instead of LLM calls for completion type searches.
83
94
 
84
95
  ## Response
85
96
  Returns a list of search results containing relevant nodes from the graph.
@@ -102,7 +113,11 @@ def get_search_router() -> APIRouter:
102
113
  "datasets": payload.datasets,
103
114
  "dataset_ids": [str(dataset_id) for dataset_id in payload.dataset_ids or []],
104
115
  "query": payload.query,
116
+ "system_prompt": payload.system_prompt,
117
+ "node_name": payload.node_name,
105
118
  "top_k": payload.top_k,
119
+ "only_context": payload.only_context,
120
+ "use_combined_context": payload.use_combined_context,
106
121
  },
107
122
  )
108
123
 
@@ -115,10 +130,14 @@ def get_search_router() -> APIRouter:
115
130
  user=user,
116
131
  datasets=payload.datasets,
117
132
  dataset_ids=payload.dataset_ids,
133
+ system_prompt=payload.system_prompt,
134
+ node_name=payload.node_name,
118
135
  top_k=payload.top_k,
136
+ only_context=payload.only_context,
137
+ use_combined_context=payload.use_combined_context,
119
138
  )
120
139
 
121
- return results
140
+ return jsonable_encoder(results)
122
141
  except PermissionDeniedError:
123
142
  return []
124
143
  except Exception as error:
@@ -1,8 +1,9 @@
1
1
  from uuid import UUID
2
2
  from typing import Union, Optional, List, Type
3
3
 
4
+ from cognee.modules.engine.models.node_set import NodeSet
4
5
  from cognee.modules.users.models import User
5
- from cognee.modules.search.types import SearchType
6
+ from cognee.modules.search.types import SearchResult, SearchType, CombinedSearchResult
6
7
  from cognee.modules.users.methods import get_default_user
7
8
  from cognee.modules.search.methods import search as search_function
8
9
  from cognee.modules.data.methods import get_authorized_existing_datasets
@@ -12,14 +13,19 @@ from cognee.modules.data.exceptions import DatasetNotFoundError
12
13
  async def search(
13
14
  query_text: str,
14
15
  query_type: SearchType = SearchType.GRAPH_COMPLETION,
15
- user: User = None,
16
+ user: Optional[User] = None,
16
17
  datasets: Optional[Union[list[str], str]] = None,
17
18
  dataset_ids: Optional[Union[list[UUID], UUID]] = None,
18
19
  system_prompt_path: str = "answer_simple_question.txt",
20
+ system_prompt: Optional[str] = None,
19
21
  top_k: int = 10,
20
- node_type: Optional[Type] = None,
22
+ node_type: Optional[Type] = NodeSet,
21
23
  node_name: Optional[List[str]] = None,
22
- ) -> list:
24
+ save_interaction: bool = False,
25
+ last_k: Optional[int] = None,
26
+ only_context: bool = False,
27
+ use_combined_context: bool = False,
28
+ ) -> Union[List[SearchResult], CombinedSearchResult]:
23
29
  """
24
30
  Search and query the knowledge graph for insights, information, and connections.
25
31
 
@@ -107,6 +113,8 @@ async def search(
107
113
 
108
114
  node_name: Filter results to specific named entities (for targeted search).
109
115
 
116
+ save_interaction: Save interaction (query, context, answer connected to triplet endpoints) results into the graph or not
117
+
110
118
  Returns:
111
119
  list: Search results in format determined by query_type:
112
120
 
@@ -179,9 +187,14 @@ async def search(
179
187
  dataset_ids=dataset_ids if dataset_ids else datasets,
180
188
  user=user,
181
189
  system_prompt_path=system_prompt_path,
190
+ system_prompt=system_prompt,
182
191
  top_k=top_k,
183
192
  node_type=node_type,
184
193
  node_name=node_name,
194
+ save_interaction=save_interaction,
195
+ last_k=last_k,
196
+ only_context=only_context,
197
+ use_combined_context=use_combined_context,
185
198
  )
186
199
 
187
200
  return filtered_search_results
@@ -0,0 +1,17 @@
1
+ from .sync import (
2
+ sync,
3
+ SyncResponse,
4
+ LocalFileInfo,
5
+ CheckMissingHashesRequest,
6
+ CheckHashesDiffResponse,
7
+ PruneDatasetRequest,
8
+ )
9
+
10
+ __all__ = [
11
+ "sync",
12
+ "SyncResponse",
13
+ "LocalFileInfo",
14
+ "CheckMissingHashesRequest",
15
+ "CheckHashesDiffResponse",
16
+ "PruneDatasetRequest",
17
+ ]
@@ -0,0 +1,3 @@
1
+ from .get_sync_router import get_sync_router
2
+
3
+ __all__ = ["get_sync_router"]