Skip to content

[BUG] build_context does not support underscore format in memory:// URLs #304

@BeaconSage

Description

@BeaconSage

name: Bug report
about: Create a report to help us improve Basic Memory
title: '[BUG] build_context does not support underscore format in memory:// URLs'
labels: bug
assignees: ''

Bug Description

When using Basic Memory's build_context function with memory:// URLs, it fails to recognize paths that contain underscores in the relation type segment. The function only works with hyphenated format (e.g., part-of) but not with underscore format (e.g., part_of), even when both formats exist in the actual markdown files.

Steps To Reproduce

  1. Create markdown files with relation links using both formats:
    • part-of [[target1]] (hyphenated)
    • part_of [[target2]] (underscore)
  2. Use build_context with memory:// URL pattern matching:
    • memory://path/to/file/part-of/* → Returns results ✅
    • memory://path/to/file/part_of/* → Returns empty results ❌

Expected Behavior

Both underscore and hyphenated formats should be supported and return matching results, as both are valid markdown link formats that users might naturally use.

Actual Behavior

  • memory://workflow/specs/workflow-manager-agent/part-of/* returns 2 results
  • memory://workflow/specs/workflow-manager-agent/part_of/* returns 0 results

The underscore format fails silently with empty results, even when matching content exists.

Environment

  • OS: macOS 14.5 (Darwin 24.5.0, ARM64)
  • Python version: 3.13.5
  • Basic Memory version: Latest (via MCP)
  • Installation method: MCP server
  • Claude Desktop version: Latest

Additional Context

This inconsistency affects user experience as both underscore and hyphenated formats are commonly used in markdown. Users may naturally use either format and expect both to work.

Example of actual file content showing both formats:

- part-of [[Sequence Diagram Operations Guide]] - task parsing syntax, generation standards, participant validation mechanism
- part_of [[Knowledge Deposition Strategy Specification]]

Tested URLs that demonstrate the issue:

  • Working: memory://workflow/specs/workflow-manager-agent/part-of/*
  • Broken: memory://workflow/specs/workflow-manager-agent/part_of/*

Possible Solution

The URL parsing logic should normalize both underscore and hyphenated formats, or support pattern matching that works with both formats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions