Skip to content

feat(parser): Markdown and YAML knowledge extractors - #539

Closed
otalrapha wants to merge 1 commit into
tirth8205:mainfrom
otalrapha:feat/markdown-yaml-knowledge-extractors
Closed

otalrapha wants to merge 1 commit into
tirth8205:mainfrom
otalrapha:feat/markdown-yaml-knowledge-extractors

Conversation

@otalrapha

Copy link
Copy Markdown

What

Adds two regex-based extractors so the graph can index knowledge files that have no bundled tree-sitter grammar:

  • Markdown (.md/.mdx/.qmd): headings → Section nodes, nesting → CONTAINS edges, links (backtick filenames, [[wikilinks]], [text](x.md)) → REFERENCES edges. Fenced code blocks are skipped.
  • YAML (.yaml/.yml): top-level keys → Section nodes, registry-style id:/name: list entries → Type nodes, with CONTAINS edges. Pure regex, no PyYAML dependency.

Why

Both reuse the existing NodeInfo/EdgeInfo schema and the shared CONTAINS/REFERENCES edge kinds, so documentation and config land in the same graph as code: a spec.md can REFERENCES the source file it describes, and a CRON-123 registry entry becomes a queryable node. Helpful for repos that mix code with specs, docs and config registries.

Approach

Follows the existing pattern for grammar-less inputs (_parse_rescript, _parse_sql): extension mapping in EXTENSION_TO_LANGUAGE, dispatch in parse_bytes, dedicated _parse_markdown / _parse_yaml methods.

Tests

tests/test_knowledge_extractors.py — 4 cases (headings/nesting, fenced-code skip, references, yaml entries). ruff check passes clean, pytest green locally.

Adds regex-based extractors for two formats that have no bundled tree-sitter
grammar (same approach already used for ReScript and SQL CREATE PROCEDURE):

- Markdown (.md/.mdx/.qmd): each heading becomes a Section node; heading nesting
  produces CONTAINS edges; backtick filenames / [[wikilinks]] / [text](x.md)
  links produce REFERENCES edges. Fenced code blocks are skipped.
- YAML (.yaml/.yml): top-level keys become Section nodes and registry-style
  list entries (id:/name:) become Type nodes, with CONTAINS edges. Pure regex,
  no PyYAML dependency.

Because both reuse the existing NodeInfo/EdgeInfo schema and the shared
CONTAINS/REFERENCES edge kinds, documentation and config now live in the SAME
graph as code — e.g. a spec.md REFERENCES the source file it describes, and a
CRON-123 registry entry is a queryable node.

Tests: tests/test_knowledge_extractors.py (4 cases — headings/nesting, code
fence skip, references, yaml entries). ruff clean, pytest green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tirth8205

Copy link
Copy Markdown
Owner

Thanks for the contribution. The parser-level tests pass, but the persisted graph is not connected correctly: File nodes use full paths while the new CONTAINS/REFERENCES edges use path.name and custom bare section IDs, so those edges do not point to stored nodes.

There are significant false positives. Ordinary inline code such as python or GraphStore becomes a reference, and YAML creates separate Types for both id: CRON-1 and name: alpha. Link directories are discarded, section spans stop on the heading line, and fence handling covers only simple triple-backtick toggling.

Please use canonical endpoints, add a full_build/query integration test, narrow Markdown reference and YAML registry detection, preserve link paths, add negative/error cases, and provide graph-size/build-time evidence. This would automatically index 61 files in this repository. Coordinate YAML design with #577, rebase, and run full CI.

@tirth8205

Copy link
Copy Markdown
Owner

Thanks for the parser work. I am closing head b4cd950 because it cannot merge into current main and remains 246 commits behind. Its parser-level tests miss the persisted-graph failure: the exact full-build harness generated 1,619 CONTAINS/REFERENCES edges and all 1,619 were dangling because File nodes use full paths while these edges use path.name and bare section IDs. It also generated 1,038 references, treating ordinary inline code such as python and GraphStore as targets; link directories are discarded; and YAML emits separate Types for an entry's id and name. Only GitGuardian ran on this head.

A future contribution should use canonical qualified endpoints, include full-build/query integration and dangling-edge assertions, preserve link paths and section spans, add conservative Markdown/YAML detection with negative and malformed-input cases, measure graph-size/build-time impact, and align with current YAML/Ansible classification before running full CI.

@marcus-sa

Copy link
Copy Markdown

Is markdown support on the path?

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.

3 participants