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

Function cbm_sem_cosine

src/semantic/semantic.c:372–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370/* ── Dense vector operations ─────────────────────────────────────── */
371
372float cbm_sem_cosine(const cbm_sem_vec_t *a, const cbm_sem_vec_t *b) {
373 if (!a || !b) {
374 return 0.0F;
375 }
376 float dot = 0.0F;
377 float mag_a = 0.0F;
378 float mag_b = 0.0F;
379 for (int i = 0; i < CBM_SEM_DIM; i++) {
380 dot += a->v[i] * b->v[i];
381 mag_a += a->v[i] * a->v[i];
382 mag_b += b->v[i] * b->v[i];
383 }
384 float denom = sqrtf(mag_a) * sqrtf(mag_b);
385 if (denom < CBM_SEM_DENOM_EPS) {
386 return 0.0F;
387 }
388 return dot / denom;
389}
390
391/* Pretrained token lookup table — built lazily on first use. */
392static CBMHashTable *g_pretrained_map = NULL;

Callers 1

test_semantic.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected