1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! Brainwires Storage — backend-agnostic persistent storage primitives for
//! the Brainwires Agent Framework.
//!
//! This crate provides the generic abstractions: a `StorageBackend` trait,
//! the per-backend connections (`LanceDatabase`, `PostgresDatabase`, ...),
//! embeddings (`CachedEmbeddingProvider`), BM25 keyword search, file
//! chunking, and image metadata types. Domain-shaped stores
//! (`ConversationStore`, `MessageStore`, `PlanStore`, `LockStore`, ...) and
//! the tiered hot/warm/cold memory orchestration moved out:
//!
//! - **`brainwires-memory`** — `MessageStore`, `SummaryStore`, `FactStore`,
//! `MentalModelStore`, `TierMetadataStore`, `TieredMemory`.
//! - **`brainwires-cli` `crate::storage`** — `ConversationStore`,
//! `TaskStore` / `AgentStateStore`, `PlanStore`, `TemplateStore`,
//! `LockStore`, `ImageStore`, `PersistentTaskManager`.
//!
//! # Unified Database Layer ([`databases`] module)
//!
//! One struct per database, one shared connection, implementing one or both
//! of the core traits:
//!
//! - [`StorageBackend`] — generic CRUD + vector search for domain stores
//! - [`VectorDatabase`](databases::traits::VectorDatabase) — RAG embedding storage
//! with hybrid search
//!
//! ### Database backends
//!
//! | Backend | Struct | `StorageBackend` | `VectorDatabase` | Feature |
//! |---------|--------|:---:|:---:|---------|
//! | LanceDB | `LanceDatabase` | YES | YES | `lance-backend` (default) |
//! | PostgreSQL | `PostgresDatabase` | YES | YES | `postgres-backend` |
//! | MySQL | `MySqlDatabase` | YES | NO | `mysql-backend` |
//! | SurrealDB | `SurrealDatabase` | YES | YES | `surrealdb-backend` |
//! | Qdrant | `QdrantDatabase` | NO | YES | `qdrant-backend` |
//! | Pinecone | `PineconeDatabase` | NO | YES | `pinecone-backend` |
//! | Milvus | `MilvusDatabase` | NO | YES | `milvus-backend` |
//! | Weaviate | `WeaviateDatabase` | NO | YES | `weaviate-backend` |
//! | NornicDB | `NornicDatabase` | NO | YES | `nornicdb-backend` |
//!
//! Backends that implement both traits share a single connection — construct
//! once, wrap in `Arc`, and pass to both domain stores and RAG subsystem.
//!
//! # Core Infrastructure
//!
//! - **`FastEmbedManager`** — text embeddings via FastEmbed ONNX model
//! (all-MiniLM-L6-v2, 384 dimensions)
//! - **`CachedEmbeddingProvider`** — LRU-cached embedding provider (1000 entries)
//! - **`BM25Search`** — keyword search via Tantivy
//! - **`FileContextManager`** — file chunking / context primitives
//!
//! # Image Types
//!
//! - **`ImageFormat`**, **`ImageMetadata`**, **`ImageSearchRequest`**,
//! **`ImageSearchResult`**, **`ImageStorage`** — pure types reused by
//! the `ImageStore` that lives in `brainwires-cli::storage`.
//!
//! # Feature Flags
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `native` | Yes | LanceDB backend + FastEmbed + file context + native primitives |
//! | `lance-backend` | Yes (via `native`) | LanceDB embedded vector database |
//! | `postgres-backend` | No | PostgreSQL + pgvector |
//! | `mysql-backend` | No | MySQL / MariaDB |
//! | `surrealdb-backend` | No | SurrealDB with native MTREE vector search |
//! | `qdrant-backend` | No | Qdrant vector search |
//! | `pinecone-backend` | No | Pinecone cloud vectors |
//! | `milvus-backend` | No | Milvus vectors |
//! | `weaviate-backend` | No | Weaviate search engine |
//! | `nornicdb-backend` | No | NornicDB graph + vector |
//! | `wasm` | No | WASM-compatible (pure types only) |
// Re-export core types
pub use brainwires_core;
// ── Always available (pure types/logic) ──────────────────────────────────
/// Structured error taxonomy. See [`StorageError`].
///
/// Public APIs on this crate return `anyhow::Result<T>` so backends don't
/// break across a trait rewrite; callers recover the typed variant via
/// `err.downcast_ref::<StorageError>()`.
pub use StorageError;
/// Image-storage type definitions (concrete `ImageStore` lives in `brainwires-cli`).
/// Unified database layer — one struct per database, shared connection,
/// implementing [`StorageBackend`](databases::traits::StorageBackend) and/or
/// [`VectorDatabase`](databases::traits::VectorDatabase).
/// BM25 keyword search using Tantivy. Used by Lance backend for hybrid
/// vector + keyword search; consumed by `brainwires-rag` and other
/// indexers.
/// Glob pattern matching utilities. Used by every database backend's
/// path/include filtering.
// Phase 9 moves:
// paths + file_context → brainwires-core (cross-cutting utilities, no storage internals)
// hnsw_wasm → deleted (zero consumers anywhere in the workspace)
/// Embedding provider for vector operations.
// ── Re-exports (always available) ────────────────────────────────────────
pub use BackendCapabilities;
pub use StorageBackend;
pub use record_get;
pub use ;
pub use LanceDatabase;
pub use ;
// ── Re-exports (native only) ─────────────────────────────────────────────
pub use ;
// FileChunk / FileContent / FileContextManager moved to brainwires-core in Phase 9.
/// Prelude module for convenient imports of the primitive surface.