lmlucene authoring skill
lmlucene exposes Apache Lucene 10.5.2 indexing, full-text and vector KNN search, facets, and custom SAM analysis and scoring callbacks to typed _lmcode_ blocks inside LMScript.
Purpose
Use lmlucene to build in-memory or persistent NIOFSDirectory Lucene indexes, run parsed, Boolean, numeric-range, facet-drilldown, or Euclidean KNN vector queries, and customize tokenization or BM25 similarity scoring directly from LMScript.
When to use it
Use lmlucene when a task needs full-text inverted indexes, stemmers, phrase and wildcard queries, term vectors, sorted-set facets, or custom per-field BM25 weighting in a standalone native executable. Use lmsearch when your primary workflow is ONNX neural model embedding combined with FAISS and AutoFaiss vector quantization.
Install
Install the LMScript compiler and download the standalone GraalVM native release binary for Linux, macOS, or Windows with lmscript install.
npm install -g @lmctl-ai/lmctl
lmscript install github:lmctl-ai/lmlucene@latest
lmlucene --version
lmlucene --lmcode-schema --json
lmlucene --lmcode-signatures
Commands
Compile an _lmcode_ block targeting lmlucene and execute it with run_lmcode:
program = _lmcode_ cli="lmlucene" install="github:lmctl-ai/lmlucene@latest";
let directory = memory_directory();
let analyzer = standard_analyzer();
let writer = index_writer(directory, writer_config(analyzer));
writer.add(document().keyword("id", "1", true).text("body", "Hello Lucene", true));
let reader = writer.reader();
index_searcher(reader).search(term_query("body", "lucene"), 10).emit("matches");
end _lmcode_
r = run_lmcode(program);
assert(r.ok);
With a compiled bytecode file (the repository examples write them under lmcode/build), you can also invoke the lmaws-style CLI runner with dry-run or JSON input options:
lmlucene run --program lmcode/build/basic.dslb
lmlucene run --program lmcode/build/basic.dslb --dryrun
lmlucene run --input-json "{\"op\":\"run\",\"params\":{\"program\":\"lmcode/build/basic.dslb\"}}"
Inputs and outputs
Programs create documents with analyzed text, exact keyword, stored-only, numeric point/doc-value, facet, and float-vector fields, index them through IndexWriter into memory_directory() or fs_directory(path), and query them through IndexSearcher.
Stdout emits a single JSON envelope containing ok and result. TopDocs.emit(label) adds stored document fields, doc IDs, and scores to result.searches; token streams, facets, and reported explanations appear in result.details.
Safety rules
Call writer.commit() or writer.close() to persist filesystem index changes; unclosed writers are automatically rolled back on exit or failure, and all open resources close in reverse acquisition order. Readers are immutable point-in-time snapshots: open a new reader via writer.reader() or directory_reader(dir) to observe committed writes.
In TokenTransform SAM rules, apply the same rule_analyzer at both indexing and query time and never return an empty replacement token. In FieldWeight SAM rules, always return a finite, nonnegative weight factor so Lucene's score monotonicity invariants hold.
Worked examples
Run the persistent indexing and query scripts or the 32-example gallery covering phrase/fuzzy queries, facets, pagination, sorting, KNN, and SAM rules:
lmscript lmcode/examples/basic.lms
lmscript lmcode/examples/rules.lms
lmscript lmcode/examples/index.lms /tmp/lmlucene-demo
lmscript lmcode/examples/query.lms /tmp/lmlucene-demo "lucene AND rules"
lmscript lmcode/examples/run-gallery.lms
Errors and exit codes
lmlucene exits with code 0 on success. Code 2 indicates CLI usage errors or compilation failures. Code 3 indicates bytecode load errors, schema hash mismatches, runtime Lucene exceptions, or policy refusals (such as passing --readonly to run).
How to verify
Verify the binary version, CLI schema, lmcode schema, canonical signatures, and integration test suite.
lmlucene --version
lmlucene --schema
lmlucene --lmcode-schema --json
lmlucene --lmcode-signatures
./lmcode/test.sh