feat(agent): expose the HNSW parameters in MemoryConfig
Graph degree and the build- and query-time candidate list sizes were constants, so a deployment had no way to trade recall against memory or query speed. They are now `MemoryConfig::hnsw_m`, `hnsw_ef_construction` and `hnsw_ef_search`, persisted with the store and defaulting to exactly the previous behaviour (16, 64, and a query list that scales with `k`). Two things the straightforward version would have got wrong: `clawhdf5-ann` asserts a graph degree of at least 2, so a configured 0 — from a file, or from a caller reading 0 as "use the default" — aborted the process inside the index builder. The store clamps instead, and a test covers it: removing the clamp makes that test panic rather than fail. `ef_search` and the candidate pool handed to score fusion were the same number. Tying the pool to the new setting would mean lowering `ef` for speed also narrows what fusion sees, quietly degrading hybrid results through a knob that looks like it only costs time. They are now independent. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
@@ -28,8 +28,12 @@ impl HDF5Memory {
|
||||
Some(index) if !index.is_empty() && index.dimension() == query_embedding.len() => {
|
||||
// Over-fetch so the merge sees a useful vector pool; cosine
|
||||
// distance from the index converts back to similarity (1 - d).
|
||||
// `ef` is configurable, but the pool the fusion stage sees is
|
||||
// not tied to it: a caller lowering `ef` for speed should not
|
||||
// silently narrow what fusion has to work with.
|
||||
let pool = (k * 8).max(64);
|
||||
let candidates = index.search(query_embedding, pool, pool);
|
||||
let ef = self.hnsw_ef_search(k).max(pool);
|
||||
let candidates = index.search(query_embedding, pool, ef);
|
||||
// A quantised index returns approximate distances, and no
|
||||
// amount of `ef` fixes that — the loss is in the distances,
|
||||
// not the graph. Re-score the pool against the cache's exact
|
||||
|
||||
Reference in New Issue
Block a user