feat(agent): new stores default to float16 embeddings
MemoryConfig::float16 now defaults to true for new stores, on measurement: on the full LongMemEval haystack with real MiniLM embeddings every retrieval metric matched f32 (previous commit), and at 100K the file is 48% smaller with faster checkpoints and opens. Existing stores are unaffected: every agent store has recorded `float16 = false` in /meta and keeps it. A test opens the v2.5.0 fixture, saves and checkpoints, and checks the embeddings are still f32 with the old rows bit-identical; another checks a new store is float16. CLI: `create --f32` opts out; like `--f32-index` it only ever switches the default off. `--float16` is still accepted and now a no-op. Values beyond +-65504 are refused, so f32 remains the choice for unnormalised vectors — the upgrade note says so. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -206,3 +206,55 @@ fn wal_replay_rounds_like_a_live_save() {
|
||||
assert_eq!(recovered.count(), 30);
|
||||
assert_eq!(search_bits(&mut recovered, 77), live);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_stores_default_to_float16() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let path = dir.path().join("default.h5");
|
||||
let mut m = HDF5Memory::create(MemoryConfig::new(path.clone(), "agent", DIM)).unwrap();
|
||||
assert!(m.config().float16);
|
||||
m.save_batch((0..10).map(entry).collect()).unwrap();
|
||||
drop(m);
|
||||
assert_eq!(embeddings_dtype_and_values(&path).0, "Other(\"float16\")");
|
||||
assert!(HDF5Memory::open(&path).unwrap().config().float16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_existing_f32_store_stays_f32() {
|
||||
// Written by the v2.5.0 CLI, with `float16 = 0` in /meta (every agent
|
||||
// store has recorded it). Flipping the default for new stores must not
|
||||
// reach back and round an existing store's embeddings.
|
||||
let dir = TempDir::new().unwrap();
|
||||
let path = dir.path().join("legacy.h5");
|
||||
std::fs::copy(
|
||||
concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/fixtures/store_v2_5_0.h5"
|
||||
),
|
||||
&path,
|
||||
)
|
||||
.unwrap();
|
||||
let before = embeddings_dtype_and_values(&path);
|
||||
assert_eq!(before.0, "F32");
|
||||
|
||||
let mut m = HDF5Memory::open(&path).unwrap();
|
||||
assert!(!m.config().float16, "an old store must reopen as f32");
|
||||
let dim = m.config().embedding_dim;
|
||||
let odd: Vec<f32> = (0..dim).map(|i| 0.1 + i as f32 * 1e-4).collect();
|
||||
m.save_batch(vec![MemoryEntry {
|
||||
chunk: "added after the upgrade".into(),
|
||||
embedding: odd.clone(),
|
||||
source_channel: "test".into(),
|
||||
timestamp: 1.0,
|
||||
session_id: "s".into(),
|
||||
tags: String::new(),
|
||||
}])
|
||||
.unwrap();
|
||||
drop(m);
|
||||
|
||||
// Checkpointed: still f32, the old rows untouched and the new one exact.
|
||||
let (dtype, values) = embeddings_dtype_and_values(&path);
|
||||
assert_eq!(dtype, "F32");
|
||||
assert_eq!(&values[..before.1.len()], before.1.as_slice());
|
||||
assert_eq!(&values[before.1.len()..], odd.as_slice());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user