Skip to content

feat(mcp): add compact search discovery results - #1515

Merged
phernandez merged 5 commits into
mainfrom
feat/686-compact-search
Sep 8, 2026
Merged

phernandez merged 5 commits into
mainfrom
feat/686-compact-search

Conversation

@phernandez

@phernandez phernandez commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Why

#686 reports excessive search response size when agents only need to discover relevant notes. JSON results can include both note content and a matched excerpt before the agent decides what to read.

Refs #686. This is the search-discovery slice; compact graph traversal remains separate.

What Changed

Add opt-in search_notes(compact=True) for both JSON and text output, including all-project searches. It omits content, matched_chunk, content_length, and content_truncated while preserving ranked identifiers, metadata, relation fields, temporal assertions, and pagination. Observation titles use their category and permalinks use their owning file path, so labels do not repeat source prose. Agents can read selected notes afterward using their stable identifiers.

Implementation Details

Apply a typed response projection after each project retrieval, before workspace qualification and account-wide merging. Normal responses remain unchanged and source response objects are not mutated. Compact observation read paths preserve case, spaces and extensions beneath the workspace/project prefix. The generated manual documents the parameter and the discovery/read workflow.

Testing

  • uv run pytest test-int/mcp/test_compact_search_integration.py tests/mcp/test_tool_search.py tests/mcp/tools/test_search_notes_multi_project.py -q --no-cov: 79 passed.
  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/mcp/test_compact_search_integration.py -q --no-cov: 4 passed.
  • Real MCP scenarios exercise project-scoped and all-project search, compare every retained field, read the selected note, and check text output omits excerpts. The long-note fixture's compact JSON is less than one-third the full JSON size; this is a fixture measurement, not a general token-saving claim.
  • just man-regen, just fast-check, and just doctor: passed.

Risks / Follow-ups

This reduces the model-visible MCP response, not API transfer or database retrieval work. It is not a hard token budget: titles and metadata can still be large. It does not add observation-summary levels or compact build_context responses, and does not change the default search output.

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez added this to the v0.24.0 milestone Sep 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T05:43:23.715677Z 6cc2d5d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 3cb9d8cda6

ℹ️ 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".

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

Copy link
Copy Markdown
Member Author

@codex review

Updated the tool signature contract to include the intentional compact parameter. All 5 contract tests and just typecheck pass. Please review the latest head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b80c4a5229

ℹ️ 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".

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

Copy link
Copy Markdown
Member Author

@codex review

@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: 209d9b0f11

ℹ️ 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/mcp/tools/search.py Resolved
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@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: db6eee92df

ℹ️ 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/mcp/tools/search.py Resolved
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 6cc2d5d66e

ℹ️ 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".

@phernandez
phernandez merged commit 7ce7e12 into main Sep 8, 2026
36 checks passed
@phernandez
phernandez deleted the feat/686-compact-search branch September 8, 2026 13:37
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.

1 participant