Repository navigation
fix(knowledge): reject invalid embeddings before caching - #1073
Conversation
dovvnloading
left a comment
There was a problem hiding this comment.
Maintainer review via ChatGPT — no blocking findings.
Reviewed all seven changed files against #1037: validation occurs on the actual float32 representation before writing a batch; SQLite BEGIN IMMEDIATE serializes model-wide dimension checks and writes; failed batches remain retryable; cosine math uses float64 and clamps scores; corrupt legacy vectors have an explicit model-scoped offline recovery path, with keyword fallback and cloud consent preserved. Regression tests cover malformed vectors, atomic retry, cross-collection dimensions, legacy repair and extreme values. The latest main comparison showed two intervening commits touching unrelated workflow UI files only.
Verified GitHub Actions run 45604990518 for this head: all four required checks succeeded (Python including pytest, frontend, build/install and POSIX); Playwright boot-smoke was skipped. Static review and CI verification only, no independent local/manual app test. The connected account is also the PR author, so recording a review comment rather than self-approval. No code changes requested.
Summary
Fixes #1037. A provider can currently return vectors with invalid shape, incompatible dimensions, nonfinite float32 values, or zero norm; the cache marks them as embedded, preventing an ordinary retry. Validate each full batch before committing it, enforce a consistent model-wide dimension under SQLite's write lock, and provide an explicit model-cache repair procedure for existing stale rows.
What Changed
docs/KNOWLEDGE_RETRIEVAL.md. It only deletes derived embeddings, not documents, chunks, keyword indexes or another model's cache.Why
A transient invalid provider response should not permanently poison the semantic index. A changed model dimension should require an explicit cache rebuild rather than silently mixing incompatible vector spaces. Repair is intentionally opt-in so a transient query failure cannot trigger a costly or unapproved rebuild.
Validation
python -m compileall -q .passes (run from the repo root - matches CI)python -m pytest -qpasses (run from the repo root - matches CI)cd web_ui && npm run checkpasses (matches CI)Passed an isolated Python smoke check using the proposed validation/write/reset logic with NumPy 2.3.5 and a minimal SQLite schema: 12 malformed input cases, cosine scoring at both float32 extremes, mixed-batch rollback, mismatch between batches, legacy mixed-cache rejection, model-scoped reset and retry. This is not the repository test suite: the execution environment could not resolve github.com to clone the repository. The added regression tests require CI validation.
UI Notes
Additional Context
No new dependencies, schema migration, wire contract or UI changes. Model-wide cache recovery is deliberately a documented offline maintenance action; it does not automatically remove embeddings or change cloud consent. Main advanced during implementation; please let CI validate the PR against the current base.