Skip to content

ADR-057: Replace sql.js with RVF native storage backend #1242

@ruvnet

Description

@ruvnet

Summary

Replace the 18MB sql.js WASM SQLite hard dependency with RuVector Format (RVF) across @claude-flow/shared, @claude-flow/memory, and @claude-flow/embeddings.

ADR: v3/implementation/adrs/ADR-057-rvf-native-storage-backend.md
Branch: feat/adr-057-rvf-storage-backend

Problem

  • sql.js is 18MB — the single largest hard dependency in the core install path
  • sql.js provides no vector indexing — uses brute-force O(n) cosine similarity
  • Adds 35s to Docker cold start and inflates images by ~18MB even after pruning

Proposed Solution

Replace sql.js with RVF (@ruvector/rvf), which provides:

Metric sql.js RVF
Package size 18MB WASM 52KB WASM / ~2MB native
Vector search O(n) brute-force O(log n) HNSW — 150x-12,500x faster
Quantization fp32 only fp16/int8/int4/binary — 2-8x memory savings
Crash safety Manual export/save Append-only (no WAL)
Progressive loading N/A 70% recall on first query

Migration

  • Automatic: Transparent migration on first access (legacy .db/.json.rvf)
  • Manual: ruflo migrate run --storage, ruflo migrate rollback --storage
  • Backward compatible: Legacy formats permanently readable; .bak files preserved
  • 3 formats supported: sql.js .db, better-sqlite3 .db, JSON .json

Implementation Phases

  • Phase 1 (Week 1-2): RvfBackend implementing IMemoryBackend interface
  • Phase 2 (Week 2-3): RvfEventLog implementing IEventStore in @claude-flow/shared
  • Phase 3 (Week 3): RvfEmbeddingCache for @claude-flow/embeddings
  • Phase 4 (Week 3-4): CLI migration commands (migrate status/run/rollback/validate --storage)
  • Phase 5 (Week 4): Move sql.js to optionalDependencies, update Docker images

Impact

  • -18MB from core install size
  • 150x-12,500x faster vector search
  • 2-8x memory reduction via quantization
  • Docker lite image: 324MB → ~306MB

Related

  • ADR-053: AgentDB v3 Controller Activation
  • ADR-054: RVF-Powered Plugin Marketplace
  • ADR-055: AgentDB Controller Bug Remediation
  • ADR-056: agentic-flow v3 Integration

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions