Skip to content

fix: cosineSim silently truncates on dimension mismatch #25

@sparkling

Description

@sparkling

Bug

cosineSim() in three files silently truncates or zero-pads when vector dimensions differ, producing meaningless similarity scores.

  • memory-initializer.ts:2468Math.min(a.length, b.length) truncates longer vector
  • memory-bridge.ts:3589 — same truncation
  • intelligence.ts:595Math.max + zero-pad (?? 0) — geometrically wrong

Impact

Any user whose stored vectors have a different dimension than query vectors gets wrong search results with no error. This happens silently when fallback paths produce 384-dim vectors while the primary path uses 768-dim.

Fix

All three functions now throw on a.length !== b.length. Surrounding try/catch blocks in callers handle the error gracefully (score of 0 or skip the entry).

Commit: ff50410 (ADR-0076 Track A)

ADR Reference

ADR-0075 Problem 2, ADR-0076 A1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions