Add global knowledge base with RAG search

- KB module: fastembed (AllMiniLML6V2) for CPU embedding, SQLite for
  vector storage with brute-force cosine similarity search
- Chunking by ## headings, embeddings stored as BLOB in kb_chunks table
- API: GET/PUT /api/kb for full-text read/write with auto re-indexing
- Agent tools: kb_search (top-5 semantic search) and kb_read (full text)
  available in both planning and execution phases
- Frontend: Settings menu in sidebar footer, KB editor as independent
  view with markdown textarea and save button
- Also: extract shared db_err/ApiResult to api/mod.rs, add context
  management design doc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 08:15:50 +00:00
parent 1aa81896b5
commit d9d3bc340c
19 changed files with 2283 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
mod api;
mod agent;
mod db;
mod kb;
mod llm;
mod exec;
mod timer;
@@ -15,6 +16,7 @@ pub struct AppState {
pub db: db::Database,
pub config: Config,
pub agent_mgr: Arc<agent::AgentManager>,
pub kb: Option<Arc<kb::KbManager>>,
}
#[derive(Debug, Clone, serde::Deserialize)]
@@ -56,9 +58,22 @@ async fn main() -> anyhow::Result<()> {
let database = db::Database::new(&config.database.path).await?;
database.migrate().await?;
// Initialize KB manager
let kb_arc = match kb::KbManager::new(database.pool.clone()) {
Ok(kb) => {
tracing::info!("KB manager initialized");
Some(Arc::new(kb))
}
Err(e) => {
tracing::warn!("KB manager init failed (will retry on use): {}", e);
None
}
};
let agent_mgr = agent::AgentManager::new(
database.pool.clone(),
config.llm.clone(),
kb_arc.clone(),
);
timer::start_timer_runner(database.pool.clone(), agent_mgr.clone());
@@ -67,6 +82,7 @@ async fn main() -> anyhow::Result<()> {
db: database,
config: config.clone(),
agent_mgr: agent_mgr.clone(),
kb: kb_arc,
});
let app = Router::new()