Extracts agent-accessible knowledge from document file trees into clean Markdown.
- Microsoft Word (.docx)
- Microsoft PowerPoint (.pptx)
- Microsoft Excel (.xlsx)
- PDF (.pdf)
- Images (.jpg, .jpeg, .png)
uv sync
cp .env.example .env # add your OpenRouter API key# Using the `convert` script (recommended)
uv run convert --input ./input --output ./output --temp ./temp --model google/gemini-2.5-flash
# Equivalent forms via the command group
uv run knowledge-extractor convert --input ./input --output ./output
uv run python main.py --input ./input --output ./output # subcommand optional; defaults to `convert`Other subcommands: convert (extract, the default), clear (remove temp/output dirs), lint (re-lint markdown), reindex (rebuild the root index/manifest across all subfolders).
# Rebuild a single root index/manifest across all subfolders (e.g. after joining vaults)
uv run knowledge-extractor reindex ./output
uv run knowledge-extractor reindex ./output --keep-nested| Flag | Default | Description |
|---|---|---|
--input |
(required) | Input directory with source documents |
--output |
./output |
Output directory for final Markdown files |
--temp |
./temp |
Intermediate data directory (debug artifacts) |
--model |
google/gemini-2.5-flash |
OpenRouter vision model for image analysis |
--translate-from |
(unset) | Translate the output into English from this source language (e.g. German, de). If unset, no translation is performed. |
--translate-model |
mistralai/mistral-large-2512 |
Model used for translation (text-only). Falls back to --model if unset. |
--dry-run |
false |
List which files would be processed and which would be skipped, then exit without processing |
| Variable | Description |
|---|---|
OPENROUTER_API_KEY |
OpenRouter API key. If not set, AI steps are skipped and raw extractions are output. |
- Incremental processing — skips a source file if its output Markdown already exists; delete the output file (or the output dir) to re-run
- Intermediate results — per-file markdown with original image references saved to temp dir
- AI image analysis — converts diagrams to Mermaid, charts to descriptions (requires API key)
- OCR for scanned PDFs — auto-detects scanned/image-only PDFs and extracts text via AI vision OCR (requires API key)
- LaTeX formula extraction — detects mathematical formulas in DOCX/PPTX (OMML) and PDF (heuristic font/character analysis), converts to LaTeX via AI vision. Inline formulas wrapped with
$...$, display formulas with$$...$$. Requires API key; without it, a placeholder is inserted. - Heuristic filtering — removes title slides, logo-only sections, repeated headers
- Translation to English — with
--translate-from <language>, a dedicated final pass translates the assembled Markdown into English after cleanup (before linting), preserving code blocks, LaTeX, tables, URLs, and Mermaid structure. Uses--translate-model(defaults to a text model, falls back to--model). Requires an API key; without one, translation is skipped and the original content is kept. Incremental skip still applies — pre-existing outputs are not re-translated (a warning is logged when files are skipped while--translate-fromis set); delete the outputs or runclearto re-translate. - Markdown linting — auto-fixes formatting issues (trailing spaces, heading spacing, list indentation) via pymarkdownlnt
- Logging — console output +
output/extraction.log
output/index.md— flat index grouped by original folder structureoutput/**/*.md— one Markdown file per source document
The reindex command rebuilds a single root index.md + manifest.json for an output
directory purely from the Markdown already on disk — no extraction, no AI, no linting.
This is useful after joining multiple vaults: copy the per-document subfolders of
several output directories into one combined directory, then run reindex to produce one
unified index/manifest covering every subfolder.
uv run knowledge-extractor reindex ./output
uv run knowledge-extractor reindex ./output --keep-nested- The output directory is a required positional argument (consistent with
lint). - By default,
reindexremoves nestedindex.md/manifest.jsonfiles found in subdirectories, but only when they are verified extractor-generated artifacts (a nestedindex.mdmust start with# Knowledge Index; a nestedmanifest.jsonmust be a JSON array of entries carryingpath/title/group). User-contentindex.mdfiles (e.g. Obsidian folder notes, Hugo/Docusaurus/MkDocs index pages) are preserved and logged. The root-level pair is always regenerated. --keep-nestedopts out of removal entirely, leaving all nested artifacts in place.- Files inside hidden directories (any path component starting with
., e.g..git,.obsidian) are neither indexed nor removed. - Avoiding collisions: place each joined vault under a distinct parent folder
inside the combined directory (e.g.
combined/VaultA/,combined/VaultB/). Documents with identical relative paths would otherwise silently overwrite each other on the filesystem beforereindexruns.