Skip to main content

cognee_database/
lib.rs

1//! Relational metadata persistence (SeaORM/SQLite) for ingestion, search history, and deletion.
2
3mod connection;
4mod conversions;
5pub mod entities;
6pub mod migrator;
7pub mod ops;
8pub mod pipelines;
9pub mod sync;
10mod traits;
11mod types;
12pub mod uuid_hex;
13
14// Re-export tutorial seeder for use by cognee-http-server (which can't depend on cognee-lib).
15pub use ops::tutorial_seeder::{
16    TUTORIAL_BASICS_ID, TUTORIAL_PYTHON_DEV_ID, seed_tutorials_if_first_call,
17};
18
19pub use connection::{connect, initialize};
20
21/// Map the active SeaORM backend to a `cognee.db.system` string
22/// matching the values used by the vector / graph adapters.
23///
24/// The tag values mirror Python's observability layer
25/// (`cognee/modules/observability/tracing.py`) and the
26/// `cognee.db.system` attribute exposed by every relational op span.
27pub fn database_system_label(db: &sea_orm::DatabaseConnection) -> &'static str {
28    use sea_orm::{ConnectionTrait, DatabaseBackend};
29    match db.get_database_backend() {
30        DatabaseBackend::Sqlite => "sqlite",
31        DatabaseBackend::Postgres => "postgres",
32        DatabaseBackend::MySql => "mysql",
33    }
34}
35pub use ops::checkpoint::{CheckpointStore, SeaOrmCheckpointStore};
36pub use pipelines::sea_orm_impl::SeaOrmPipelineRunRepository;
37pub use pipelines::{
38    NoopPipelineRunRepository, PipelineRunRepository, PipelineRunWithAttributionRow,
39};
40pub use sea_orm::DatabaseConnection;
41pub use sync::{
42    SeaOrmSyncOperationRepository, SyncOperationRepository, SyncOperationRow, SyncOperationStatus,
43};
44pub use traits::{
45    AclDb, CostByModelRow, DatasetConfigDb, DatasetConfiguration, DatasetConfigurationPatch,
46    DeleteDb, IngestDb, Notebook, NotebookDb, NotebookUpdatePatch, SearchHistoryDb,
47    SessionLifecycleDb, SessionListFilters, SessionListPage, SessionRowWithStatus, SessionStats,
48};
49pub use types::{
50    DatabaseError, GraphEdge, GraphMetrics, GraphNode, PipelineRun, PipelineRunStatus,
51    SearchHistoryEntry, SearchHistoryEntryType, TaskRun,
52};
53
54// The `auth`, `permissions`, `UserDb`/`RoleDb`/`TenantDb`,
55// `SeaOrmUserAuthRepository`, `SeaOrmApiKeyRepository`, `ApiKey`, `AuthUser`,
56// `CreateUserPayload`, `UpdateUserPayload`, `ActiveUserWithApiKeyCount` items
57// moved to the closed `cognee-access-control` crate
58//. The `types` module deliberately remains private —
59// closed callers reach `DatabaseError` via the top-level re-export above.