Skip to content

Remove the read_note title-lookup paging loop #1958

Closed

Description

@phernandez

Background

read_note's title fallback (src/basic_memory/mcp/tools/read_note.py) walks up to _TITLE_LOOKUP_MAX_PAGES pages of title-search results looking for an exact title. The loop was added because bm25 ranked longer titles that repeat the query above the exact title, which could push the exact match past page 1.

#1957 (fixing #1956) makes title search sort an exact, case-insensitive title match first on both backends, so one page is enough.

Remaining case

On SQLite, lower() folds ASCII only, while read_note compares with str.casefold(). A non-ASCII title queried with different case (café notes for Café Notes) is not boosted. It can still land past page 1 when more than 10 fuzzy titles outrank it. Postgres lower() is Unicode-aware and is not affected.

Proposal

Replace the loop with a single title lookup, and delete _TITLE_LOOKUP_MAX_PAGES and test_read_note_title_lookup_stops_at_page_cap. Either accept the SQLite non-ASCII case-mismatch edge case, or close it in the search query instead of paging.

read_note is no longer a registered MCP tool; it stays in core because Basic Memory Cloud still imports it. If Cloud drops that import first, delete the module instead and close this issue.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8

Activity

  1. claude commented on Oct 29, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 22s —— View job


    Triage

    • Type: Enhancement (cleanup and simplification). I applied the enhancement label.
    • Component: MCP tools (read_note title fallback). It is not Cloud-specific, so no cloud label. Cloud's import of the module is a constraint, not the subject of the issue.
    • Priority: Low. Nothing is broken. fix(core): rank an exact title match first in title search #1957 already puts the exact title match first, so the paging loop is now redundant.
    • Complexity: Simple.
      • Replace the loop with one title lookup.
      • Delete _TITLE_LOOKUP_MAX_PAGES and test_read_note_title_lookup_stops_at_page_cap.
      • Keep 100% coverage.
    • Duplicates: I searched for similar issues and found none.

    Notes

    • The decision to make is how to handle the SQLite non-ASCII case-mismatch edge case (café notes vs Café Notes):
      • Accept it. This is the smallest change.
      • Close it in the search query, for example by matching on a casefolded title. That is better than paging, but it touches the search layer and needs a migration or an index-time column to be reliable on SQLite.
    • Which option you pick affects the scope, and it's not stated in the issue. I'd accept the edge case unless you've seen it hit in practice.
    • This module stays only because Cloud still imports it. If Cloud drops that import first, deleting the module is cleaner and would close this issue.
    • Per the triage scope, I have made no code changes.
  2. added a commit that references this issue on Oct 29, 2026
    8ea66d8
  3. added a commit that references this issue on Oct 29, 2026
    39441e8
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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions