llammer is a command-line tool for grammatical and spelling correction with an optional Retrieval-Augmented Generation (RAG) search mode. This hub is the entry point to the full documentation set — architecture, theory, per-component references, configuration, worked examples, integration notes, and the roadmap. Every document describes llammer as built; anything not yet wired to a live code path is labelled Planned and collected in the roadmap.
llammer is a thin, clap-based CLI shell over two independent library stacks. Keeping them separate is the single most important thing to understand about the system:
- Correction stack — all spelling/grammar correction is performed by the sibling crate
llammer-pipeline. It builds a weighted finite-state transducer (WFST) lattice whose candidate words come from a dictionary-constrained Damerau–Levenshtein automaton (vialiblevenshtein), and decodes the lattice with the Viterbi algorithm over the tropical (min-plus) semiring (vialling-llang). An optional phonetic layer reweights sound-alike candidates. No neural network runs here. - Retrieval stack — the
ragsubcommand (and the query-correction inside it) useslibgrammsteinfor ModernBERT sentence embeddings and a cosine-similarityRagIndex. libgrammstein is the only place a neural model executes, and it is used only by RAG.
Accuracy note. Earlier drafts of these docs claimed the WFST correction engine lived in libgrammstein and that ModernBERT rescored corrections. Neither is true in the shipped code: correction is
llammer-pipeline(→lling-llang+liblevenshtein), and libgrammstein is RAG/embedding only. The documentation you are reading now reflects the real design.
liblevenshtein (fuzzy dictionary automata) and lling-llang (WFST lattice, layer pipeline, Viterbi, semiring) are foundation crates that reach llammer transitively through llammer-pipeline. The binary uses #[tokio::main], but there is no real concurrency or networking today.
Each input is tokenized (whitespace split, punctuation peeled into a prefix/suffix, case pattern recorded). For every token that is out of vocabulary, the pipeline adds one lattice edge per Damerau–Levenshtein candidate found within the maximum edit distance, weighting each edge by its distance; the original (uncorrected) token is added at a deliberately high weight so any genuine correction outranks keeping the typo. Viterbi then selects the minimum-total-weight path through the lattice:
Here thier → their), and edit_weight defaults to 0.3. Because weights are costs on the tropical semiring, lower is better and Viterbi finds the cheapest path. There is deliberately no probabilistic language-model term today — the lm_weight / LM-rerank machinery is scaffolding for a Planned layer, so ties between equally-close candidates are resolved without context. The correction-model theory and pipeline component docs develop this in full.
llammer writes an informational
Loading models...line to stdout atinfolevel by default. Prefix a command withRUST_LOG=offto silence it — required when piping machine-readable output. Every example below is verbatim.
$ cargo build --release
$ RUST_LOG=off llammer correct "thier problm"
[original] thier problm
[corrected] their problem
$ RUST_LOG=off llammer correct --format json "custmer"
{
"changed": true,
"corrected": "customer",
"original": "custmer"
}correct always uses the compact 363-word dictionary embedded in llammer-pipeline; there is no flag to substitute a larger word list on this path, so out-of-vocabulary words pass through or map to a near neighbour (see the roadmap for the Planned larger-dictionary and LM-rerank work). See Basic Correction for the single-string and file workflows, REPL Modes for the interactive session, and RAG Workflow for indexing and search.
llammer exposes exactly three subcommands (rag has three subcommands of its own). This is the complete surface — there is no config subcommand, and rag has no info/export/import.
| Command | Purpose | Key options |
|---|---|---|
correct |
Correct a single string or a file (one sentence per line) | --format text|json|tsv, --input <FILE>, --output <FILE>, --max-edit-distance <N> |
repl |
Interactive correction session | --mode standalone|agent|customer|rag, --language <CODE>, --context-window <N> |
rag init |
Build a RAG index from a directory of documents | --documents <DIR> (required), --output <DIR> (required) |
rag query |
Search an index, optionally spell-correcting the query first | --index <DIR> (required), --top-k <N>, --correct-query |
rag extend |
Add documents to an existing index | --index <DIR>, --documents <DIR>, --output <DIR> |
The full argument reference — including flags that are accepted but currently ignored (--models, --insertion-penalty, --deletion-penalty, --beam-width, repl --address, rag init --summarize) — is in the CLI component overview.
- Overview — the CLI → application → library → foundation layer stack, the crate dependency DAG, and the two-stack design.
- Data Flow — end-to-end flow of
correct(single + batch),rag init/query, and the REPL loop.
- Correction Model — Damerau–Levenshtein distance, Levenshtein automata, the tropical semiring, and Viterbi decoding, with references.
- CLI — every subcommand, argument, default, and the consumed-versus-inert status of each flag.
- Pipeline — Overview — the
LatticeCorrectionPipeline: tokenize → expand → (phonetic) rescore → Viterbi → reconstruct. - Pipeline — Contextual —
LatticeContextualCorrector, the library-only confidence-reweighting API (CLI wiring is Planned). - REPL — the
BaseRepldriver, theReplRolestrategy, the three roles, and the RAG placeholder mode. - RAG — index construction, ModernBERT embedding, cosine query, and optional query correction.
- Overview — the
llammer.tomlschema, the load order, and which keys are live versus reserved.
- Basic Correction — single-string and file correction, output formats, and exit behavior.
- Batch Processing —
--input/--outputfile workflows and scripting withRUST_LOG=off. - RAG Workflow — building, querying, and extending an index.
- REPL Modes — standalone, agent, customer, and the RAG placeholder mode.
- llammer-pipeline — how llammer consumes the correction crate and its re-exported
pipeline/context/languagemodules. - libgrammstein — how the
ragsubcommand consumes the retrieval crate and ModernBERT embeddings.
- Planned / Not Yet Implemented — the honest tier list of Implemented / Partial / Planned features, each with the code that exists and the wiring it needs.
- Diagram index — every figure is authored in PlantUML (
*.puml) and committed alongside its rendered*.svg; the Markdown docs embed the SVGs. There is no Mermaid in this repository.
- Rust — a stable toolchain; llammer targets Rust edition 2021.
- Sibling path crates — llammer depends on two crates by relative path, so they must sit alongside this repository:
../llammer-pipeline— correction (WFST lattice, tokenizer, conversation context, language tags; brings inlling-llangandliblevenshteintransitively).../libgrammstein— RAG indexing and ModernBERT embeddings.
- Project README — the landing page and status matrix.
- Roadmap — what is Planned and why.
- Architecture Overview — the deepest single treatment of the system's shape.
- Damerau, F. J. (1964). A technique for computer detection and correction of spelling errors. Communications of the ACM, 7(3), 171–176. https://doi.org/10.1145/363958.363994
- Schulz, K. U., & Mihov, S. (2002). Fast string correction with Levenshtein automata. International Journal on Document Analysis and Recognition, 5(1), 67–85. https://doi.org/10.1007/s10032-002-0082-8
- Viterbi, A. J. (1967). Error bounds for convolutional codes and an asymptotically optimum decoding algorithm. IEEE Transactions on Information Theory, 13(2), 260–269. https://doi.org/10.1109/TIT.1967.1054010
- Mohri, M., Pereira, F., & Riley, M. (2002). Weighted finite-state transducers in speech recognition. Computer Speech & Language, 16(1), 69–88. https://doi.org/10.1006/csla.2001.0184
- Warner, B., et al. (2024). Smarter, better, faster, longer: A modern bidirectional encoder (ModernBERT). arXiv. https://arxiv.org/abs/2412.13663
- Lewis, P., et al. (2020). Retrieval-augmented generation for knowledge-intensive NLP tasks. Advances in Neural Information Processing Systems (NeurIPS). https://arxiv.org/abs/2005.11401