Skip to content

QMD memory backend searches all collections in index, not just managed onesΒ #10042

@jdvmi00

Description

@jdvmi00

Summary

When memory.backend = "qmd" is configured, OpenClaw creates and manages its own QMD index at ~/.openclaw/agents/main/qmd/xdg-cache/qmd/index.sqlite with proper XDG isolation. However, if the standalone qmd CLI has previously added collections to the same index (or if collections leak in from a shared config), memory_search queries will search all collections β€” not just the ones OpenClaw manages.

Current Behavior

  • OpenClaw's config (memory.qmd.paths: []) resolves to only memory-root, memory-alt, memory-dir, and sessions collections
  • But the QMD index file can contain additional collections (e.g., meetings, obsidian, projects) that were added externally
  • QmdMemoryManager.search() runs qmd query <text> --json -n <limit> with no collection filter (-c flag)
  • This means memory_search returns results from all collections in the index, including ones OpenClaw didn't create
  • With a large index (286+ files, 1900+ embeddings), the qmd query command frequently times out at the 4s default, falling back to the builtin SQLite backend

Expected Behavior

memory_search should only return results from collections that OpenClaw manages (default memory collections + configured paths + sessions).

Suggested Fix

Two complementary approaches:

1. Scope search queries to managed collections

In QmdMemoryManager.search(), pass -c flags for each managed collection, or use a combined collection filter if QMD supports it.

2. Clean up foreign collections on boot

In ensureCollections(), after ensuring managed collections exist, remove any collections from the index that are NOT in the resolved config. This prevents stale/foreign collections from accumulating.

Environment

  • OpenClaw: 2026.2.3-1
  • QMD: standalone CLI (bun-based, uses SQLite + sqlite-vec)
  • OS: macOS (Darwin arm64)

Reproduction

  1. Install standalone qmd and add collections: qmd collection add /path/to/docs --name extra-docs
  2. Configure OpenClaw with memory.backend = "qmd" and memory.qmd.paths: []
  3. Run memory_search for a topic that exists in the external collection
  4. Results from extra-docs will appear even though OpenClaw didn't configure it

The issue occurs because both the standalone QMD and OpenClaw's QMD instance can share the same index file (or collections can be manually added to the OpenClaw-managed index).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions