openclaw - 💡(How to fix) Fix Feature Request: SQLite FTS index for wiki_search to improve synthesis query performance [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#72717Fetched 2026-04-28 06:33:02
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Code Example

DEC-260426-02  exchange_status=lost  (Claude Code diagnostic discussion)
DEC-260426-03  exchange_status=lost  (wiki lint rule alignment)
DEC-260426-04  exchange_status=lost  (wiki-memory.db architecture decision)

---

source    | files
----------|------
sessions  | 139
memory    | 28
wiki      | 0     ← gap

---

-- Decisions with preserved conversations (survives compaction)
CREATE TABLE decisions (
    dec_id TEXT PRIMARY KEY,        -- DEC-YYMMDD-NN
    title TEXT NOT NULL,
    summary TEXT NOT NULL,
    exchange TEXT,                   -- original conversation, captured before compaction
    exchange_status TEXT NOT NULL,   -- preserved | lost | none
    origin TEXT DEFAULT 'conversation'  -- conversation | imported
);
CREATE VIRTUAL TABLE decisions_fts USING fts5(dec_id, title, summary, exchange);

-- Structured synthesis metadata (avoids parsing frontmatter YAML)
CREATE TABLE syntheses (
    synthesis_id TEXT PRIMARY KEY,
    title TEXT NOT NULL,
    status TEXT DEFAULT 'active',
    confidence REAL,
    source_ids TEXT               -- e.g. "wiki-memory:DEC-260408-10"
);

-- Provenance chain
CREATE TABLE claims (...);
CREATE TABLE evidence (...);
RAW_BUFFERClick to expand / collapse

Is your feature request related to a problem?

When the wiki vault grows (80+ synthesis pages), wiki_search scans Markdown files for matches. This works but becomes increasingly inefficient as an agent's knowledge base scales. Each search requires reading and parsing multiple .md files, consuming tool-call tokens and adding latency.

Additionally, session compaction and memory/main.sqlite are both lossy — compaction discards conversation detail, and the memory SQLite only indexes session transcripts and MEMORY.md (not wiki content). This means wiki is often the only durable layer that preserves decision context. When we need to trace why a decision was made, we have to pull the original conversation out of session files before compaction destroys it, then store it alongside the wiki. A structured, indexed wiki search layer would make this retrieval reliable instead of a race against compaction.

Describe the solution you'd like

Add an internal SQLite FTS5 index that wiki_search queries instead of scanning files. The index should auto-update when wiki_apply or other write operations modify synthesis pages.

Proposed behavior:

  • On wiki compile or wiki_apply, update the FTS index with the page's title + body
  • wiki_search queries the FTS index first, returns ranked results
  • Falls back to file scan if index is stale or missing

Real-world usage: our SQLite companion approach

We run a production OpenClaw instance (daily cron tasks, 5 Ghost CMS sites, Telegram delivery) with 90 synthesis pages, 28 decision records (DECs), and 59 claims. To work around wiki_search limitations and the compaction/memory loss problem, we built a companion SQLite database (wiki-memory.db, ~124 KB).

The compaction problem (real data loss)

Out of 28 decision records, 3 had their original conversation context destroyed by session compaction before we could preserve them:

DEC-260426-02  exchange_status=lost  (Claude Code diagnostic discussion)
DEC-260426-03  exchange_status=lost  (wiki lint rule alignment)
DEC-260426-04  exchange_status=lost  (wiki-memory.db architecture decision)

These decisions still have summaries, but the reasoning and back-and-forth that led to them is gone forever. We now capture the original exchange at DEC creation time into the companion DB, before compaction can run. The remaining 25 DECs are either preserved (10, with full conversation) or none (15, legacy imports that never had conversations).

The memory/main.sqlite gap

memory/main.sqlite indexes 139 session files + 28 memory files = 1841 chunks. But it contains zero wiki content:

source    | files
----------|------
sessions  | 139
memory    | 28
wiki      | 0     ← gap

So memory_search can find "what did we discuss about Ghost" in old sessions, but cannot find "what is our confirmed Ghost CMS operational rule" in wiki syntheses — unless you use corpus=all, which bridges via file scanning (not indexed).

DB schema that solved both problems

-- Decisions with preserved conversations (survives compaction)
CREATE TABLE decisions (
    dec_id TEXT PRIMARY KEY,        -- DEC-YYMMDD-NN
    title TEXT NOT NULL,
    summary TEXT NOT NULL,
    exchange TEXT,                   -- original conversation, captured before compaction
    exchange_status TEXT NOT NULL,   -- preserved | lost | none
    origin TEXT DEFAULT 'conversation'  -- conversation | imported
);
CREATE VIRTUAL TABLE decisions_fts USING fts5(dec_id, title, summary, exchange);

-- Structured synthesis metadata (avoids parsing frontmatter YAML)
CREATE TABLE syntheses (
    synthesis_id TEXT PRIMARY KEY,
    title TEXT NOT NULL,
    status TEXT DEFAULT 'active',
    confidence REAL,
    source_ids TEXT               -- e.g. "wiki-memory:DEC-260408-10"
);

-- Provenance chain
CREATE TABLE claims (...);
CREATE TABLE evidence (...);

Query comparison

TaskVia wiki toolsVia companion DB
Find all Ghost-related decisionswiki_search → scan → 3-5 wiki_get calls (~4000 tokens)SELECT * FROM decisions_fts WHERE decisions_fts MATCH 'Ghost' (1 exec, ~800 tokens)
Read one synthesiswiki_search + wiki_get (2 calls, ~1500 tokens)SELECT * FROM syntheses WHERE synthesis_id = ? (1 exec, ~800 tokens)
Which syntheses cite DEC-260408-10?Impossible without reading all 90 filesSELECT * FROM syntheses WHERE source_ids LIKE '%DEC-260408-10%'
Decisions in last 30 daysImpossible (no structured date field)SELECT * FROM decisions WHERE created_at > '2026-03-27'
Find lost conversationsImpossibleSELECT * FROM decisions WHERE exchange_status = 'lost'

Token savings estimate

With ~3 wiki queries per day, the companion DB saves ~4200 input tokens/day (~756K tokens over 6 months). The real value is fewer tool-call round-trips and cleaner context windows.

Additional context

  • SQLite FTS5 is zero-dependency on Linux/macOS (bundled with Python and Node sqlite3)
  • The memory/main.sqlite already uses this pattern for session transcript search — but it does not index wiki content, creating a gap
  • Wiki pages remain the source of truth; the index is a read-optimized cache
  • memory_search(corpus=all) bridges wiki into memory search via corpus-supplement, but uses file scanning rather than indexed search
  • Vault size at which this matters: ~50+ synthesis pages with active agent querying
  • The compaction + memory loss problem makes wiki the critical durable knowledge layer, which further motivates efficient wiki search

extent analysis

TL;DR

Implement an internal SQLite FTS5 index for wiki search to improve efficiency and reduce latency.

Guidance

  • Create a virtual table using FTS5 to index wiki page titles and bodies, allowing for efficient querying.
  • Update the index automatically when wiki pages are modified through wiki_apply or other write operations.
  • Modify wiki_search to query the FTS index first, falling back to file scanning if the index is stale or missing.
  • Consider implementing a companion database to store decision records and synthesis metadata, as demonstrated in the provided example.

Example

CREATE VIRTUAL TABLE wiki_index USING fts5(title, body);

This creates a virtual table wiki_index that can be used for efficient full-text searching of wiki page titles and bodies.

Notes

The proposed solution relies on SQLite FTS5, which is a zero-dependency feature on Linux/macOS. The wiki pages remain the source of truth, and the index is a read-optimized cache.

Recommendation

Apply the workaround by implementing the internal SQLite FTS5 index for wiki search, as it addresses the efficiency and latency issues associated with the current file-scanning approach.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature Request: SQLite FTS index for wiki_search to improve synthesis query performance [1 participants]