Dsxir. Optimizer. KNNFewShot
(dsxir v0.3.0)
Copy Markdown
Per-call dynamic demo selection optimizer.
At compile time, embeds the trainset under a snapshotted embedder and builds
a per-predictor index. At inference time (via the runtime hook in
Dsxir.Module.Runtime.call/4), each call's inputs are embedded with the
same embedder and the top-K nearest examples are passed as demos.
Options
:k(default5) — neighbors returned per call. Must be>= 1.:embedder—{impl_module, config}tuple. The config MUST include a:modelkey; it becomes theembedder_idon the resulting strategy and a missing:modelreturns{:error, %Dsxir.Errors.Invalid.Configuration{key: :embedder, reason: :missing_model}}at compile. Default: snapshot ofDsxir.Settings.resolve(:lm)at compile time. Credentials are stripped before storage.:embed_fields(default:all) —:allor[atom()]subset of each predictor's signature input fields. Validated per predictor.
The metric argument is accepted (Optimizer behaviour uniformity) and ignored. The trace and forward path are never invoked.
Returned stats
%{k: pos_integer(),
embedder_id: String.t(),
entries_per_predictor: %{atom() => non_neg_integer()},
embedding_tokens: non_neg_integer(),
compile_duration_ms: non_neg_integer()}compiled_with and trainset_hash are written onto program.metadata.