MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / cosineQuantized

Function cosineQuantized

src/context/sqlite-index.ts:85–97  ·  view source on GitHub ↗
(query: number[], q: QuantizedVec)

Source from the content-addressed store, hash-verified

83 * Running the dot product in a tight loop over the Int8Array is the hot path.
84 */
85export function cosineQuantized(query: number[], q: QuantizedVec): number {
86 const { scale, bytes } = q;
87 const len = Math.min(query.length, bytes.length);
88 let dot = 0, nq = 0, ns = 0;
89 for (let i = 0; i < len; i++) {
90 const s = bytes[i]! * scale;
91 dot += query[i]! * s;
92 nq += query[i]! * query[i]!;
93 ns += s * s;
94 }
95 if (nq === 0 || ns === 0) return 0;
96 return dot / (Math.sqrt(nq) * Math.sqrt(ns));
97}
98
99// ── Build / open / search ─────────────────────────────────────────────────────
100

Callers 2

searchSqliteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected