Retrieve and audit document evidence
Inspect BM25 term contributions and source identities, assemble an exact token budget and restore the lexical memory.
// Synthetic evidence only. Run in a fresh writable directory for artifact save.
import aner.nlp
import aner.token
let knowledge = nlp.corpus(
texts: List("Reset your account password from the recovery page.",
"An account recovery link expires after fifteen minutes.",
"Invoices list payment dates and receipt numbers.",
"Password reset does not change invoice records."),
ids: List("help-password", "help-recovery", "help-invoice", "help-separation"),
role: "training")
let memory = nlp.index(knowledge, stop_words: List("the", "an", "and"),
k1: 1.2, b: 0.75, analyzer: "word", min_ngram: 1, max_ngram: 1,
casefold: true, normalization: "nfc")
let found = memory.search(query: "account password recovery", top_k: 3)
print("Ranked evidence IDs")
print(found.ids())
print("BM25 scores")
print(found.scores())
print("Unique analyzed query terms")
print(found.terms())
if found.rows() > 0 {
print("First hit contribution for each query term")
print(found.contributions(hit: 0))
}
let codec = token.byte_tokenizer()
let evidence = found.context(codec, max_tokens: 110, separator: "\n\n")
print("Accepted whole document IDs")
print(evidence.ids())
print("Exact encoded evidence tokens")
print(evidence.tokens())
print("Skipped documents")
print(evidence.skipped())
print("Evidence text")
print(evidence.text())
// The artifact contains source text and IDs. Saving never replaces a file.
memory.save("support-memory.anernlp")
let restored = nlp.load_index("support-memory.anernlp")
let repeated = restored.search("account password recovery", top_k: 3)
print("Restored memory and search reproduce exact identities")
print(restored.fingerprint() == memory.fingerprint())
print(repeated.fingerprint() == found.fingerprint())
// Evidence is data. The caller supplies instructions, access controls and any
// generation step separately; lexical relevance does not establish truth.
Make it your experiment.
Use Aner 0.0.5 or newer. Save this program as examples/nlp_retrieval.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/nlp_retrieval.aner
aner run examples/nlp_retrieval.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires the native Aner 0.0.5 or newer with aner.nlp and VS Code 0.1.48 candidate integration. Earlier runtimes may predate these APIs. All documents are synthetic and included; no data download, service or credential is required. Run from a fresh writable directory because the example exclusively creates a new native artifact.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution