Skip to content

search_notes returns an empty result set on a never-indexed project, indistinguishable from "no such note" #1534

Description

@groksrc

Summary

On a project that has never been indexed, search_notes returns an empty result set for every query — including a stopword-grade term like "the" — and says nothing about the index being empty. From inside an MCP session that is indistinguishable from an honest "no such note."

That matters because "search before creating" is the standing rule in most agent workspaces. When search cannot fail loudly, that check passes vacuously: the agent searches, sees nothing, and concludes the note does not exist. It is also the state of every fresh install before the first index pass, so it is the first thing a new user hits.

Reported by a user running a ~24k-file local knowledge base across a bunch of agent workspaces. One of their machines had bm installed and never indexed, and it was the machine most of the workspaces booted from. Neither they nor their agents noticed for weeks — the agents just grepped the tree and carried on.

Reproduce

  1. Install Basic Memory on a machine with notes on disk, and never run an index pass (last_indexed_at IS NULL).
  2. From an MCP session, call search_notes(query="the", project="<project>").
  3. Result: results: [], total: 0, with the standard "No results found for 'the' … Try broader or different terms" copy.
  4. Expected: something that names the state — files are present, the index was never built.

Why it happens

_format_search_markdown in src/basic_memory/mcp/tools/search.py:377-400 deliberately assumes an empty result means "no match for this query," not "empty knowledge base":

# Empty search is usually "no match for this query," not "empty knowledge base," so we
# do not repeat the first-note offer here (that would nag established users). Point at
# recent_activity, which owns the getting-started guidance when the base is truly empty.

That assumption is right for an indexed project and wrong for a never-indexed one, and nothing on the path distinguishes the two. The zero-results branch at search.py:1480-1486 only logs and returns the empty response as normal.

The handoff to recent_activity does not rescue it either: recent_activity does not consult readiness, so on a never-indexed project it is empty for the same reason. The two surfaces agree, and are both wrong together.

The signal already exists

#1414 added exactly what is needed and wired it into the CLI only:

  • Project.last_indexed_at (models/project.py:76-82) — "the one durable bit that separates 'never indexed' from 'indexed and idle'. Every other readiness signal is a count, and a count of zero cannot tell 'nothing to do' from 'nothing was ever started'."
  • ProjectIndexPhase.NEVER_INDEXED and ProjectIndexReadiness.describe() (schemas/project_readiness.py:112-143), which already renders "N files present, not yet indexed — run 'bm project index <name>'".
  • report_project_readiness (cli/commands/command_utils.py:102) renders it for bm project add / bm status.

grep -rn "last_indexed_at" src/basic_memory/mcp/ returns nothing. The MCP surface — the one agents actually read through — never asks.

This is the same class of bug as #1414, one surface over: #1414 fixed vacuous readiness on the CLI, this is vacuous negative results on MCP.

Suggested fix

When a search returns zero results, check project readiness before formatting the miss. If the phase is NEVER_INDEXED, say so instead of reporting a negative — reuse ProjectIndexReadiness.describe() so the wording cannot drift from bm status. Roughly:

Search returned no results because project '' has never been indexed (N files present on disk). This is not a negative result — run bm project index <name>.

Notes on scope:

Filed at b04d1b6d.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds reviewA human maintainer needs to look at this issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions