kitt_score 0.1.0

Decision engine at the core of Project KITT — in-memory stateful matching with pluggable scoring backends.
Documentation
# Scoring Core

This note covers `src/scoring/mod.rs`, `src/scoring/score_result.rs`, and `src/scoring/vector/*`.

## `Scorer`

**Defined in:** `src/scoring/mod.rs`

A trait with one method: `score(&LocationView) -> f32`.

### Role
Represents the runtime scoring function for a single action.

### Important property
The engine itself does not store `Box<dyn Scorer>` in the hot path. Instead it lowers scorer specs into [[Modules/Engine and Decision#CompiledScorer]]. The trait remains the abstract extension point.

## `ScorerBuilder`

**Defined in:** `src/scoring/mod.rs`

A trait that compiles a [[#ScorerSpec]] into a concrete scorer.

### Associated type
- `type Scorer: Scorer + 'static`

### Method
- `build(spec, schema) -> Result<Self::Scorer, BuildErr>`

### Role
Amortizes parse/compile work at registration time.

## `ScorerSpec<'a>`

**Defined in:** `src/scoring/mod.rs`

The public declarative scoring surface.

### Variants
- `Predicate(&'a str)`
- `Vector { target: &'a [f32], metric: VectorMetric }`

### Role
This is what the caller puts into [[Modules/Events#ActionIngest]].

## `VectorMetric`

**Defined in:** `src/scoring/mod.rs`

The supported similarity functions for vector scoring.

### Variants
- `Dot`
- `Cosine`

## `VectorBackend`

**Defined in:** `src/scoring/mod.rs`

The backend-selection enum for vector implementations.

### Current variant
- `Linear`

### Important note
The API keeps this enum extensible, but current runtime compilation only uses the linear path.

## `BuildErr`

**Defined in:** `src/scoring/mod.rs`

The public scorer-compilation error enum.

### Variants
- `Parse(String)`
- `UnknownKind(String)`
- `UnknownAttr(String)`
- `Type(String)`
- `Vector(String)`

### Role
This is the canonical failure surface for invalid scorer specifications.

## `ScoreResult`

**Defined in:** `src/scoring/score_result.rs`

The scalar score tuple for one candidate.

### Fields
- `priority: u8`
- `score: f32`

### Semantics
`priority` is copied from action registration; `score` is computed at trigger time.

## `Candidate`

**Defined in:** `src/scoring/score_result.rs`

The decider-facing wrapper around a scored action.

### Fields
- `action_id: ActionId`
- `score: ScoreResult`

### Role
A decider never sees full payloads or scorers; it sees only candidate identities and their score tuples.

## Vector helper functions

### `vector::linear::dot`
Computes the dot product of two equal-length `f32` slices.

### `vector::linear::cosine`
Computes cosine similarity, returning `0.0` if either vector has zero magnitude.

### Runtime dispatch note
Both functions use `pulp::Arch::new().dispatch(...)` so they can take advantage of the best SIMD instructions available on the current CPU.

## Scoring philosophy

The scoring subsystem separates three concerns:
1. **declarative input** via [[#ScorerSpec]],
2. **compilation** via [[#ScorerBuilder]],
3. **execution** via either the predicate VM or the vector linear functions.

That separation is why action registration can be expensive while trigger-time evaluation stays lean.