Skip to content

Index markdown headers to enable section validation and deep-linking #547

Open

Description

@phernandez

Summary

Indexing markdown section headers (## Heading) in the parser would unlock two capabilities from a single change:

  1. Section validation — schemas could declare required sections and validate that observations appear in the correct section
  2. Deep-linking — permalinks could point to sections within documents (e.g., memory://note#section)

Current State

  • The parser is completely section-agnostic — observations and relations are extracted by pattern matching regardless of which ## section they appear under
  • The validator receives flat (category, content) tuples with no section context
  • Section headers like ## Observations, ## Relations, ## Background are purely organizational/visual

Proposed Changes

Parser

  • Track which section each observation/relation was extracted from
  • Index section headers as searchable/queryable metadata
  • Preserve section context through the parse → validate pipeline

Schema Format Extension

The picoschema format could extend with a sections key:

schema:
  name: string
  role?: string
sections:
  - Background
  - Methods
  - Findings

Deep-linking

With headers indexed, permalinks could reference specific sections:

  • memory://coffee-brewing-methods#methods
  • memory://auth-service#observations

Context

  • Schema system core (parser, resolver, validator, inference, diff) has 100+ tests at high coverage
  • Schema router integration tests completed (8 tests in tests/api/v2/test_schema_router.py)
  • Router search_fn bug was fixed during test work — was returning search index metadata instead of full entity_metadata

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    on Feb 7, 2026
  2. claude commented on Feb 7, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 2m 38s —— View job


    Issue Triage Complete

    Type: Enhancement / Feature Request
    Priority: Medium
    Complexity: Complex (architectural changes)
    Components: Parser, Schema System, MCP Tools
    Label Applied: enhancement


    Summary

    This is a well-structured feature request to add markdown section header indexing, enabling:

    1. Section validation - Schemas could enforce that observations appear in correct sections
    2. Deep-linking - Permalinks could reference specific sections (e.g., memory://note#section)

    Related Issues

    Closely Related:

    Possibly Related:

    Current Architecture

    The parser (entity_parser.py:113-136) is currently section-agnostic:

    • Extracts observations/relations via pattern matching without section context
    • Uses markdown-it with custom plugins (observation_plugin, relation_plugin)
    • Returns flat EntityContent with no section metadata
    • No section tracking in Observation or Relation schemas

    Required Changes

    1. Parser Layer (entity_parser.py)

      • Track section headers during markdown-it token parsing
      • Associate observations/relations with their containing section
      • Extend EntityContent to include section metadata
    2. Schema Layer (markdown/schemas.py)

      • Add optional section field to Observation and Relation models
      • Create section header index structure
      • Support for picoschema format extension (if applicable)
    3. Deep-linking Support

      • Extend permalink resolution to handle #section fragments
      • Update MCP tools (read_note, build_context) to support section-level addressing
      • Database schema migration to store section metadata

    Complexity Assessment

    Complex due to:

    Recommendations

    1. Clarify Schema System: The issue mentions a schema system with "parser, resolver, validator, inference, diff" and 100+ tests. Verify if this refers to existing Pydantic schemas or planned features from [FEATURE] Support schema for notes #375.

    2. Coordinate with Section and Observation Anchor Wikilinks Support #135: These issues are highly synergistic - consider implementing together.

    3. Phased Approach:

      • Phase 1: Add section tracking to parser (non-breaking - optional section field)
      • Phase 2: Implement deep-linking with #section fragments
      • Phase 3: Add section validation once schema system is ready
    4. Consider Observation IDs: Issue Section and Observation Anchor Wikilinks Support #135 proposes observation-level anchors (#id-0001). Worth considering in the same effort.

    Next Steps

    This issue is now properly triaged and ready for:

    • Discussion on implementation approach
    • Prioritization in the roadmap
    • Assignment when ready to implement

  3. calebpickerconsulting commented on Mar 18, 2026

    @calebpickerconsulting

    Adding a thought @claude what do you think?

    Semantic search with embeddings and vectors is a fantastic feature. From the documentation, chunks are vectorized by header (I think these are the same as section) AND by observation. This is great.

    While building the indexing, consider whether and how these can both be integrated to greater effect.

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

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions