mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-13 11:21:42 -04:00
fix(router): production-ready request router + auto-size batch for embedding/rerank (#10104)
* fix(router): score classifier production-readiness Conversation trimming runs through the classifier model's chat template and trims by exact token count, sized to the model's n_batch which is now scaled to context so long probes can't crash the backend. Missing chat_message templates are a hard error at router build time. Router- facing factories (Embedder/Scorer/Reranker/TokenCounter) re-resolve ModelConfig per call so a model installed post-startup doesn't bind a stub Backend="" config and silently fall into the loader's auto- iterate path. New 'vector_store' backend trace recorded inside localVectorStore on every Search/Insert — including the backend-load-failure path that previously vanished into an xlog.Warn — with outcome tagging (hit/miss/empty_store/backend_load_error/find_error/insert_error/ok). Companion cleanup drops misleading similarity:0 and input_tokens_count:0 from non-hit and text-mode traces. Gallery local-store-development aliases to 'local-store' so the master image satisfies pkg/model.LocalStoreBackend lookups from the embedding cache. Misc: llama-cpp TokenizeString reads the correct 'prompt' JSON key (the original bug); ModelTokenize nil-guard; non-fatal mitm proxy startup; PII 'route_local' renamed to 'allow' with docs/UI in sync; model-editor footer no longer eats the edit area on small screens; several config-editor template/dropdown/section fixes. Tests: e2e router specs (casual/code-hint + long-conversation trim), vector_store trace specs, lazy-factory specs, gallery dev-alias resolution, Playwright trace badge + scroll regression. Assisted-by: Claude:claude-opus-4-7 [Claude Code] Signed-off-by: Richard Palethorpe <io@richiejp.com> * feat(backend): auto-size batch to context for embedding and rerank models Embedding and rerank models pool over the whole input in a single physical batch (n_ubatch). With batch left at the 512 default, the backend rejects longer inputs with "input is too large to process", silently capping a large-context embedder (e.g. 8k/32k) at 512 tokens. Size n_batch to the context for these single-pass usecases, mirroring the existing FLAG_SCORE behaviour; an explicit batch: still wins. Extracts EffectiveContextSize/EffectiveBatchSize from grpcModelOpts so the effective decode window has one home for other callers to reuse. Adds an e2e-aio regression test that embeds a >512-token input. The AIO embedding model is switched to nomic-embed-text-v1.5 (2048 context) because the previous granite model was capped at 512 tokens and could not exercise the larger batch. Assisted-by: claude-code:claude-opus-4-8 [Claude Code] Signed-off-by: Richard Palethorpe <io@richiejp.com> * fix(gallery): raise arch-router scoring output cap via parallel:64 Scoring decodes the whole prompt+candidate in a single llama_decode and reads one logit row per candidate token. The vendored llama.cpp server caps causal output rows at n_parallel, so the default of 1 aborts with GGML_ASSERT(n_outputs_max <= cparams.n_outputs_max) on multi-token route labels. Set options: [parallel:64] on both arch-router quant entries to lift the cap; kv_unified (the grpc-server default) keeps the full context per sequence, so this does not split the KV cache. Assisted-by: claude-code:claude-opus-4-8 [Claude Code] Signed-off-by: Richard Palethorpe <io@richiejp.com> --------- Signed-off-by: Richard Palethorpe <io@richiejp.com>
This commit is contained in:
committed by
GitHub
parent
56cc4f63fc
commit
085fc53bbc
@@ -47,7 +47,7 @@ in a model's YAML always wins over the backend default.
|
||||
### Pattern catalog
|
||||
|
||||
The built-in regex tier ships six patterns. Each has a default action
|
||||
(`mask`, `block`, or `route_local`) and a length cap that prevents
|
||||
(`mask`, `block`, or `allow`) and a length cap that prevents
|
||||
pathological inputs from blowing up scanning time:
|
||||
|
||||
| ID | Description | Default action | Max length |
|
||||
@@ -61,9 +61,11 @@ pathological inputs from blowing up scanning time:
|
||||
|
||||
`mask` rewrites the match to `[REDACTED:<id>]` in the request body before
|
||||
forwarding. `block` returns HTTP 400 with `error.type=pii_blocked` to the
|
||||
client without forwarding. `route_local` is reserved for the routing
|
||||
integration (see below) and falls back to `mask` when no local route is
|
||||
available.
|
||||
client without forwarding. `allow` detects and logs the match (a PIIEvent
|
||||
is still recorded) but leaves the text unchanged — use it to downgrade a
|
||||
pattern's default for a model while keeping it visible in the audit log.
|
||||
It is also the foundation for surfacing detected-PII labels to the router,
|
||||
a planned router-model feature.
|
||||
|
||||
### Per-model configuration
|
||||
|
||||
@@ -82,8 +84,7 @@ pii:
|
||||
```yaml
|
||||
# Cloud-bound model — defaults to enabled because backend is cloud-proxy.
|
||||
# Tighten api_key_prefix from the global default and downgrade email to
|
||||
# route_local so emails route to a local model rather than leaving the
|
||||
# network.
|
||||
# allow so emails are logged but pass through unchanged.
|
||||
name: claude-strict
|
||||
backend: cloud-proxy
|
||||
proxy:
|
||||
@@ -96,7 +97,7 @@ pii:
|
||||
- id: api_key_prefix
|
||||
action: block # already the default, made explicit for audit
|
||||
- id: email
|
||||
action: route_local
|
||||
action: allow
|
||||
```
|
||||
|
||||
The regex itself stays global — only the action is settable per-model.
|
||||
@@ -154,7 +155,7 @@ and **Events**. The Filtering tab shows:
|
||||
| GET | `/api/pii/patterns` | any | Live pattern list with current actions. Used by the UI catalogue. |
|
||||
| POST | `/api/pii/test` | any | Dry-run the redactor on `{"text":"..."}`. Returns hits and the would-be-rewritten body. Does not write to the event log. |
|
||||
| GET | `/api/pii/events` | admin | Recent middleware events — PII redactions, MITM connect/traffic, admission denials. Filterable by `correlation_id`, `user_id`, `pattern_id`, `kind`. |
|
||||
| PUT | `/api/pii/patterns/:id` | admin | Update a pattern in-process. Body accepts `{"action":"mask"\|"block"\|"route_local"}` and/or `{"disabled":true\|false}`. Transient — reverts on restart unless persisted. |
|
||||
| PUT | `/api/pii/patterns/:id` | admin | Update a pattern in-process. Body accepts `{"action":"mask"\|"block"\|"allow"}` and/or `{"disabled":true\|false}`. Transient — reverts on restart unless persisted. |
|
||||
| POST | `/api/pii/patterns/persist` | admin | Snapshot the live per-pattern (action, disabled) state into `runtime_settings.json`. |
|
||||
| GET | `/api/middleware/status` | admin | Aggregated dashboard data: patterns + per-model resolved state + router status + MITM status + admission status. One round-trip for the UI. |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user