mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix: handle non‑finite magnitude in L2 normalization and remove stale test reset
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
61c82998cc
commit
8160d80f35
@@ -330,7 +330,6 @@ describe("embedding provider local fallback", () => {
|
||||
describe("local embedding L2 normalization", () => {
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
vi.doUnmock("./node-llama.js");
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import { importNodeLlamaCpp } from "./node-llama.js";
|
||||
|
||||
function l2Normalize(vec: number[]): number[] {
|
||||
const magnitude = Math.sqrt(vec.reduce((sum, x) => sum + x * x, 0));
|
||||
if (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