MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / vs_normalize_and_quantize

Function vs_normalize_and_quantize

src/store/store.c:12159–12173  ·  view source on GitHub ↗

Normalize + int8 quantize a float vector. Returns false if the vector is * effectively zero (magnitude below epsilon), in which case `dst` is left in * an indeterminate state and the caller should skip this keyword. */

Source from the content-addressed store, hash-verified

12157 * effectively zero (magnitude below epsilon), in which case `dst` is left in
12158 * an indeterminate state and the caller should skip this keyword. */
12159static bool vs_normalize_and_quantize(const float *src, int8_t *dst) {
12160 float mag = 0.0F;
12161 for (int d = 0; d < VS_VEC_DIM; d++) {
12162 mag += src[d] * src[d];
12163 }
12164 mag = sqrtf(mag);
12165 if (mag < CBM_STORE_DENOM_EPS_F) {
12166 return false;
12167 }
12168 float inv = CBM_STORE_UNIT_POS_F / mag;
12169 for (int d = 0; d < VS_VEC_DIM; d++) {
12170 dst[d] = vs_clamp_int8(src[d] * inv * CBM_STORE_INT8_MAX);
12171 }
12172 return true;
12173}
12174
12175/* Build int8 query vectors for each keyword. Returns the number of
12176 * successfully built vectors (may be less than keyword_count when some

Callers 1

vs_build_keyword_vectorsFunction · 0.85

Calls 1

vs_clamp_int8Function · 0.85

Tested by

no test coverage detected