ir.cli¶
Command-line surface for ir (dispatched by cw).
Commands operate on named corpora from the registry (see
ir.registry):
ir build skills # build/update the skills preset corpus
ir search skills "deploy app" # rank candidates (retrieval only)
ir discover skills "deploy app" # retrieve -> commit to a high-precision subset
ir discover skills "deploy app" --disclose # + load each selected item's body
ir ls # list corpora + record counts
ir coverage reports # disk-vs-index coverage (silent-gap detector)
ir info packages # config + stats for a corpus
ir maintain --all # run due background work (idempotent)
ir schedule # install/inspect the OS job that runs it
ir register notes files --root ~/notes --pattern '.*\.md$'
ir rm notes # unregister (keeps built data)
ir eval-gen skills skills_eval.jsonl --k 5 # generate cases (needs aix/LLM)
ir eval skills skills_eval.jsonl --mode hybrid # score retrieval on a case file
ir eval-select skills skills_eval.jsonl # score the selection stage
ir sweep-select skills skills_eval.jsonl # tune max_k/rel for the selector
ir calibrate-min-score skills skills_eval.jsonl --persist # abstention floor
ir discover skills "deploy app" --min-score auto # use the calibrated floor
ir synonyms acmecorp # a term's aliases + a grep regex, from the ledger
ir synonyms-add "acmecorp, acme corp" --note "client nickname"
ir search session_turns "acmecorp invoice" -m lexical --expand
Functions
|
Build or incrementally update a registered (or preset) corpus. |
|
Calibrate the absolute abstention min_score floor for a corpus + mode. |
|
Report disk-vs-index coverage for a reports or packages corpus (silent-gap detector). |
|
Search a corpus, commit to a distractor-robust subset, and show it. |
|
Score a built corpus's retrieval against a DiscoveryCase JSONL file. |
|
Generate an eval-case file for a corpus by back-translation (needs aix/LLM). |
|
Score a selector against a DiscoveryCase JSONL file (selection quality). |
|
Show a corpus's stored config, stats, policy, and any abstention floors. |
|
List registered corpora with their kind, embedder, and record count. |
|
Run due background work: incremental reindex, synopsis in its downtime window. |
|
Register a named corpus. |
|
Unregister a corpus (does not delete its built data). |
|
Install, inspect, and operate the OS job that runs |
|
Search a built corpus and print the top-k hits. |
|
Sweep selector knobs (max_k × rel) against a case file; print the grid + best. |
|
Show what the synonym ledger knows: a term's aliases and grep regex, or all entries. |
|
Record corpus vocabulary in the synonym ledger: comma-separated equivalent terms. |
|
Replay the synonym ledger's entries against corpus NAME and say which still help. |
- ir.cli.build(name, *, embedder=None, full=True)[source]¶
Build or incrementally update a registered (or preset) corpus.
- ir.cli.calibrate_min_score(name, cases, *, mode='hybrid', k=10, sensitivity_weight=0.5, persist=False, fusion='rrf', rerank=None, rerank_text='surface')[source]¶
Calibrate the absolute abstention min_score floor for a corpus + mode.
Separates in-scope (gold-bearing) from out-of-scope (empty-gold) query top scores and reports the floor that best splits them, with sensitivity / specificity / Youden’s J.
casesmust include BOTH gold-bearing and abstention cases — generate them withir eval-gen(it adds an abstention slice).--persiststores the floor soir discover ... --min-score autowill abstain by it.--sensitivity-weight(0..1, balanced default); lower it to abstain more readily (precision-leaning). For hybrid, calibrate with--fusion blend(rank-based RRF barely separates — see ir_08) and query under the same fusion. mode: dense | lexical | hybrid. fusion (hybrid only): rrf | blend.--rerank cross-encodercalibrates the floor for a reranked search (its own floor, stored apart from the plain one); query with the same--rerank/--rerank-text.
- ir.cli.coverage(name='reports')[source]¶
Report disk-vs-index coverage for a reports or packages corpus (silent-gap detector).
Independently walks every
*/*/docsand*/*/misc/docstree on disk and diffs the includable reports against what is actually indexed, listing any file that is on disk but missing from the index (rebuild withir buildto fix). Catches the ingestion gaps that back-translation evals structurally cannot — a doc that was never indexed can never be an eval gold id.
- ir.cli.discover(name, query, *, k=10, mode='hybrid', strategy='conservative', disclose=False, min_score=None, fusion='rrf', rerank=None, rerank_text='surface', expand=False, filter=None, variant_weight=1.0, lexical='bm25', prefix=False)[source]¶
Search a corpus, commit to a distractor-robust subset, and show it.
Retrieves
kcandidates, then selects the few high-precision results an agent should act on (or abstains).--discloseadditionally loads each selected item’s body (SKILL.md / file text) via its stored pointer.--min-score autoturns on absolute abstention using the floor calibrated byir calibrate-min-score(or pass a float). mode: dense | lexical | hybrid. fusion (hybrid only): rrf (default) | blend (magnitude-preserving; pair with –min-score for abstention — see ir_08). strategy: conservative | top_k | rel_threshold | score_gap.--rerank cross-encoderadds the calibrated cross-encoder precision stage (--rerank-textpicks what it reads); with--min-score autoit uses the floor calibrated under the same--rerank/--rerank-text.--expandadds the query’s variants from the synonym ledger (ir synonyms).--filtertakes the JSON form of the metadata filter (seesearch).--lexical fts5/--prefix: seesearch(--min-score autois refused with it: the floors are calibrated on BM25 scores).
- ir.cli.eval(name, cases, *, mode='hybrid', k=10)[source]¶
Score a built corpus’s retrieval against a DiscoveryCase JSONL file.
cases: path to a JSONL file of cases (see
ir.eval); each line is a{"query": ..., "gold": [artifact_id, ...]}record (emptygold= an abstention case). Prints recall@k / NDCG@k / MRR / MAP plus the failure-mode taxonomy. mode: dense | lexical | hybrid.
- ir.cli.eval_gen(name, out, *, k=5, abstention_frac=0.15, max_artifacts=None)[source]¶
Generate an eval-case file for a corpus by back-translation (needs aix/LLM).
Writes a DiscoveryCase JSONL set (gold cases + an abstention slice) for the registered corpus name to out, stamping a corpus-signature into the header so the frozen file can be checked against the live corpus later. This command calls an LLM via aix; scoring it afterwards (
ir eval) is offline.
- ir.cli.eval_select(name, cases, *, strategy='conservative', mode='hybrid', k=10, max_k=3, rel=0.9, min_score=None)[source]¶
Score a selector against a DiscoveryCase JSONL file (selection quality).
Reports the conditional commit rate (the selection decision isolated from retrieval) plus selection precision / recall / F1 and abstention accuracy. strategy: conservative | top_k | rel_threshold | score_gap. mode: dense | lexical | hybrid. max_k / rel / min_score tune the commit (see
ir.select);ir sweep-selectsweeps them to find good values.
- ir.cli.maintain(name=None, *, all=False, dry_run=False)[source]¶
Run due background work: incremental reindex, synopsis in its downtime window.
With a name, maintains that corpus; with –all (or no name), every registered corpus. Idempotent and safe to schedule (cron/launchd): it no-ops what is not due. –dry-run reports what would run without doing it.
- ir.cli.register(name, kind, *, root=None, pattern=None, records=None, metadata_keys=None, id_key=None, text_key=None, embedder='default', reindex_on=None, every_hours=None, synopsis=False)[source]¶
Register a named corpus. kind: skills | packages | reports | files | records.
A
recordscorpus is one a package owns:--records module:attrnames the callable yielding its record mappings (e.g.--records annals.records:records),--metadata-keys a,bthe record fields kept as filterable metadata, and--id-key/--text-keythe fields holding the id and the text (defaultsid/text).Background-work policy (optional; smart per-kind defaults otherwise — see
ir.policy): reindex_on (source-change | interval | manual), every_hours (for interval), synopsis (enable LLM synopses, run only in the policy’s downtime window byir maintain).
- ir.cli.schedule(*, every=None, status=False, restart=False, remove=False, dry_run=False, backend=None)[source]¶
Install, inspect, and operate the OS job that runs
ir maintain.Bare
ir scheduleis idempotent: it creates the schedule when there is none, and when there already is one it reports it (interval, definition, whether the OS has it loaded, last run) plus how to operate it, rather than silently reinstalling over a schedule you tuned.An existing definition’s environment is carried forward by every operation, so operating a working schedule from a shell that happens to lack $PP never silently re-points it at a different corpus store.
every: interval as 15m / 2h / 1d, or a plain number of minutes. status: report only; never mutates. restart: reload the definition and re-pin it to this interpreter. remove: stop the schedule and delete its definition. dry_run: print the definition that would be written, and write nothing. backend: launchd | cron (default: whichever this machine provides).
- ir.cli.search(name, query, *, k=10, mode='dense', fusion='rrf', rerank=None, rerank_text='surface', expand=False, filter=None, variant_weight=1.0, lexical='bm25', prefix=False)[source]¶
Search a built corpus and print the top-k hits.
mode: dense (cosine) | lexical (BM25) | hybrid (dense + BM25 fused). fusion (hybrid only): rrf (rank-based, default) | blend (magnitude-preserving; better abstention separability — see ir_08).
--rerank cross-encoderadds the cross-encoder precision stage (needs their[rerank]extra; without it the search warns and keeps the first-stage ranking);--rerank-textpicks what it reads: surface (default) | artifact. Reranked scores are on the reranker’s own scale.--expandalso searches the query’s variants from the synonym ledger (ir synonyms) and fuses them (best score per artifact across the variants; the original query is always one of them;--variant-weight 0.5demotes the variants against the query itself, to keep the original on top; 0 keeps variant-only hits at the tail; a--rerankstage replaces the weighted scores).--filteris a JSON metadata filter in the Mongo-style form ofir.search(filter=...), e.g.--filter '{"project": "dol"}'or'{"source": {"$in": ["a", "b"]}}'; operators: $eq $ne $in $nin $gt $gte $lt $lte $exists, plus $and/$or/$not.--lexical fts5ranks the lexical leg (mode lexical / hybrid) with the persisted SQLite FTS5 index (Porter-stemmed; scores on its own scale) instead of in-memory BM25;--prefixthen also matches the last query word as a prefix.
- ir.cli.sweep_select(name, cases, *, strategy='conservative', mode='hybrid', k=10, objective='selection_f1')[source]¶
Sweep selector knobs (max_k × rel) against a case file; print the grid + best.
Retrieves once per case and reuses the candidates across the whole grid, so the sweep is cheap. Prints a table (one row per setting, best objective first) and the winning max_k / rel. Use it to pick
ir.selectdefaults empirically. objective: selection_f1 | selection_precision | selection_recall | conditional_commit_rate | mean_selected_size. mode: dense | lexical | hybrid.
- ir.cli.synonyms(term=None, *, corpus=None)[source]¶
Show what the synonym ledger knows: a term’s aliases and grep regex, or all entries.
The ledger (
$IR_SYNONYMSor<config dir>/synonyms.jsonl) holds a corpus’s private vocabulary (nicknames, renamed packages, jargon) learned from misses. Use the printed regex inrg/astern grep;ir search --expanduses the same entries. Add withir synonyms-add.
- ir.cli.synonyms_add(terms, *, note='', oneway=False, corpus=None, miss_query=None, found=None)[source]¶
Record corpus vocabulary in the synonym ledger: comma-separated equivalent terms.
ir synonyms-add "acmecorp, acme corp, ac" --note "client nickname". Add only after a verified find that the word made possible;--onewaymakes the first term expand to the others but not back;--corpusscopes the entry.--miss-query "the query that missed" --found "id1,id2"records the miss and what the word found, so the entry can later be replayed throughir.eval(ir.synonyms_eval.replay_ledger) and demoted if it does not help.
- ir.cli.synonyms_replay(name, *, apply=False, mode='lexical')[source]¶
Replay the synonym ledger’s entries against corpus NAME and say which still help.
Each entry recorded with
--miss-query/--foundis searched with and without its expansion throughir.eval:helps,no_effect,hurtsorunverifiable(no provenance, its ids are not in this corpus, or vd missing). Dry run by default;--applybumpsverifiedon a win and demotes ahurts(or ano_effectthat never won). Demoted entries stay in the file but stop expanding searches.