Skip to content

fix(selfhost): skip dimension-mismatched vectors in the SQLite vectorize adapter instead of silently truncating - #8792

Merged
loopover-orb[bot] merged 2 commits into
mainfrom
fix/sqlite-vectorize-dimension-guard
Jul 26, 2026
Merged

fix(selfhost): skip dimension-mismatched vectors in the SQLite vectorize adapter instead of silently truncating#8792
loopover-orb[bot] merged 2 commits into
mainfrom
fix/sqlite-vectorize-dimension-guard

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

RAG-audit hardening from epic #8757. cosineSimilarity's Math.min(a.length, b.length) silently scored mixed-width vectors over the shorter prefix — wrong similarity results if an operator ever swaps embedding models without a full reindex. Qdrant hard-fails this at the collection level and pgvector raises; the SQLite adapter was the only backend that silently computed garbage.

Changes

  • src/selfhost/vectorize.ts — the query path skips any stored vector whose width differs from the query's (degrade-to-fewer-candidates, the RAG pipeline's established fail-safe posture) and emits one sqlite_vectorize_dimension_mismatch WARN per query (not per row) naming the query width and the deduped mismatched widths.
  • cosineSimilarity itself is untouched (pure function, existing behavior pinned by its own tests).

Test plan

  • npm run typecheck — clean
  • 3 new tests: mismatch skipped + single warn with both widths; steady-state silence; width dedupe with sorted output and score ordering preserved — 10/10 unit + 15/15 contract suite
  • Changed range: 0 uncovered statements/branches

Closes #8766

JSONbored and others added 2 commits July 25, 2026 22:57
…ize adapter instead of silently truncating (#8766)

cosineSimilarity's Math.min(a.length, b.length) meant a store containing
mixed-width vectors (an operator swapping embedding models without a full
reindex) silently produced wrong similarity scores over the shorter prefix.
Qdrant hard-fails this at the collection level and pgvector raises — the
SQLite adapter was the odd one out.

A mismatched-width row is now skipped (degrade-to-fewer-candidates, the RAG
pipeline's established fail-safe posture) with one WARN per query naming the
query width and the deduped set of mismatched stored widths.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 26, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
loopover-ui c1572db Commit Preview URL

Branch Preview URL
Jul 26 2026, 06:00 AM

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored JSONbored self-assigned this Jul 26, 2026
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (f4c946b) to head (c1572db).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8792      +/-   ##
==========================================
+ Coverage   90.56%   92.26%   +1.70%     
==========================================
  Files          96      797     +701     
  Lines       22490    79563   +57073     
  Branches     3884    24111   +20227     
==========================================
+ Hits        20367    73408   +53041     
- Misses       1945     5090    +3145     
- Partials      178     1065     +887     
Flag Coverage Δ
backend 92.93% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/selfhost/vectorize.ts 100.00% <100.00%> (ø)

... and 700 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 06:09:57 UTC

2 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
The AI review returned non-blocking notes for this change but did not include a separate narrative summary. Review the nits below before deciding this PR.

Nits — 5 non-blocking
  • src/selfhost/vectorize.ts:66-84 — the inline comment block is quite long (7 lines) for a single guard; consider trimming it since the PR description already carries most of this rationale.
  • The external brief flags `console.warn` at vectorize.ts:83 as a 'debug leftover', but this is clearly an intentional structured operational log (JSON with an `event` field), not debug output left behind by accident — worth noting the flag is a false positive.
  • No corresponding dimension-mismatch guard/log was added to pg-vectorize.ts, so if that backend has the same Math.min-style truncation risk it remains silent there — worth confirming whether pgvector's own DB-level raise already covers this (per the PR description it does).
  • Consider whether the WARN should also fire on `upsert` when a caller inserts a vector whose width doesn't match existing rows for the same namespace, giving earlier visibility than waiting for the next query.
  • The `mismatchedWidths` Set could be seeded lazily only when at least one mismatch is found (already done) — no change needed, just confirms current design is fine.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8766
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 13 registered-repo PR(s), 13 merged, 275 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 13 PR(s), 275 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff adds a width check that skips mismatched vectors instead of scoring them, emits a single deduplicated WARN per query naming both widths, and adds tests covering skip behavior, silent steady-state, and dedupe/ordering as requested.

Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, Ruby, Go, MDX, Shell, Solidity, JavaScript
  • Official Gittensor activity: 13 PR(s), 275 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Treat this as maintainer-lane context rather than normal contributor-lane activity.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 637e43f into main Jul 26, 2026
8 checks passed
@loopover-orb
loopover-orb Bot deleted the fix/sqlite-vectorize-dimension-guard branch July 26, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selfhost/rag: reject dimension-mismatched vectors in the SQLite vectorize adapter instead of silently truncating

1 participant