Repository navigation
Closed
Description
Context and Motivation
NodeSpace needs a semantic search capability to enable Claude Code and other AI agents to find relevant nodes based on meaning, not just keywords. This requires:
- Embeddings storage: Vector representations of node content for semantic similarity
- Multi-model support: Different embedding models for different use cases (accuracy vs speed)
- Intelligent embeddability: Not all nodes should be embedded individually - some contribute to parent embeddings
- Efficiency: Embed only when content changes, debounce rapid edits, background processing
This issue implements the backend embeddings system that will later be used by MCP semantic search (Issue #2).
Test Baseline (Session Start)
Recorded on 2025-11-21 at session start:
- Test Files: 3 failed | 69 passed | 22 skipped (94 total)
- Tests: 2 failed | 1425 passed | 22 skipped (1449 total)
- Failures:
index-stability-with-reordering.test.ts- Reordering children test failedsplit-pane-isolation.test.ts- Split pane isolation test failed
Note: These failures pre-exist and are not related to embeddings implementation.
Implementation Approach
1. Database Schema Changes
Create embeddings table:
CREATE TABLE embeddings (
id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
node_id TEXT NOT NULL REFERENCES node(id) ON DELETE CASCADE,
model_name TEXT NOT NULL DEFAULT 'all-MiniLM-L6-v2',
embedding_vector BLOB NOT NULL, -- F32 vector serialized
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
-- Composite unique constraint: one embedding per node per model
UNIQUE(node_id, model_name)
);
-- Index for lookups
CREATE INDEX idx_embeddings_node_model ON embeddings(node_id, model_name);Modify node table:
- Add
last_embedded_atcolumn for staleness tracking - Create index for finding stale nodes
Why separate table?
- Support multiple embedding models per node (future-proof)
- Keep node table clean and focused
- Easier to rebuild embeddings without touching core data
- Foreign key cascade handles cleanup automatically
2. Two-Level Embeddability System
Add to NodeBehavior trait:
get_embeddable_content()- Returns content if node should be embedded as a rootget_parent_contribution()- Returns content this node contributes to parent
Implementations:
- Text nodes: Always embeddable, always contribute full content
- Headers: Embeddable if they are roots with children, contribute title
- Tasks: Never embedded alone, never contribute to parent
- Dates: Never embedded, never contribute
3. Embeddings Service
Create EmbeddingsService:
- Generate embeddings using fastembed crate with all-MiniLM-L6-v2 model
- Store and retrieve embeddings from database
- Build embeddable content by combining node + children contributions
- Track staleness and identify nodes needing re-embedding
4. Background Embedding Job
Hourly background task:
- Find nodes that need re-embedding (stale or never embedded)
- Process with 30-second debounce per root
- Store in database with CASCADE cleanup on node deletion
Acceptance Criteria
-
embeddingstable created withnode_id,model_name,embedding_vector, timestamps -
embedding_vectorcolumn removed fromnodetable (if exists) -
last_embedded_atcolumn added tonodetable -
NodeBehaviortrait includesget_embeddable_content()andget_parent_contribution() - All node types (text, header, task, date) implement embeddability methods correctly
-
EmbeddingsServicecan generate embeddings usingall-MiniLM-L6-v2 -
EmbeddingsServicecan store and retrieve embeddings from database -
should_embed_node()correctly identifies embeddable roots (text nodes, headers with children) -
build_embeddable_content()combines node + children contributions recursively - Staleness detection finds nodes updated since last embedding with 30-second debounce
- Background job runs hourly and processes all stale embeddings
- Unit tests for embeddability logic (each node type)
- Integration tests for embedding generation and storage
- Integration tests for staleness tracking and background processing
Activity
Implement two-level embeddability system for semantic search (issue #573
Implement multi-model embeddings system with two-level embeddability (#…
Implement multi-model embeddings system with two-level embeddability (#…
Implement multi-model embeddings system with two-level embeddability (#…
Implement multi-model embeddings system with two-level embeddability (#…