Commit Graph

4 Commits

Author SHA1 Message Date
Martin Vogel 83c137d2a5 feat: complete shared daemon lifecycle
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-07-18 01:26:08 +02:00
Martin Vogel 0e00ef5702 feat: coordinate concurrent CBM sessions
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-07-16 19:20:46 +02:00
Martin Vogel d83ab50a19 perf(semantic): quantize the resident semantic vectors (rotated 4-bit SQ)
The semantic pass kept four dense 768-float vectors resident per function
(ri/api/type/deco = 12.3 KB per func, ~9.4 GB transient on the linux kernel)
solely so candidate pairs could be cosine-scored after LSH. Replace the
resident floats with 4-bit quantized codes (~0.5 KB each, ~6x): new
src/semantic/rotsq.{h,c} — rotated scalar quantization from the RaBitQ
family of algorithms (Gao et al., SIGMOD 2024/2025), implemented from the
papers in plain C11 (no Eigen/library dependency): a deterministic
XXH3-seeded +-1 diagonal followed by a Fast Walsh-Hadamard rotation
(768 -> 1024 padded) spreads vector mass so per-vector scalar quantization
is near-optimal; the inner product is recovered from the codes with the
exact SQ expansion (one u8 integer dot + four multiplies) — a deterministic
pure function of the codes. Named rotsq, not rabitq: this is the family
core, not the papers' exact codebook construction.

Producers build each dense vector in a worker-local buffer, encode, and
discard; the int8 qvec export is unchanged. LSH signatures are computed
from DEQUANTIZED codes against hyperplanes in the rotated basis — random
hyperplanes are basis-agnostic, so no dense originals are retained and the
phase structure is untouched.

Estimator quality gated by sem_rotsq_ip_error_bounds (seeded vectors:
mean error < 1%, max < 4% of unit scale, ASan-green). Effect on output:
multi-threaded determinism preserved (xfs: two runs byte-identical);
SEMANTICALLY_RELATED edges shift once as scores move within ~1% of the
0.75 threshold (xfs: ~130 -> 203; sampled new pairs are high quality —
alloc/free, read-verify and collapse/insert families).

Suites: semantic 33 (incl. the new estimator gate), simhash 24,
pipeline 216 — zero failures.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-07-06 21:52:37 +02:00
Raul Acosta 6919ae669f test: add 56 unit tests for semantic, slab_alloc, and ast_profile modules
Add focused unit tests for three previously untested modules:

- tests/test_semantic.c (32 tests): cbm_sem_tokenize (camel/snake/dot/abbrev),
  cbm_sem_cosine (identical/orthogonal/zero/negative/null),
  cbm_sem_normalize, cbm_sem_vec_add_scaled,
  cbm_sem_random_index (determinism), cbm_sem_proximity,
  cbm_sem_diffuse, corpus lifecycle, IDF, config

- tests/test_slab_alloc.c (14 tests): slab malloc/free (≤64B and >64B),
  calloc zeroing/overflow, realloc (shrink/promote/same-size),
  free-list cycling, pointer uniqueness, thread reset

- tests/test_ast_profile.c (10 tests): to_str/from_str round-trip
  (25 fields), null/empty/invalid inputs, to_vector range/saturation

All 56 tests pass with ASan+UBSan. Registered in Makefile.cbm
and test_main.c.

Signed-off-by: Raul Acosta <raulacosta@users.noreply.github.com>
Signed-off-by: Raul Acosta <raul.acosta.mmm@gmail.com>
2026-06-28 21:57:35 -06:00