← Back to library

永久记忆:SQLite FTS5 + LanceDB 混合检索

解决事实检索不准与 embedding 成本问题:SQLite 负责精确事实,LanceDB 负责语义召回,并用 TTL 分层控制记忆衰减。

REDDITDiscovered 2026-02-14Author u/adamb0mbNZ
Prerequisites
  • Can run SQLite + LanceDB locally and configure background cleanup jobs.
  • Able to edit retrieval pipeline and memory schema.
Steps
  1. Create structured facts table and FTS5 index for entity/key/value queries.
  2. Keep LanceDB for fuzzy recall, then merge + dedup results after FTS pass.
  3. Add memory tiers (permanent/stable/active/session/checkpoint) with periodic TTL cleanup.
  4. Extract ‘decision facts’ (chose X because Y) into permanent memory.
Commands
sqlite3 memory.db 'CREATE VIRTUAL TABLE IF NOT EXISTS facts_fts USING fts5(entity,key,value,source);'
npm i better-sqlite3 @lancedb/lancedb openai
openclaw gateway status
Verify

Factual questions return exact rows from SQLite, while semantic questions still retrieve relevant context chunks.

Caveats
  • Community pattern; exact chunking/TTL values need local tuning (需验证).
  • Embedding path still depends on provider latency/quotas.
Source attribution

This tip is aggregated from community/public sources and preserved with attribution.

Open original source ↗
Visit original post