cognee 0.5.1.dev0__py3-none-any.whl → 0.5.2.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 (238) hide show
  1. cognee/__init__.py +2 -0
  2. cognee/alembic/README +1 -0
  3. cognee/alembic/env.py +107 -0
  4. cognee/alembic/script.py.mako +26 -0
  5. cognee/alembic/versions/1a58b986e6e1_enable_delete_for_old_tutorial_notebooks.py +52 -0
  6. cognee/alembic/versions/1d0bb7fede17_add_pipeline_run_status.py +33 -0
  7. cognee/alembic/versions/1daae0df1866_incremental_loading.py +48 -0
  8. cognee/alembic/versions/211ab850ef3d_add_sync_operations_table.py +118 -0
  9. cognee/alembic/versions/45957f0a9849_add_notebook_table.py +46 -0
  10. cognee/alembic/versions/46a6ce2bd2b2_expand_dataset_database_with_json_.py +333 -0
  11. cognee/alembic/versions/482cd6517ce4_add_default_user.py +30 -0
  12. cognee/alembic/versions/76625596c5c3_expand_dataset_database_for_multi_user.py +98 -0
  13. cognee/alembic/versions/8057ae7329c2_initial_migration.py +25 -0
  14. cognee/alembic/versions/9e7a3cb85175_loader_separation.py +104 -0
  15. cognee/alembic/versions/a1b2c3d4e5f6_add_label_column_to_data.py +38 -0
  16. cognee/alembic/versions/ab7e313804ae_permission_system_rework.py +236 -0
  17. cognee/alembic/versions/b9274c27a25a_kuzu_11_migration.py +75 -0
  18. cognee/alembic/versions/c946955da633_multi_tenant_support.py +137 -0
  19. cognee/alembic/versions/e1ec1dcb50b6_add_last_accessed_to_data.py +51 -0
  20. cognee/alembic/versions/e4ebee1091e7_expand_data_model_info.py +140 -0
  21. cognee/alembic.ini +117 -0
  22. cognee/api/v1/add/routers/get_add_router.py +2 -0
  23. cognee/api/v1/cognify/cognify.py +11 -6
  24. cognee/api/v1/cognify/routers/get_cognify_router.py +8 -0
  25. cognee/api/v1/config/config.py +60 -0
  26. cognee/api/v1/datasets/routers/get_datasets_router.py +45 -3
  27. cognee/api/v1/memify/routers/get_memify_router.py +2 -0
  28. cognee/api/v1/search/routers/get_search_router.py +21 -6
  29. cognee/api/v1/search/search.py +25 -5
  30. cognee/api/v1/sync/routers/get_sync_router.py +3 -3
  31. cognee/cli/commands/add_command.py +1 -1
  32. cognee/cli/commands/cognify_command.py +6 -0
  33. cognee/cli/commands/config_command.py +1 -1
  34. cognee/context_global_variables.py +5 -1
  35. cognee/eval_framework/answer_generation/answer_generation_executor.py +7 -8
  36. cognee/infrastructure/databases/cache/cache_db_interface.py +38 -1
  37. cognee/infrastructure/databases/cache/config.py +6 -0
  38. cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py +21 -0
  39. cognee/infrastructure/databases/cache/get_cache_engine.py +9 -3
  40. cognee/infrastructure/databases/cache/redis/RedisAdapter.py +60 -1
  41. cognee/infrastructure/databases/dataset_database_handler/supported_dataset_database_handlers.py +7 -0
  42. cognee/infrastructure/databases/graph/get_graph_engine.py +29 -1
  43. cognee/infrastructure/databases/graph/neo4j_driver/Neo4jAuraDevDatasetDatabaseHandler.py +62 -27
  44. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +17 -4
  45. cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +2 -1
  46. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -0
  47. cognee/infrastructure/databases/vector/config.py +6 -0
  48. cognee/infrastructure/databases/vector/create_vector_engine.py +69 -22
  49. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +64 -9
  50. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +13 -2
  51. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +16 -3
  52. cognee/infrastructure/databases/vector/models/ScoredResult.py +3 -3
  53. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +16 -3
  54. cognee/infrastructure/databases/vector/pgvector/PGVectorDatasetDatabaseHandler.py +86 -0
  55. cognee/infrastructure/databases/vector/pgvector/create_db_and_tables.py +81 -2
  56. cognee/infrastructure/databases/vector/vector_db_interface.py +8 -0
  57. cognee/infrastructure/files/utils/get_data_file_path.py +33 -27
  58. cognee/infrastructure/llm/prompts/extract_query_time.txt +1 -1
  59. cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +1 -1
  60. cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +1 -1
  61. cognee/infrastructure/llm/prompts/generate_graph_prompt.txt +2 -2
  62. cognee/infrastructure/llm/prompts/generate_graph_prompt_guided.txt +1 -1
  63. cognee/infrastructure/llm/prompts/generate_graph_prompt_oneshot.txt +2 -2
  64. cognee/infrastructure/llm/prompts/generate_graph_prompt_simple.txt +1 -1
  65. cognee/infrastructure/llm/prompts/generate_graph_prompt_strict.txt +1 -1
  66. cognee/infrastructure/llm/prompts/search_type_selector_prompt.txt +6 -6
  67. cognee/infrastructure/llm/prompts/test.txt +1 -1
  68. cognee/infrastructure/llm/prompts/translate_content.txt +19 -0
  69. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +24 -0
  70. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llama_cpp/adapter.py +191 -0
  71. cognee/modules/chunking/models/DocumentChunk.py +0 -1
  72. cognee/modules/cognify/config.py +2 -0
  73. cognee/modules/data/models/Data.py +1 -0
  74. cognee/modules/engine/models/Entity.py +0 -1
  75. cognee/modules/engine/operations/setup.py +6 -0
  76. cognee/modules/graph/cognee_graph/CogneeGraph.py +150 -37
  77. cognee/modules/graph/cognee_graph/CogneeGraphElements.py +48 -2
  78. cognee/modules/graph/utils/__init__.py +1 -0
  79. cognee/modules/graph/utils/get_entity_nodes_from_triplets.py +12 -0
  80. cognee/modules/notebooks/methods/__init__.py +1 -0
  81. cognee/modules/notebooks/methods/create_notebook.py +0 -34
  82. cognee/modules/notebooks/methods/create_tutorial_notebooks.py +191 -0
  83. cognee/modules/notebooks/methods/get_notebooks.py +12 -8
  84. cognee/modules/notebooks/tutorials/cognee-basics/cell-1.md +3 -0
  85. cognee/modules/notebooks/tutorials/cognee-basics/cell-2.md +10 -0
  86. cognee/modules/notebooks/tutorials/cognee-basics/cell-3.md +7 -0
  87. cognee/modules/notebooks/tutorials/cognee-basics/cell-4.py +28 -0
  88. cognee/modules/notebooks/tutorials/cognee-basics/cell-5.py +3 -0
  89. cognee/modules/notebooks/tutorials/cognee-basics/cell-6.py +9 -0
  90. cognee/modules/notebooks/tutorials/cognee-basics/cell-7.py +17 -0
  91. cognee/modules/notebooks/tutorials/cognee-basics/config.json +4 -0
  92. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-1.md +3 -0
  93. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-10.md +3 -0
  94. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-11.md +3 -0
  95. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-12.py +3 -0
  96. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-13.md +7 -0
  97. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-14.py +6 -0
  98. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-15.md +3 -0
  99. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-16.py +7 -0
  100. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-2.md +9 -0
  101. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-3.md +7 -0
  102. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-4.md +9 -0
  103. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-5.md +5 -0
  104. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-6.py +13 -0
  105. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-7.md +3 -0
  106. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-8.md +3 -0
  107. cognee/modules/notebooks/tutorials/python-development-with-cognee/cell-9.py +31 -0
  108. cognee/modules/notebooks/tutorials/python-development-with-cognee/config.json +4 -0
  109. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/copilot_conversations.json +107 -0
  110. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/guido_contributions.json +976 -0
  111. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/my_developer_rules.md +79 -0
  112. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/pep_style_guide.md +74 -0
  113. cognee/modules/notebooks/tutorials/python-development-with-cognee/data/zen_principles.md +74 -0
  114. cognee/modules/retrieval/EntityCompletionRetriever.py +51 -38
  115. cognee/modules/retrieval/__init__.py +0 -1
  116. cognee/modules/retrieval/base_retriever.py +66 -10
  117. cognee/modules/retrieval/chunks_retriever.py +57 -49
  118. cognee/modules/retrieval/coding_rules_retriever.py +12 -5
  119. cognee/modules/retrieval/completion_retriever.py +29 -28
  120. cognee/modules/retrieval/cypher_search_retriever.py +25 -20
  121. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +42 -46
  122. cognee/modules/retrieval/graph_completion_cot_retriever.py +68 -51
  123. cognee/modules/retrieval/graph_completion_retriever.py +78 -63
  124. cognee/modules/retrieval/graph_summary_completion_retriever.py +2 -0
  125. cognee/modules/retrieval/lexical_retriever.py +34 -12
  126. cognee/modules/retrieval/natural_language_retriever.py +18 -15
  127. cognee/modules/retrieval/summaries_retriever.py +51 -34
  128. cognee/modules/retrieval/temporal_retriever.py +59 -49
  129. cognee/modules/retrieval/triplet_retriever.py +31 -32
  130. cognee/modules/retrieval/utils/access_tracking.py +88 -0
  131. cognee/modules/retrieval/utils/brute_force_triplet_search.py +99 -85
  132. cognee/modules/retrieval/utils/node_edge_vector_search.py +174 -0
  133. cognee/modules/search/methods/__init__.py +1 -0
  134. cognee/modules/search/methods/get_retriever_output.py +53 -0
  135. cognee/modules/search/methods/get_search_type_retriever_instance.py +252 -0
  136. cognee/modules/search/methods/search.py +90 -215
  137. cognee/modules/search/models/SearchResultPayload.py +67 -0
  138. cognee/modules/search/types/SearchResult.py +1 -8
  139. cognee/modules/search/types/SearchType.py +1 -2
  140. cognee/modules/search/types/__init__.py +1 -1
  141. cognee/modules/search/utils/__init__.py +1 -2
  142. cognee/modules/search/utils/transform_insights_to_graph.py +2 -2
  143. cognee/modules/search/utils/{transform_context_to_graph.py → transform_triplets_to_graph.py} +2 -2
  144. cognee/modules/users/authentication/default/default_transport.py +11 -1
  145. cognee/modules/users/authentication/get_api_auth_backend.py +2 -1
  146. cognee/modules/users/authentication/get_client_auth_backend.py +2 -1
  147. cognee/modules/users/methods/create_user.py +0 -9
  148. cognee/modules/users/permissions/methods/has_user_management_permission.py +29 -0
  149. cognee/modules/visualization/cognee_network_visualization.py +1 -1
  150. cognee/run_migrations.py +48 -0
  151. cognee/shared/exceptions/__init__.py +1 -3
  152. cognee/shared/exceptions/exceptions.py +11 -1
  153. cognee/shared/usage_logger.py +332 -0
  154. cognee/shared/utils.py +12 -5
  155. cognee/tasks/cleanup/cleanup_unused_data.py +172 -0
  156. cognee/tasks/memify/extract_usage_frequency.py +613 -0
  157. cognee/tasks/summarization/models.py +0 -2
  158. cognee/tasks/temporal_graph/__init__.py +0 -1
  159. cognee/tasks/translation/__init__.py +96 -0
  160. cognee/tasks/translation/config.py +110 -0
  161. cognee/tasks/translation/detect_language.py +190 -0
  162. cognee/tasks/translation/exceptions.py +62 -0
  163. cognee/tasks/translation/models.py +72 -0
  164. cognee/tasks/translation/providers/__init__.py +44 -0
  165. cognee/tasks/translation/providers/azure_provider.py +192 -0
  166. cognee/tasks/translation/providers/base.py +85 -0
  167. cognee/tasks/translation/providers/google_provider.py +158 -0
  168. cognee/tasks/translation/providers/llm_provider.py +143 -0
  169. cognee/tasks/translation/translate_content.py +282 -0
  170. cognee/tasks/web_scraper/default_url_crawler.py +6 -2
  171. cognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py +1 -0
  172. cognee/tests/cli_tests/cli_unit_tests/test_cli_edge_cases.py +3 -0
  173. cognee/tests/integration/retrieval/test_brute_force_triplet_search_with_cognify.py +62 -0
  174. cognee/tests/integration/retrieval/test_chunks_retriever.py +115 -16
  175. cognee/tests/integration/retrieval/test_graph_completion_retriever.py +13 -5
  176. cognee/tests/integration/retrieval/test_graph_completion_retriever_context_extension.py +22 -20
  177. cognee/tests/integration/retrieval/test_graph_completion_retriever_cot.py +23 -24
  178. cognee/tests/integration/retrieval/test_rag_completion_retriever.py +70 -5
  179. cognee/tests/integration/retrieval/test_structured_output.py +62 -18
  180. cognee/tests/integration/retrieval/test_summaries_retriever.py +20 -9
  181. cognee/tests/integration/retrieval/test_temporal_retriever.py +38 -8
  182. cognee/tests/integration/retrieval/test_triplet_retriever.py +13 -4
  183. cognee/tests/integration/shared/test_usage_logger_integration.py +255 -0
  184. cognee/tests/tasks/translation/README.md +147 -0
  185. cognee/tests/tasks/translation/__init__.py +1 -0
  186. cognee/tests/tasks/translation/config_test.py +93 -0
  187. cognee/tests/tasks/translation/detect_language_test.py +118 -0
  188. cognee/tests/tasks/translation/providers_test.py +151 -0
  189. cognee/tests/tasks/translation/translate_content_test.py +213 -0
  190. cognee/tests/test_chromadb.py +1 -1
  191. cognee/tests/test_cleanup_unused_data.py +165 -0
  192. cognee/tests/test_delete_by_id.py +6 -6
  193. cognee/tests/test_extract_usage_frequency.py +308 -0
  194. cognee/tests/test_kuzu.py +17 -7
  195. cognee/tests/test_lancedb.py +3 -1
  196. cognee/tests/test_library.py +1 -1
  197. cognee/tests/test_neo4j.py +17 -7
  198. cognee/tests/test_neptune_analytics_vector.py +3 -1
  199. cognee/tests/test_permissions.py +172 -187
  200. cognee/tests/test_pgvector.py +3 -1
  201. cognee/tests/test_relational_db_migration.py +15 -1
  202. cognee/tests/test_remote_kuzu.py +3 -1
  203. cognee/tests/test_s3_file_storage.py +1 -1
  204. cognee/tests/test_search_db.py +97 -110
  205. cognee/tests/test_usage_logger_e2e.py +268 -0
  206. cognee/tests/unit/api/test_get_raw_data_endpoint.py +206 -0
  207. cognee/tests/unit/eval_framework/answer_generation_test.py +4 -3
  208. cognee/tests/unit/infrastructure/databases/cache/test_cache_config.py +2 -0
  209. cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +42 -2
  210. cognee/tests/unit/modules/graph/cognee_graph_test.py +329 -31
  211. cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +31 -59
  212. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +70 -33
  213. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +72 -52
  214. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +27 -33
  215. cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +28 -15
  216. cognee/tests/unit/modules/retrieval/summaries_retriever_test.py +37 -42
  217. cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +48 -64
  218. cognee/tests/unit/modules/retrieval/test_brute_force_triplet_search.py +263 -24
  219. cognee/tests/unit/modules/retrieval/test_node_edge_vector_search.py +273 -0
  220. cognee/tests/unit/modules/retrieval/triplet_retriever_test.py +30 -16
  221. cognee/tests/unit/modules/search/test_get_search_type_retriever_instance.py +125 -0
  222. cognee/tests/unit/modules/search/test_search.py +176 -0
  223. cognee/tests/unit/modules/search/test_search_prepare_search_result_contract.py +190 -0
  224. cognee/tests/unit/modules/users/test_tutorial_notebook_creation.py +511 -297
  225. cognee/tests/unit/shared/test_usage_logger.py +241 -0
  226. cognee/tests/unit/users/permissions/test_has_user_management_permission.py +46 -0
  227. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/METADATA +17 -10
  228. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/RECORD +232 -144
  229. cognee/api/.env.example +0 -5
  230. cognee/modules/retrieval/base_graph_retriever.py +0 -24
  231. cognee/modules/search/methods/get_search_type_tools.py +0 -223
  232. cognee/modules/search/methods/no_access_control_search.py +0 -62
  233. cognee/modules/search/utils/prepare_search_result.py +0 -63
  234. cognee/tests/test_feedback_enrichment.py +0 -174
  235. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/WHEEL +0 -0
  236. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/entry_points.txt +0 -0
  237. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/LICENSE +0 -0
  238. {cognee-0.5.1.dev0.dist-info → cognee-0.5.2.dev0.dist-info}/licenses/NOTICE.md +0 -0
