fix(mcp): expose unknown search totals by phernandez · Pull Request #1069 · basicmachines-co/basic-memory · GitHub
Skip to content

fix(mcp): expose unknown search totals - #1069

Merged
phernandez merged 2 commits into
mainfrom
codex/issue-1068-search-total-exactness
Jul 16, 2026
Merged

fix(mcp): expose unknown search totals#1069
phernandez merged 2 commits into
mainfrom
codex/issue-1068-search-total-exactness

Conversation

@phernandez

@phernandez phernandez commented Jul 16, 2026

Copy link
Copy Markdown
Member

Why

Semantic and hybrid search intentionally use a probe row instead of a second vector retrieval, so total: 0 means unknown rather than no matches. Structured clients could not distinguish that sentinel from an exact zero, which made working pagination look broken.

Closes #1068.

What Changed

  • Added additive total_is_exact metadata to structured search responses.
  • Marked FTS, title, and permalink counts exact while vector and hybrid totals remain unknown.
  • Preserved the probe-row strategy and existing total: 0 compatibility value for semantic modes.
  • Propagated exactness through MCP JSON and account-wide aggregation, including partial-project failures.
  • Updated Rich and plain CLI pagination summaries to consume the explicit flag while retaining legacy payload behavior.

Implementation Details

SearchResponse defaults total_is_exact to true for compatibility with existing exact-count constructors. The HTTP router sets it from the retrieval mode. Multi-project MCP search only claims an exact aggregate when every project supplied an exact total; otherwise its aggregate is explicitly unknown. When an older API omits the new field, the typed client infers exactness from the outbound retrieval mode so legacy semantic responses remain unknown. No additional vector or hybrid retrieval is performed.

Testing

  • uv run pytest tests/mcp/clients/test_clients.py tests/schemas/test_search.py tests/api/v2/test_search_router.py tests/mcp/test_search_total_exactness.py tests/mcp/tools/test_search_notes_multi_project.py tests/cli/test_cli_tool_rich_output.py -q — 109 passed.
  • just fast-check — passed; type checking reported only the existing Python 3.14 asyncio deprecation warnings.
  • just doctor — passed.
  • just test-smoke — passed.
  • just fast-test — 4,278 passed and 41 skipped; one unrelated live OpenAI semantic-quality case failed because the configured provider returned HTTP 429 insufficient_quota.

Risks / Follow-ups

The response change is additive, existing clients can ignore the new field, and semantic retrieval cost and pagination behavior are unchanged. No follow-up is required.

Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a89dfb437

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/schemas/search.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez merged commit 4f2dda4 into main Jul 16, 2026
26 checks passed
@phernandez
phernandez deleted the codex/issue-1068-search-total-exactness branch July 16, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make unknown semantic and hybrid search totals explicit in structured responses

1 participant