Skip to content

feat(agent): hybrid BM25 full-text search tool for query/chat agent #233

Description

@sebastianbraun25

Problem

openkb query / openkb chat navigate the wiki purely via index.md one-line summaries plus
LLM-directed page reads (read_file, get_page_content). One-line summaries cannot surface facts
buried deep in a concept/entity/summary page body (a specific figure, a niche keyword, an exact
term). As the wiki grows past a few dozen pages, the agent increasingly misses pages whose
index.md summary doesn't happen to mention the exact term the user asked about, even though the
page body contains the answer.

This is a known limitation of the underlying "LLM Wiki" pattern OpenKB implements (see
Karpathy's original gist and
its comments): index-based navigation works well at moderate scale, but recall degrades for
buried details. The suggested mitigation is a hybrid retrieval strategy — union the
index-driven candidates with a full-text search result set, so recall can only improve, never
regress relative to index-only navigation.

Context

  • openkb query/openkb chat (openkb/agent/query.py) currently expose only read_file,
    get_page_content, and get_image as retrieval tools — no keyword/full-text search tool.
  • openkb's dependencies are pinned exactly and vetted deliberately (see pyproject.toml); adding
    a new indexing dependency (e.g. Whoosh, tantivy bindings) is a heavier ask than a small,
    dependency-free BM25 implementation over the wiki's Markdown files.

Vorschlag

Add a lightweight, dependency-free BM25 full-text index over concepts/, entities/, and
summaries/ wiki pages, exposed to the query/chat agent as a search_wiki(query) tool alongside
the existing index.md-driven navigation (hybrid retrieval — additive, not a replacement).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions