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

Function quantize

src/context/sqlite-index.ts:68–78  ·  view source on GitHub ↗
(vec: number[])

Source from the content-addressed store, hash-verified

66
67/** Symmetric per-vector int8 quantization. */
68export function quantize(vec: number[]): QuantizedVec {
69 let max = 0;
70 for (const v of vec) { const a = Math.abs(v); if (a > max) max = a; }
71 const scale = max === 0 ? 1 : max / 127;
72 const bytes = new Int8Array(vec.length);
73 for (let i = 0; i < vec.length; i++) {
74 const q = Math.round(vec[i]! / scale);
75 bytes[i] = q > 127 ? 127 : q < -127 ? -127 : q;
76 }
77 return { scale, bytes };
78}
79
80/**
81 * Cosine similarity between a (full-precision) query vector and a quantized

Callers 2

buildSqliteIndexFunction · 0.85

Calls 1

absMethod · 0.80

Tested by

no test coverage detected