Skip to content

feat: implement storage layer (PRD-001) - #1

Merged
hurttlocker merged 1 commit into
mainfrom
feat/storage-layer
Feb 17, 2026
Merged

hurttlocker merged 1 commit into
mainfrom
feat/storage-layer

Conversation

@hurttlocker

Copy link
Copy Markdown
Owner

Summary

Implements the complete internal/store/ package per PRD-001.

What's Implemented

Core Files

  • store.go — Store interface, SQLiteStore struct, NewStore constructor with configurable DB path, batch size, and embedding dimensions
  • migrations.go — Schema creation for all 9 tables + FTS5 virtual table + sync triggers + metadata seeding
  • memory.go — Memory CRUD, batch insert (chunked by configurable batch size), soft delete, content deduplication via SHA-256 hash
  • facts.go — Fact CRUD with 8 fact types, confidence updates, reinforcement tracking, stale fact detection
  • embeddings.go — Embedding storage as BLOBs with configurable dimensions, brute-force cosine similarity search
  • events.go — Append-only event log (6 event types), FTS5 search with BM25 ranking + snippets, database stats

Tables

Table Purpose
memories Core content with provenance, content_hash dedup, soft delete
memories_fts FTS5 index (porter unicode61), auto-synced via triggers
facts Extracted facts with confidence, decay rate, reinforcement
embeddings Vector storage with configurable dimensions
recall_log Provenance chains (P1)
memory_events Differential memory / event log (P1)
snapshots Point-in-time restore (P2, schema only)
lenses Context-dependent views (P2, schema only)
meta Schema version, embedding dimensions, timestamps

Design Decisions (per Q's review)

  • Embedding dimensions: Configurable with 384 default, stored in meta table
  • FTS5 tokenizer: porter unicode61 hardcoded for MVP
  • Batch size: 500 default, exposed as config option
  • Vacuum: Manual only — Vacuum() method, never auto-vacuum
  • WAL mode: Enabled by default
  • Pure Go: modernc.org/sqlite (no CGO)

Test Results (33 tests, all passing)

  • All CRUD operations for memories and facts
  • FTS5 search: keyword, boolean (AND/OR/NOT), quoted phrases, snippets
  • Embedding storage and cosine similarity search with thresholds
  • Batch insert performance: ~13-22K inserts/sec
  • Event logging, stats, stale facts, deduplication, vacuum
  • go build, go test, go vet all pass clean

Checklist

  • go build ./... passes
  • go test ./... passes (33/33)
  • go vet ./... passes
  • No external deps except modernc.org/sqlite
  • References PRD-001 spec completely

Implements the complete internal/store/ package per PRD-001:

Core files:
- store.go — Store interface, SQLiteStore struct, NewStore constructor, config
- migrations.go — Schema creation for all 9 tables + FTS5 + triggers + metadata
- memory.go — Memory CRUD, batch insert, soft delete, content dedup (SHA-256)
- facts.go — Fact CRUD, confidence updates, reinforcement, stale fact detection
- embeddings.go — Embedding storage (BLOB), brute-force cosine similarity search
- events.go — Append-only event log, FTS5 search with BM25 + snippets, stats

Tables created:
- memories (with content_hash dedup, soft delete)
- memories_fts (FTS5 with porter unicode61 tokenizer, auto-sync triggers)
- facts (8 fact types, confidence decay, reinforcement tracking)
- embeddings (configurable dimensions, stored in meta table)
- recall_log (provenance chains)
- memory_events (differential memory, 6 event types)
- snapshots (point-in-time restore)
- lenses (context-dependent views)
- meta (schema version, embedding dimensions, timestamps)

Design decisions per Q's review:
- Embedding dimensions: configurable, 384 default, stored in meta table
- FTS5 tokenizer: porter unicode61 hardcoded (Phase 2: configurable)
- Batch size: 500 default, exposed as config option
- Vacuum: manual only via Vacuum() method
- WAL mode enabled by default
- Pure Go SQLite via modernc.org/sqlite (no CGO)

Test coverage (33 tests):
- All CRUD operations for memories and facts
- FTS5 search: keyword, boolean (AND/OR), quoted phrases, snippets
- Embedding storage and cosine similarity search
- Batch insert performance (100: ~13K/sec, 500: ~22K/sec, 1000: ~16K/sec)
- Event logging, stats, stale fact detection, deduplication, vacuum
@hurttlocker
hurttlocker merged commit 5b9008e into main Feb 17, 2026
1 check passed
@hurttlocker
hurttlocker deleted the feat/storage-layer branch February 17, 2026 05:38
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.

1 participant