Dsxir.Optimizer.KNNFewShot (dsxir v0.2.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 (default 5) — neighbors returned per call. Must be >= 1.
  • :embedder{impl_module, config} tuple. The config MUST include a :model key; it becomes the embedder_id on the resulting strategy and a missing :model returns {:error, %Dsxir.Errors.Invalid.Configuration{key: :embedder, reason: :missing_model}} at compile. Default: snapshot of Dsxir.Settings.resolve(:lm) at compile time. Credentials are stripped before storage.
  • :embed_fields (default :all) — :all or [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.