This example demonstrates the full llm-patch pipeline: ingesting structured wiki pages (produced by an LLM Wiki Agent) and converting them into LoRA adapter weights that can be applied to a base language model.
data/papers/*.md ──► LLM Wiki Agent ──► wiki/ (structured markdown)
(ingest) │
▼
llm-patch library
┌──────────────┐
│ WikiSource │ (IKnowledgeSource)
│ watches │
│ wiki/ │
└──────┬───────┘
▼
┌──────────────┐
│ Weight │ (IWeightGenerator)
│ Generator │
└──────┬───────┘
▼
┌──────────────┐
│ Adapter │ (IAdapterRepository)
│ Repository │
└──────┬───────┘
▼
adapters/{id}/
examples/
├── data/ # Read-only sample corpora used by the demos
│ ├── papers/ # 3 sample ML paper summaries (raw input)
│ └── wiki/ # Pre-built wiki snapshot (sources/ + entities/)
├── e2e/ # End-to-end demo scripts
│ ├── run_e2e.py # Full pipeline: simulate wiki → generate → validate
│ ├── run_wiki_e2e.py # Wiki-agent variant (mock or Anthropic)
│ ├── demo_e2e_scenario.py # Scripted 5-step scenario for documentation/tests
│ ├── research_pipeline.py # Core batch/watch pipeline implementation
│ └── validate_adapter.py # GPU-only adapter validation script
└── quickstart/ # Smallest possible getting-started example
python examples/e2e/run_e2e.py --cleanThis will:
- Copy raw papers from
examples/data/papers/into a simulatedwiki/directory - Add wiki-style frontmatter and create entity stub pages
- Run the WikiKnowledgeSource → MockWeightGenerator → MockAdapterRepository pipeline
- Report all generated adapter manifests
python examples/e2e/research_pipeline.py batch \
--wiki-dir examples/data/wiki/ --output-dir adapters/python examples/e2e/research_pipeline.py batch \
--wiki-dir examples/data/wiki/ --aggregateWhen --aggregate is enabled, each source page follows its [[wikilinks]]
to entity and concept pages, concatenating linked content into a single
enriched document before weight generation.
python examples/e2e/research_pipeline.py watch --wiki-dir wiki/Add or modify wiki pages while the watcher is running. Each change triggers automatic adapter generation. Press Ctrl-C to stop.
python examples/e2e/validate_adapter.py \
--adapter-dir adapters/sources/attention-paper \
--base-model google/gemma-2-2b-itThis loads the base model, applies the LoRA adapter, and runs a side-by-side
inference comparison. Requires torch, transformers, and peft with a
working CUDA installation.
The LLM Wiki Agent (or the run_e2e.py simulator) produces:
wiki/
├── sources/ # One page per ingested paper
│ ├── attention-is-all-you-need.md
│ ├── lora-low-rank-adaptation.md
│ └── gpt3-few-shot-learners.md
├── entities/ # Auto-extracted entity pages
│ ├── transformer.md
│ ├── self-attention.md
│ └── ...
└── concepts/ # Concept pages
├── lora.md
└── ...
Each page has YAML frontmatter:
---
title: Attention Is All You Need
authors: Vaswani et al.
year: 2017
tags: transformer, attention
---WikiKnowledgeSource is a new IKnowledgeSource that:
- Watches wiki directories recursively for
.mdfile changes - Parses YAML frontmatter into
DocumentContext.metadata - Extracts
[[wikilinks]]and stores them in metadata - Optionally aggregates linked pages into enriched documents
from llm_patch import WikiKnowledgeSource, WatcherConfig
config = WatcherConfig(directory="wiki/")
source = WikiKnowledgeSource(config, aggregate=True)
# Scan existing pages
docs = source.scan_existing()
for doc in docs:
print(doc.document_id, doc.metadata.get("title"))
# Or use with the orchestrator for live monitoring
from llm_patch import KnowledgeFusionOrchestrator
orchestrator = KnowledgeFusionOrchestrator(source, generator, repository)
with orchestrator:
# Watcher is running — changes trigger automatic processing
...- Real weight generation: Replace
MockWeightGeneratorwithSakanaT2LGeneratorwhen a Sakana T2L checkpoint is available. - Real storage: Replace
MockAdapterRepositorywithLocalSafetensorsRepositoryfor persistent safetensors output. - LLM Wiki Agent: Point
--wiki-dirat the actual output ofSamurAIGPT/llm-wiki-agentinstead of using the simulator. - Adapter merging: Use PEFT's
add_weighted_adapter()to combine multiple per-document adapters into a single domain adapter.