Keyword knowledge
Score paragraphs of local files against a question and answer only from the best matches.
The script writes two small notes into kb/, splits every file into paragraphs and scores each paragraph by how many question words it contains. The two best paragraphs, with their file names, are the only sources the librarian agent sees, and it is asked to cite them. There are no embeddings: the scoring is plain and easy to inspect.
What it maps to
Knowledge: retrieval from local files before the model call. Citations come from the file names passed with each paragraph. See the concept map.
Script: keyword-knowledge.lms
# Keyword knowledge: score paragraphs of local files against the question and answer from the best ones.
import "agentic.lms";
mkdir("kb");
write_file("kb/dry-run.md", "Dry runs\n\nRun lmscript --dry-run FILE to evaluate a script with effects off.\n\nThe PLAN lists every skipped effect.");
write_file("kb/check.md", "Checking\n\nRun lmscript --check FILE to type-check without running anything.");
question = ARGV.get(0, "How do I run a script with effects off?");
hits = [];
for (file in sort(glob("kb/*.md"))) {
for (para in split(read_file(file), "\n\n")) {
score = 0;
for (w in words(lower(question))) {
if (len(w) > 3 && contains(lower(para), w)) { score = score + 1; }
}
if (score > 0) { push(hits, {score: score, file: file, text: para}); }
}
}
top = take(reverse(sort(hits, "score")), 2);
require(len(top) > 0, "no matching paragraphs in kb/");
librarian = agent("librarian", "answer only from the given sources and cite the file names");
println(ask(librarian, f"Sources: {json_stringify(top)}\nQuestion: {question}"));
It imports the shared helpers from examples/agentic.lms, shown on the recipe index.
Run it
export OLLAMA_API_KEY=...
LLM_MODEL=ollama-cloud/deepseek-v4.1-flash lmscript examples/keyword-knowledge.lms
Output (offline mock)
The site check runs this recipe against examples/mock-model.lms, a deterministic stand-in for the model, and compares this output.
Run lmscript --dry-run FILE: it evaluates the script with effects off and the PLAN lists every skipped effect (kb/dry-run.md).
Live run
Recorded on 2026-11-01 with ollama-cloud/deepseek-v4.1-flash. It made 1 model call and used 212 tokens. Live replies differ from run to run.
Run `lmscript --dry-run FILE` to evaluate a script with effects off. (Source: `kb/dry-run.md`)
Previous: Stateful checkpoint · Next: concept map
Try it: download examples/keyword-knowledge.lms and examples/agentic.lms into an examples/ directory, export the key for your provider, then run the command above. Replace the kb/ notes with your own files and pass a question as the first argument.