cognee/__init__.py CHANGED
@@ -33,3 +33,5 @@ from .api.v1.ui import start_ui
33
33
 
34
34
  # Pipelines
35
35
  from .modules import pipelines
36
+
37
+ from cognee.run_migrations import run_migrations
cognee/alembic/README ADDED
@@ -0,0 +1 @@
1
+ Generic single-database configuration with an async dbapi.
cognee/alembic/env.py ADDED
@@ -0,0 +1,107 @@
1
+ import asyncio
2
+ from alembic import context
3
+ from logging.config import fileConfig
4
+ from sqlalchemy import pool
5
+ from sqlalchemy.engine import Connection
6
+ from sqlalchemy.ext.asyncio import async_engine_from_config
7
+
8
+ from cognee.infrastructure.databases.relational import get_relational_engine, Base
9
+
10
+ # this is the Alembic Config object, which provides
11
+ # access to the values within the .ini file in use.
12
+ config = context.config
13
+
14
+ # Interpret the config file for Python logging.
15
+ # This line sets up loggers basically.
16
+ if config.config_file_name is not None:
17
+ fileConfig(config.config_file_name)
18
+
19
+ # add your model's MetaData object here
20
+ # for 'autogenerate' support
21
+ # from myapp import mymodel
22
+ # target_metadata = mymodel.Base.metadata
23
+
24
+ target_metadata = Base.metadata
25
+
26
+ # other values from the config, defined by the needs of env.py,
27
+ # can be acquired:
28
+ # my_important_option = config.get_main_option("my_important_option")
29
+ # ... etc.
30
+
31
+
32
+ def run_migrations_offline() -> None:
33
+ """Run migrations in 'offline' mode.
34
+
35
+ This configures the context with just a URL
36
+ and not an Engine, though an Engine is acceptable
37
+ here as well. By skipping the Engine creation
38
+ we don't even need a DBAPI to be available.
39
+
40
+ Calls to context.execute() here emit the given string to the
41
+ script output.
42
+
43
+ """
44
+ url = config.get_main_option("sqlalchemy.url")
45
+ context.configure(
46
+ url=url,
47
+ target_metadata=target_metadata,
48
+ literal_binds=True,
49
+ dialect_opts={"paramstyle": "named"},
50
+ )
51
+
52
+ with context.begin_transaction():
53
+ context.run_migrations()
54
+
55
+
56
+ def do_run_migrations(connection: Connection) -> None:
57
+ context.configure(connection=connection, target_metadata=target_metadata)
58
+
59
+ with context.begin_transaction():
60
+ context.run_migrations()
61
+
62
+
63
+ async def run_async_migrations() -> None:
64
+ """In this scenario we need to create an Engine
65
+ and associate a connection with the context.
66
+ """
67
+
68
+ connectable = async_engine_from_config(
69
+ config.get_section(config.config_ini_section, {}),
70
+ prefix="sqlalchemy.",
71
+ poolclass=pool.NullPool,
72
+ )
73
+
74
+ async with connectable.connect() as connection:
75
+ await connection.run_sync(do_run_migrations)
76
+
77
+ await connectable.dispose()
78
+
79
+
80
+ def run_migrations_online() -> None:
81
+ """Run migrations in 'online' mode."""
82
+
83
+ asyncio.run(run_async_migrations())
84
+
85
+
86
+ db_engine = get_relational_engine()
87
+
88
+ print("Using database:", db_engine.db_uri)
89
+ # In case db_uri is a SQLAlchemy URL object, convert it to string
90
+ db_uri = (
91
+ db_engine.db_uri
92
+ if isinstance(db_engine.db_uri, str)
93
+ else db_engine.db_uri.render_as_string(hide_password=False)
94
+ )
95
+
96
+ config.set_section_option(
97
+ config.config_ini_section,
98
+ "SQLALCHEMY_DATABASE_URI",
99
+ db_uri,
100
+ )
101
+
102
+
103
+ if context.is_offline_mode():
104
+ print("OFFLINE MODE")
105
+ run_migrations_offline()
106
+ else:
107
+ run_migrations_online()
@@ -0,0 +1,26 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ ${upgrades if upgrades else "pass"}
23
+
24
+
25
+ def downgrade() -> None:
26
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,52 @@
1
+ """Enable delete for old tutorial notebooks
2
+
3
+ Revision ID: 1a58b986e6e1
4
+ Revises: 46a6ce2bd2b2
5
+ Create Date: 2025-12-17 11:04:44.414259
6
+
7
+ """
8
+
9
+ from typing import Sequence, Union
10
+
11
+ from alembic import op
12
+ import sqlalchemy as sa
13
+
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision: str = "1a58b986e6e1"
17
+ down_revision: Union[str, None] = "e1ec1dcb50b6"
18
+ branch_labels: Union[str, Sequence[str], None] = None
19
+ depends_on: Union[str, Sequence[str], None] = None
20
+
21
+
22
+ def change_tutorial_deletable_flag(deletable: bool) -> None:
23
+ bind = op.get_bind()
24
+ inspector = sa.inspect(bind)
25
+
26
+ if "notebooks" not in inspector.get_table_names():
27
+ return
28
+
29
+ columns = {col["name"] for col in inspector.get_columns("notebooks")}
30
+ required_columns = {"name", "deletable"}
31
+ if not required_columns.issubset(columns):
32
+ return
33
+
34
+ notebooks = sa.table(
35
+ "notebooks",
36
+ sa.Column("name", sa.String()),
37
+ sa.Column("deletable", sa.Boolean()),
38
+ )
39
+
40
+ tutorial_name = "Python Development with Cognee Tutorial 🧠"
41
+
42
+ bind.execute(
43
+ notebooks.update().where(notebooks.c.name == tutorial_name).values(deletable=deletable)
44
+ )
45
+
46
+
47
+ def upgrade() -> None:
48
+ change_tutorial_deletable_flag(True)
49
+
50
+
51
+ def downgrade() -> None:
52
+ change_tutorial_deletable_flag(False)
@@ -0,0 +1,33 @@
1
+ """Add pipeline run status
2
+
3
+ Revision ID: 1d0bb7fede17
4
+ Revises: 482cd6517ce4
5
+ Create Date: 2025-05-19 10:58:15.993314
6
+ """
7
+
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+
12
+ from cognee.infrastructure.databases.relational.get_relational_engine import get_relational_engine
13
+ from cognee.modules.pipelines.models.PipelineRun import PipelineRun, PipelineRunStatus
14
+
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = "1d0bb7fede17"
18
+ down_revision: Union[str, None] = "482cd6517ce4"
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = "482cd6517ce4"
21
+
22
+
23
+ def upgrade() -> None:
24
+ db_engine = get_relational_engine()
25
+
26
+ if db_engine.engine.dialect.name == "postgresql":
27
+ op.execute(
28
+ "ALTER TYPE pipelinerunstatus ADD VALUE IF NOT EXISTS 'DATASET_PROCESSING_INITIATED'"
29
+ )
30
+
31
+
32
+ def downgrade() -> None:
33
+ pass
@@ -0,0 +1,48 @@
1
+ """incremental_loading
2
+
3
+ Revision ID: 1daae0df1866
4
+ Revises: b9274c27a25a
5
+ Create Date: 2025-08-12 13:14:12.515935
6
+
7
+ """
8
+
9
+ from typing import Sequence, Union
10
+
11
+ from alembic import op
12
+ import sqlalchemy as sa
13
+ from sqlalchemy.ext.mutable import MutableDict
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision: str = "1daae0df1866"
17
+ down_revision: Union[str, None] = "b9274c27a25a"
18
+ branch_labels: Union[str, Sequence[str], None] = None
19
+ depends_on: Union[str, Sequence[str], None] = None
20
+
21
+
22
+ def _get_column(inspector, table, name, schema=None):
23
+ for col in inspector.get_columns(table, schema=schema):
24
+ if col["name"] == name:
25
+ return col
26
+ return None
27
+
28
+
29
+ def upgrade() -> None:
30
+ conn = op.get_bind()
31
+ insp = sa.inspect(conn)
32
+
33
+ # If column already exists skip migration
34
+ pipeline_status_column = _get_column(insp, "data", "pipeline_status")
35
+ if not pipeline_status_column:
36
+ op.add_column(
37
+ "data",
38
+ sa.Column(
39
+ "pipeline_status",
40
+ MutableDict.as_mutable(sa.JSON),
41
+ nullable=False,
42
+ server_default=sa.text("'{}'"),
43
+ ),
44
+ )
45
+
46
+
47
+ def downgrade() -> None:
48
+ op.drop_column("data", "pipeline_status")
@@ -0,0 +1,118 @@
1
+ """Add sync_operations table
2
+
3
+ Revision ID: 211ab850ef3d
4
+ Revises: 9e7a3cb85175
5
+ Create Date: 2025-09-10 20:11:13.534829
6
+
7
+ """
8
+
9
+ from typing import Sequence, Union
10
+
11
+ from alembic import op
12
+ import sqlalchemy as sa
13
+ from sqlalchemy.dialects import postgresql
14
+
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = "211ab850ef3d"
18
+ down_revision: Union[str, None] = "45957f0a9849"
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = None
21
+
22
+
23
+ def upgrade() -> None:
24
+ # ### commands auto generated by Alembic - please adjust! ###
25
+
26
+ # Check if table already exists (it might be created by Base.metadata.create_all() in initial migration)
27
+ connection = op.get_bind()
28
+ inspector = sa.inspect(connection)
29
+
30
+ if op.get_context().dialect.name == "postgresql":
31
+ syncstatus_enum = postgresql.ENUM(
32
+ "STARTED", "IN_PROGRESS", "COMPLETED", "FAILED", "CANCELLED", name="syncstatus"
33
+ )
34
+ syncstatus_enum.create(op.get_bind(), checkfirst=True)
35
+
36
+ if "sync_operations" not in inspector.get_table_names():
37
+ if op.get_context().dialect.name == "postgresql":
38
+ syncstatus = postgresql.ENUM(
39
+ "STARTED",
40
+ "IN_PROGRESS",
41
+ "COMPLETED",
42
+ "FAILED",
43
+ "CANCELLED",
44
+ name="syncstatus",
45
+ create_type=False,
46
+ )
47
+ else:
48
+ syncstatus = sa.Enum(
49
+ "STARTED",
50
+ "IN_PROGRESS",
51
+ "COMPLETED",
52
+ "FAILED",
53
+ "CANCELLED",
54
+ name="syncstatus",
55
+ create_type=False,
56
+ )
57
+
58
+ # Table doesn't exist, create it normally
59
+ op.create_table(
60
+ "sync_operations",
61
+ sa.Column("id", sa.UUID(), nullable=False),
62
+ sa.Column("run_id", sa.Text(), nullable=True),
63
+ sa.Column(
64
+ "status",
65
+ syncstatus,
66
+ nullable=True,
67
+ ),
68
+ sa.Column("progress_percentage", sa.Integer(), nullable=True),
69
+ sa.Column("dataset_ids", sa.JSON(), nullable=True),
70
+ sa.Column("dataset_names", sa.JSON(), nullable=True),
71
+ sa.Column("user_id", sa.UUID(), nullable=True),
72
+ sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
73
+ sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
74
+ sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
75
+ sa.Column("total_records_to_sync", sa.Integer(), nullable=True),
76
+ sa.Column("total_records_to_download", sa.Integer(), nullable=True),
77
+ sa.Column("total_records_to_upload", sa.Integer(), nullable=True),
78
+ sa.Column("records_downloaded", sa.Integer(), nullable=True),
79
+ sa.Column("records_uploaded", sa.Integer(), nullable=True),
80
+ sa.Column("bytes_downloaded", sa.Integer(), nullable=True),
81
+ sa.Column("bytes_uploaded", sa.Integer(), nullable=True),
82
+ sa.Column("dataset_sync_hashes", sa.JSON(), nullable=True),
83
+ sa.Column("error_message", sa.Text(), nullable=True),
84
+ sa.Column("retry_count", sa.Integer(), nullable=True),
85
+ sa.PrimaryKeyConstraint("id"),
86
+ )
87
+ op.create_index(
88
+ op.f("ix_sync_operations_run_id"), "sync_operations", ["run_id"], unique=True
89
+ )
90
+ op.create_index(
91
+ op.f("ix_sync_operations_user_id"), "sync_operations", ["user_id"], unique=False
92
+ )
93
+ else:
94
+ # Table already exists, but we might need to add missing columns or indexes
95
+ # For now, just log that the table already exists
96
+ print("sync_operations table already exists, skipping creation")
97
+
98
+ # ### end Alembic commands ###
99
+
100
+
101
+ def downgrade() -> None:
102
+ # ### commands auto generated by Alembic - please adjust! ###
103
+
104
+ # Only drop if table exists (might have been created by Base.metadata.create_all())
105
+ connection = op.get_bind()
106
+ inspector = sa.inspect(connection)
107
+
108
+ if "sync_operations" in inspector.get_table_names():
109
+ op.drop_index(op.f("ix_sync_operations_user_id"), table_name="sync_operations")
110
+ op.drop_index(op.f("ix_sync_operations_run_id"), table_name="sync_operations")
111
+ op.drop_table("sync_operations")
112
+
113
+ # Drop the enum type that was created (only if no other tables are using it)
114
+ sa.Enum(name="syncstatus").drop(op.get_bind(), checkfirst=True)
115
+ else:
116
+ print("sync_operations table doesn't exist, skipping downgrade")
117
+
118
+ # ### end Alembic commands ###
@@ -0,0 +1,46 @@
1
+ """Add notebook table
2
+
3
+ Revision ID: 45957f0a9849
4
+ Revises: 9e7a3cb85175
5
+ Create Date: 2025-09-10 17:47:58.201319
6
+
7
+ """
8
+
9
+ from datetime import datetime, timezone
10
+ from uuid import uuid4
11
+ from typing import Sequence, Union
12
+
13
+ from alembic import op
14
+ import sqlalchemy as sa
15
+
16
+
17
+ # revision identifiers, used by Alembic.
18
+ revision: str = "45957f0a9849"
19
+ down_revision: Union[str, None] = "9e7a3cb85175"
20
+ branch_labels: Union[str, Sequence[str], None] = None
21
+ depends_on: Union[str, Sequence[str], None] = None
22
+
23
+
24
+ def upgrade() -> None:
25
+ bind = op.get_bind()
26
+ inspector = sa.inspect(bind)
27
+
28
+ if "notebooks" not in inspector.get_table_names():
29
+ # Define table with all necessary columns including primary key
30
+ op.create_table(
31
+ "notebooks",
32
+ sa.Column("id", sa.UUID, primary_key=True, default=uuid4), # Critical for SQLite
33
+ sa.Column("owner_id", sa.UUID, index=True),
34
+ sa.Column("name", sa.String(), nullable=False),
35
+ sa.Column("cells", sa.JSON(), nullable=False),
36
+ sa.Column("deletable", sa.Boolean(), default=True),
37
+ sa.Column("created_at", sa.DateTime(), default=lambda: datetime.now(timezone.utc)),
38
+ )
39
+
40
+
41
+ def downgrade() -> None:
42
+ bind = op.get_bind()
43
+ inspector = sa.inspect(bind)
44
+
45
+ if "notebooks" in inspector.get_table_names():
46
+ op.drop_table("notebooks")