Skip to content

feat(#317): SQLite knowledge graph storage (schema v7) - #332

Merged
ajianaz merged 2 commits into
developfrom
feat/v020-317-graph-storage
Jun 14, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/v020-317-graph-storage

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #317

Changes

Schema v7

  • graph_nodes (id, label, entity_type, properties_json, memory_id, created_at)
  • graph_edges (id, source_id, target_id, relation, weight, created_at)
  • Indexes on label, source_id, target_id

GraphStore (crates/uteke-core/src/graph.rs)

  • upsert_node() — get-or-create by label (case-insensitive)
  • add_edge() — INSERT OR IGNORE (idempotent, logs duplicates)
  • find_node() / get_node() — lookup by label or ID
  • neighbors() — outgoing edges via BFS up to depth N
  • find_path() — shortest path via BFS with parent tracking
  • query_relation() — (source, edge, target) triples
  • all_nodes() / all_edges() / stats()

CLI: uteke graph

uteke graph nodes [--entity-type TYPE]
uteke graph edges [--relation REL]
uteke graph neighbors <label> [--depth N]
uteke graph path <source> <target> [--max-depth N]
uteke graph query <relation>
uteke graph stats

All support --json output.

Backward compatible

Tests

  • cargo test --workspace ✅ (162 passed, 5 ignored)
  • 16 graph tests (upsert, edge, find, neighbors, path, query, stats)
  • cargo clippy --workspace -- -D warnings ✅
  • cargo fmt --all ✅

ajianaz added 2 commits June 14, 2026 12:25
- Schema v7: graph_nodes + graph_edges tables
- GraphStore: upsert_node, add_edge, find_node, neighbors, find_path
- BFS pathfinding with parent tracking
- query_relation: (source, edge, target) triples
- stats: node/edge count, relation types
- 16 graph tests
- Foreign keys enabled (PRAGMA foreign_keys=ON)
- Backward compatible: relationship metadata system preserved

Part 1 of #317 — CLI + remember integration next.
- CLI: `uteke graph nodes/edges/neighbors/path/query/stats`
- Human-readable + JSON output for all subcommands
- BFS pathfinding with node labels
- GraphStore accessible via uteke.graph_store()
- Store.conn made pub for graph access

Closes #317
pub struct GraphPath {
pub nodes: Vec<GraphNode>,
pub edges: Vec<GraphEdge>,
pub total_weight: f64,
}

/// Get or create a node by label. Returns node ID.
/// Idempotent — if a node with the same label exists, returns its ID.
5 => self.migrate_v4_to_v5()?,
// v6: Content type column (text vs json)
6 => self.migrate_v5_to_v6()?,
// v7: Knowledge graph tables (graph_nodes, graph_edges)
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (3)

  • crates/uteke-core/src/memory/schema.rs:164 — The migration dispatcher maps schema version 6 to self.migrate_v5_to_v6()?, and version 7 to self.migrate_v6_to_v7()?. For an existing database currently at version 6, the match will execute the 6 arm, rerun the v5→v6 migration, and never call the new v6→v7 migration. As a result, upgraded installs can remain on schema 6 without graph_nodes/graph_edges, while fresh installs work because INIT_SCHEMA_SQL already creates the tables.
  • crates/uteke-core/src/graph.rs:225 — The new find_path API documents and returns total_weight, but the implementation uses plain BFS over outgoing edges and stops at the first time the target is reached. BFS minimizes number of hops, not accumulated edge.weight. This can return a more expensive path even though weights are surfaced to callers, e.g. a direct edge with weight 100 will beat a two-hop path totaling 2.0.
  • crates/uteke-core/src/graph.rs:195 — In upsert_node, once a case-insensitive label match is found, the code only conditionally updates memory_id and immediately returns the existing id. The entity_type parameter is ignored on that path, so calling upsert_node("Alice", Some("person"), ...) after an earlier upsert_node("Alice", None, ...) leaves the stored node without the requested type.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit a1378fb into develop Jun 14, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/v020-317-graph-storage branch June 14, 2026 05:42
ajianaz added a commit that referenced this pull request Aug 13, 2026
* feat(#317): graph core — schema v7, GraphStore, BFS pathfinding

- Schema v7: graph_nodes + graph_edges tables
- GraphStore: upsert_node, add_edge, find_node, neighbors, find_path
- BFS pathfinding with parent tracking
- query_relation: (source, edge, target) triples
- stats: node/edge count, relation types
- 16 graph tests
- Foreign keys enabled (PRAGMA foreign_keys=ON)
- Backward compatible: relationship metadata system preserved

Part 1 of #317 — CLI + remember integration next.

* feat(#317): graph CLI — uteke graph subcommand + GraphStore accessor

- CLI: `uteke graph nodes/edges/neighbors/path/query/stats`
- Human-readable + JSON output for all subcommands
- BFS pathfinding with node labels
- GraphStore accessible via uteke.graph_store()
- Store.conn made pub for graph access

Closes #317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: SQLite graph storage — optional knowledge graph mode

2 participants