second-brain-api 0.10.0

HTTP API server for second-brain: REST endpoints for recall, remember, and ingest
Documentation
pub mod associate;
pub mod eval;
pub mod heap;
pub mod ingest;
pub mod maintenance;
pub mod mentions;
pub mod near_duplicates;
pub mod repairs;
pub mod routes;
pub mod watcher;

use std::sync::{Arc, RwLock};

use second_brain_core::embedding::Embedder;
use second_brain_core::index::Indexes;
use second_brain_core::machine::MachineIdentity;
use second_brain_core::maintenance::MaintenanceSummary;
use second_brain_core::retrieval::{Reranker, RetrievalTunables};
use second_brain_core::sqlite_store::SqliteStore;
use second_brain_core::store::StoreAdmin;

pub struct AppState {
    pub store: Arc<dyn StoreAdmin>,
    /// Same store as `store`: Retriever::candidates and the outbox drain need
    /// the concrete SqliteStore, which the trait object cannot provide.
    pub sqlite: Arc<SqliteStore>,
    /// A read-only `Indexes` handle shared by every recall call; searches take
    /// the `RwLock` read side, which does not block other readers. The drain
    /// loop owns a separate read-write `Indexes` and only reaches into this
    /// lock's write side briefly, to call `reload_view` after persisting.
    /// None when index open/rebuild failed; recall then uses the legacy engine.
    pub indexes: Option<Arc<RwLock<Indexes>>>,
    pub reranker: Option<Arc<Reranker>>,
    pub tunables: RetrievalTunables,
    pub embedder: Option<Arc<Embedder>>,
    pub machine: MachineIdentity,
    /// The most recent repair, scheduled or requested; `/v1/status` reports
    /// it without recomputing anything.
    pub maintenance: Arc<RwLock<Option<MaintenanceSummary>>>,
    /// Hands a repair request to the drain thread, the one owner of the
    /// writable indexes, so an on-demand repair never races the scheduled
    /// one. None when the indexes failed to open and no drain thread exists;
    /// the repair route then runs against the store alone.
    pub repair_tx: Option<std::sync::mpsc::Sender<maintenance::RepairRequest>>,
    /// `[distill] near_duplicate_threshold`: the default for the
    /// near-duplicates route and the threshold status counts at.
    pub near_duplicate_threshold: f32,
    /// The last near-duplicate count at `near_duplicate_threshold`, from a
    /// listing or a repair. Counting is a grouping pass over every live
    /// distillate (seconds on the Pi), so status reports this instead.
    pub near_duplicates: Arc<RwLock<Option<near_duplicates::NearDupCount>>>,
}

/// Extract the entity names a query refers to, using the same gazetteer
/// extraction the ingest path applies to transcripts. Matching extractors on
/// both sides is what lets query entities resolve to stored entity ids, so the
/// graph term in recall is conditioned on the query rather than raw
/// connectedness. Shared by the live recall route and the eval harness so both
/// measure the same ranking.
pub fn link_query_entities(text: &str) -> Vec<String> {
    second_brain_adapters::claude_code::extract_entities(text)
        .into_iter()
        .map(|e| e.name)
        .collect()
}