Index markdown headers to enable section validation and deep-linking
Summary
Indexing markdown section headers (## Heading) in the parser would unlock two capabilities from a single change:
- Section validation — schemas could declare required sections and validate that observations appear in the correct section
- 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,## Backgroundare 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#methodsmemory://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_fnbug was fixed during test work — was returning search index metadata instead of fullentity_metadata
🤖 Generated with Claude Code
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:
- Section validation - Schemas could enforce that observations appear in correct sections
- Deep-linking - Permalinks could reference specific sections (e.g.,
memory://note#section)
Related Issues
Closely Related:
- #135 - "Section and Observation Anchor Wikilinks Support" - Proposes
[[entity#section#observation]]syntax. Issue #547 provides the parser infrastructure needed to support section-aware features like #135.
Possibly Related:
- #375 - "[FEATURE] Support schema for notes" - General schema system. Section validation would build upon this.
Current Architecture
The parser (entity_parser.py:113-136) is currently section-agnostic:
- Extracts observations/relations via pattern matching without section context
- Uses
markdown-itwith custom plugins (observation_plugin,relation_plugin) - Returns flat
EntityContentwith no section metadata - No section tracking in
ObservationorRelationschemas
Required Changes
-
Parser Layer (
entity_parser.py)- Track section headers during markdown-it token parsing
- Associate observations/relations with their containing section
- Extend
EntityContentto include section metadata
-
Schema Layer (
markdown/schemas.py)- Add optional
sectionfield toObservationandRelationmodels - Create section header index structure
- Support for picoschema format extension (if applicable)
- Add optional
-
Deep-linking Support
- Extend permalink resolution to handle
#sectionfragments - Update MCP tools (
read_note,build_context) to support section-level addressing - Database schema migration to store section metadata
- Extend permalink resolution to handle
Complexity Assessment
Complex due to:
- Core parsing logic with extensive test coverage (17+ test files in
tests/markdown/) - Database schema migration required
- Multi-layer impact: parser → schemas → database → MCP tools → API
- Backwards compatibility considerations
- Coordination with related issues (#135, #375)
Recommendations
-
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 #375.
-
Coordinate with #135: These issues are highly synergistic - consider implementing together.
-
Phased Approach:
- Phase 1: Add section tracking to parser (non-breaking - optional
sectionfield) - Phase 2: Implement deep-linking with
#sectionfragments - Phase 3: Add section validation once schema system is ready
- Phase 1: Add section tracking to parser (non-breaking - optional
-
Consider Observation IDs: Issue #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
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.