Expand description
Knowledge graph with SQLite persistence, FTS5 search, and smart recall.
Provides a complete knowledge graph layer on top of SQLite:
- Types:
GraphNode,GraphEdge,ScoredNode,GraphStats - Schema:
init_graph_schema— creates tables, FTS5, indexes - CRUD: node/edge insert, read, update, delete
- Search: FTS5 full-text search and dynamic filtering
- Recall:
smart_recall— composite scoring with recency, importance, access, FTS, graph boost - Traversal:
graph_neighbors(1-hop),related_nodes(BFS via recursive CTE) - Algorithms: pure-Rust CSR algorithms in
algo—pagerank(),connected_components(),label_propagation(),dijkstra(),jaccard_similarity() - Lifecycle:
decay_importance,tag_stale_nodes,compute_stats
All functions take &rusqlite::Connection — no hardcoded paths.
use rusqlite::Connection;
use llm_kernel::graph::{init_graph_schema, upsert_node, smart_recall, GraphNode};
let conn = Connection::open_in_memory().unwrap();
init_graph_schema(&conn).unwrap();
upsert_node(&conn, &GraphNode {
id: "rust-ownership".into(),
node_type: "concept".into(),
title: "Rust Ownership Model".into(),
body: "Ownership, borrowing, and lifetimes...".into(),
tags: vec!["rust".into(), "memory-safety".into()],
projects: vec!["my-project".into()],
agents: vec![],
created: "2026-01-01T00:00:00Z".into(),
updated: "2026-01-01T00:00:00Z".into(),
importance: 0.8,
access_count: 0,
accessed_at: String::new(),
}).unwrap();
let results = smart_recall(&conn, Some("my-project"), Some("ownership"), 5).unwrap();
for scored in &results {
println!("{:.2} — {}", scored.score, scored.node.title);
}Re-exports§
pub use async_pool::AsyncPoolGraph;pub use algo::CsrGraph;pub use algo::LABEL_PROPAGATION_ITERS;pub use algo::PAGERANK_DAMPING;pub use algo::PAGERANK_EPS;pub use algo::PAGERANK_ITERS;pub use algo::SHORTEST_PATH_W_MIN;pub use algo::adamic_adar;pub use algo::common_neighbors;pub use algo::connected_components;pub use algo::dijkstra;pub use algo::jaccard_similarity;pub use algo::label_propagation;pub use algo::label_propagation_default;pub use algo::link_prediction;pub use algo::pagerank;pub use algo::pagerank;pub use algo::pagerank_default;pub use algo::pagerank_scores;pub use algo::shortest_path;pub use algo::shortest_path_ids;pub use backend::GraphBackend;pub use backend::SqliteGraph;pub use dedup::find_duplicate;pub use dedup::upsert_node_dedup;pub use lifecycle::compute_stats;pub use lifecycle::decay_importance;pub use lifecycle::tag_stale_nodes;pub use lifecycle::touch_node;pub use lifecycle::touch_nodes;pub use recall::smart_recall;pub use schema::GRAPH_SCHEMA_VERSION;pub use schema::init_graph_schema;pub use schema::migrate_graph;pub use schema::schema_version;pub use search::query_nodes;pub use search::search_nodes;pub use store::append_edge;pub use store::delete_edge;pub use store::delete_node;pub use store::read_edges;pub use store::read_node;pub use store::read_nodes;pub use store::upsert_node;pub use traversal::build_graph;pub use traversal::graph_neighbors;pub use types::Graph;pub use types::GraphEdge;pub use types::GraphNode;pub use types::GraphNodeSummary;pub use types::GraphStats;pub use types::ScoredNode;pub use types::validate_uuid;pub use cjk::search_nodes_cjk;pub use cjk::segment_cjk;pub use pg::PgGraph;
Modules§
- algo
- Graph algorithms operating on an in-memory CSR snapshot.
- async_
graph - Async wrappers for the knowledge graph.
- async_
pool - Multi-connection async pool for the knowledge graph.
- backend
- Backend-agnostic graph trait and SQLite implementation.
- cjk
- CJK-aware graph search (Rust-side segmentation; no schema change). CJK-aware graph search (Rust-side segmentation, no schema change).
- dedup
- Node deduplication: prevent duplicate nodes by title within a time window.
- lifecycle
- Node lifecycle: access tracking, importance decay, stale tagging, and stats.
- pg
- PostgreSQL
GraphBackend(featuregraph-pg). PostgreSQLGraphBackend(graph-pgfeature). - recall
- Smart recall with composite scoring and graph boost.
- schema
- Schema initialization for the knowledge graph SQLite database.
- search
- FTS5 full-text search for knowledge graph nodes.
- store
- Node and edge CRUD operations.
- traversal
- Graph traversal: 1-hop neighbors and BFS via recursive CTEs.
- types
- Core types for the knowledge graph.