Skip to content

Structural pre-extraction pass (wikilinks + frontmatter) before LLM processing #295

Open

Description

@adelaidasofia

Problem

For markdown vaults (Obsidian, Logseq, etc.), a large percentage of meaningful relationships are already encoded as [[wikilinks]]. Sending these files through LLM extraction to discover links that are already in the text is expensive and slower.

Proposed solution

A pre-extraction pass that runs before LLM processing:

  1. Wikilink extraction: Regex \[\[([^\[\]|#]+?)(?:\|([^\[\]]+?))?(?:#[^\[\]]*)?\]\] captures target and optional alias. Each match becomes a references edge from the source file node to the target concept node.

  2. Frontmatter parsing: Extract YAML frontmatter keys (tags, categories, custom fields) as typed edges without needing the LLM.

  3. Output: A pre-flight JSON with all structurally extractable nodes and edges. The LLM pass can then skip wikilink discovery and focus on semantic relationships the regex can't catch.

Benchmarks from our vault

On 566 files after dedup:

  • Regex produced 10.4 edges/file (11,809 total) in under 2 seconds
  • LLM on a 200-file batch produced 7.3 edges/file (1,468 total)
  • ~50% of files have 12+ wikilinks each (fully handled by regex); the other 50% have zero and need full LLM extraction

The regex pass is free in terms of API cost and reduces LLM token spend by 50 to 65% on link-heavy vaults.

Scope

This would be most useful as an optional --pre-extract flag or a separate graphify pre-extract command, so it doesn't change the default behavior for non-markdown inputs.

Happy to send a PR.

Activity

  1. DavidPalazonUPCT commented on May 29, 2026

    @DavidPalazonUPCT

    Second data point, plus two angles beyond token cost

    Implemented this exact pre-extraction idea as a post-hoc layer on my Obsidian PhD vault (~700 nodes after curation). Strong +1, with findings that complement the benchmarks above.

    1. The win isn't only token cost — it's edge fidelity. Before reinjecting wikilinks, most of my edges were LLM-INFERRED. After parsing [[...]] into EXTRACTED edges, ~97% of edges became EXTRACTED (human-curated signal). For a hand-curated vault the wikilinks are the ground-truth relationships; having the LLM re-discover them isn't just wasteful, it's strictly worse than reading what the author already encoded. So I'd frame --pre-extract as a fidelity feature first, cost second.

    2. Wikilinks as a soft supervision prior over community detection. This is the part I find most interesting and haven't seen raised. In a curated vault the [[links]] encode the author's mental taxonomy. Reinjecting them as edges biases Louvain toward the communities the human actually intends — a cheap form of semi-supervised clustering, no must-link machinery needed. In my vault this raised modularity (Q ~ 0.47 across 27 communities) and made the clusters map onto my own MOC structure. Two notes:

    • It's a soft prior, not a hard constraint — a lone wikilink between two dense clusters won't merge them. Weighting wikilink edges higher than inferred ones (a curated link should outvote a co-occurrence) would strengthen the effect for those who want more control.
    • Trade-off worth flagging: over-supervising erodes graphify's cross-document-surprise value. The sweet spot is wikilinks as skeleton + LLM inference filling the gaps you didn't link.

    3. Two implementation gotchas if a PR happens:

    • Label fragmentation after reinjection. Short concepts (SWaT, LSTM) and per-row MOC entries get extracted as several near-duplicate nodes. I needed a merge_by_label consolidation pass (survivor = highest degree) — and crucially you must re-point each edge's source/target to the survivor, or to_json serializes dangling edges that reload as phantom nodes.
    • Windows encoding. export/query crash on cp1252 with special chars (e.g. arrows) and on None-valued attributes. Setting PYTHONUTF8=1 + sanitizing None before export fixes it.

    Happy to share my standalone scripts (wikilink_layer.py + a rebuild driver) as a reference implementation if useful.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions