mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-07-12 03:12:11 +02:00
perf(engine): normalize with the already-computed norm in embedding validation
Greptile follow-up: the zero-norm guard computed the norm and then normalize_vector recomputed it (a wasted pass at 1536+ dims), with the inner zero guard unreachable by construction. Normalize in place with the validated norm; normalize_vector stays for its other caller (the mock provider).
This commit is contained in:
parent
4834c6a0dc
commit
db96e7000d
1 changed files with 8 additions and 1 deletions
|
|
@ -579,7 +579,14 @@ fn validate_and_normalize_embedding(
|
|||
if norm <= f32::EPSILON {
|
||||
return Err("embedding has zero norm (no direction)".to_string());
|
||||
}
|
||||
Ok(normalize_vector(values))
|
||||
// Normalize in place with the norm just computed — `normalize_vector`
|
||||
// would recompute it (and its zero guard is unreachable here, since a
|
||||
// zero norm already returned Err above).
|
||||
let mut values = values;
|
||||
for value in &mut values {
|
||||
*value /= norm;
|
||||
}
|
||||
Ok(values)
|
||||
}
|
||||
|
||||
fn normalize_vector(mut values: Vec<f32>) -> Vec<f32> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue