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

Function cbm_sem_random_index

src/semantic/semantic.c:439–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437}
438
439void cbm_sem_random_index(const char *token, cbm_sem_vec_t *out) {
440 memset(out, 0, sizeof(*out));
441 if (!token) {
442 return;
443 }
444
445 /* Try pretrained nomic-embed-code vector first (768d, distilled from 7B). */
446 ensure_pretrained_map();
447 const char *idx_str = cbm_ht_get(g_pretrained_map, token);
448 if (idx_str) {
449 char *end = NULL;
450 long idx = strtol(idx_str, &end, BASE_DECIMAL);
451 if (end != idx_str && idx >= 0 && idx < PRETRAINED_TOKEN_COUNT) {
452 const int8_t *pvec = pretrained_vec_at((int)idx);
453 for (int d = 0; d < CBM_SEM_DIM && d < PRETRAINED_DIM; d++) {
454 out->v[d] = (float)pvec[d] / CBM_SEM_INT8_MAX;
455 }
456 return;
457 }
458 }
459
460 /* Fallback: sparse random vector for tokens not in pretrained vocab. */
461 uint64_t seed = XXH3_64bits(token, strlen(token));
462 for (int i = 0; i < CBM_SEM_SPARSE_NNZE; i++) {
463 uint64_t h = XXH3_64bits_withSeed(&i, sizeof(i), seed + RI_SEED_BASE);
464 int pos = (int)(h % CBM_SEM_DIM);
465 float sign = (h & SKIP_ONE) ? CBM_SEM_UNIT_POS : -CBM_SEM_UNIT_POS;
466 out->v[pos] += sign;
467 }
468}
469
470void cbm_sem_normalize(cbm_sem_vec_t *v) {
471 if (!v) {

Callers 4

build_api_vecFunction · 0.85
build_type_vecFunction · 0.85
build_deco_vecFunction · 0.85
test_semantic.cFile · 0.85

Calls 2

ensure_pretrained_mapFunction · 0.85
cbm_ht_getFunction · 0.85

Tested by

no test coverage detected