mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor: add braces to l2Normalize guard clause in embeddings
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
8160d80f35
commit
fc0fdebd8b
@@ -8,7 +8,9 @@ import { importNodeLlamaCpp } from "./node-llama.js";
|
||||
|
||||
function l2Normalize(vec: number[]): number[] {
|
||||
const magnitude = Math.sqrt(vec.reduce((sum, x) => sum + x * x, 0));
|
||||
if (!Number.isFinite(magnitude) || magnitude < 1e-10) return vec;
|
||||
if (!Number.isFinite(magnitude) || magnitude < 1e-10) {
|
||||
return vec;
|
||||
}
|
||||
return vec.map((x) => x / magnitude);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user