Files
openclaw/extensions/memory-core
Youssef Hemimy 333a77fde3 fix(memory-core): clamp widen-fallback kNN k to sqlite-vec 4096 limit (#96157)
* fix(memory-core): clamp widen-fallback kNN k to sqlite-vec 4096 limit

The widen fallback in searchVector re-runs the kNN with k = vectorCount
(the full vector table size), unclamped. sqlite-vec hard-caps `k` at 4096,
so once a memory index exceeds 4096 chunks any query that triggers the
fallback fails with "k value in knn query too large".

Clamp the widen re-query to MAX_VECTOR_KNN_K (4096). 4096 oversampled
candidates is far more than enough to feed top-N hybrid ranking, so there
is no meaningful recall loss.

* test(memory-core): cover widen-fallback kNN clamp to sqlite-vec 4096 ceiling

Add two regression tests for the searchVector widen-fallback clamp:
- asserts a >4096-vector widen re-query caps k at 4096 (out-of-range k
  would raise sqlite-vec "k out of range" and kill the whole search)
- asserts a sub-ceiling widen (30) passes through untouched, proving the
  clamp is a ceiling and not a fixed value

Uses a prepare-mock on the KNN/COUNT statements rather than materializing
4097+ real vectors plus the native extension; the assertion is purely on
the k bind handed to the widen re-query.

* fix(memory-core): preserve filtered recall beyond KNN cap

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-07-06 16:53:34 -07:00
..
2026-06-04 21:40:44 -04:00