# `Tune.KNN`
[🔗](https://github.com/mikehostetler/tune/blob/v0.5.0/lib/tune/knn.ex#L1)

A program that selects nearby training examples for each input.

For every call it ranks the declared pool by similarity to the input,
takes the `k` nearest rows (pool order breaks ties), runs the inner program
on each neighbor under the explicit `:teacher` role to bootstrap
demonstrations from successful trajectories, adds labeled demonstrations
when configured, and then runs the inner program with those demonstrations
under the active role. Every teacher call is a managed call in the same
execution, so the run needs a teacher configuration and an explicit
`:max_model_calls`.

The pool is a declared JSON parameter named `"knn_pool"`, so it is saved in
artifacts. The vectorizer is application code and is never saved. The
default vectorizer is a bag of lowercase words over the input values.

# `t`

```elixir
@type t() :: %Tune.KNN{
  inner: term(),
  k: term(),
  max_bootstrapped_demos: term(),
  max_labeled_demos: term(),
  pool: term(),
  vectorizer: term()
}
```

# `new`

```elixir
@spec new(Tune.Program.t(), keyword()) :: {:ok, t()} | {:error, Exception.t()}
```

Builds a KNN program around an inner program.

Options: `:pool` (training rows), `:k`, `:max_bootstrapped_demos`,
`:max_labeled_demos`, and `:vectorizer` (a function of an input map returning
a list of numbers, or a map of term to weight).

# `pool_schema`

```elixir
@spec pool_schema(Tune.Signature.t()) :: Zoi.schema()
```

Returns the JSON schema used for the pool parameter.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
