chore: remove unused embedding cache export (#5355)

Integrated into release/v3.8.41 — dead-code removal (typecheck:core EXIT 0, 102 affected tests green, fabricated-docs clean). Thanks @JxnLexn.
This commit is contained in:
Jan Leon
2026-06-29 17:05:21 +02:00
committed by GitHub
parent fc173c5857
commit 605c4d4ece
2 changed files with 75 additions and 66 deletions

View File

@@ -15,16 +15,10 @@ import type {
import { embedRemote } from "./remote";
import { embedStatic } from "./staticPotion";
import { embedTransformers } from "./transformersLocal";
import {
buildCacheKey,
get as cacheGet,
set as cacheSet,
invalidate as cacheInvalidate,
} from "./cache";
import { buildCacheKey, get as cacheGet, set as cacheSet } from "./cache";
const STATIC_MODEL = process.env.MEMORY_STATIC_MODEL || "minishlab/potion-base-8M";
const TRANSFORMERS_MODEL =
process.env.MEMORY_TRANSFORMERS_MODEL || "Xenova/all-MiniLM-L6-v2";
const TRANSFORMERS_MODEL = process.env.MEMORY_TRANSFORMERS_MODEL || "Xenova/all-MiniLM-L6-v2";
/** Build an EmbeddingResolution for "no source available" cases. */
function noSource(reason: string): EmbeddingResolution {
@@ -184,12 +178,7 @@ export async function embed(
};
}
const cacheKey = buildCacheKey(
resolution.source,
resolution.model,
resolution.dimensions,
text
);
const cacheKey = buildCacheKey(resolution.source, resolution.model, resolution.dimensions, text);
const cached = cacheGet(cacheKey);
if (cached) {
@@ -290,11 +279,3 @@ export async function listEmbeddingProviders(): Promise<EmbeddingProviderListing
return result;
}
/**
* Drop the in-memory embedding cache.
* Called when settings (model/source) change.
*/
export function invalidateEmbeddingCache(): void {
cacheInvalidate();
}

View File

@@ -1,6 +1,7 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { resolveEmbeddingSource } from "../../src/lib/memory/embedding/index";
const embeddingPublicApi = await import("../../src/lib/memory/embedding/index");
import type { MemorySettingsExtended } from "../../src/shared/schemas/memory";
function makeSettings(overrides: Partial<MemorySettingsExtended> = {}): MemorySettingsExtended {
@@ -17,6 +18,10 @@ function makeSettings(overrides: Partial<MemorySettingsExtended> = {}): MemorySe
}
describe("resolveEmbeddingSource", () => {
it("public surface excludes unused cache invalidation wrapper", () => {
assert.equal("invalidateEmbeddingCache" in embeddingPublicApi, false);
});
it("auto + no key + no static + no transformers => source null", () => {
const res = resolveEmbeddingSource(makeSettings({ embeddingSource: "auto" }));
assert.strictEqual(res.source, null);
@@ -28,39 +33,47 @@ describe("resolveEmbeddingSource", () => {
});
it("auto + embeddingProviderModel set to openai/... => source remote", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "auto",
embeddingProviderModel: "openai/text-embedding-3-small",
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "auto",
embeddingProviderModel: "openai/text-embedding-3-small",
})
);
assert.strictEqual(res.source, "remote");
assert.strictEqual(res.model, "openai/text-embedding-3-small");
});
it("auto + no model + staticEnabled=true => source static", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "auto",
embeddingProviderModel: null,
staticEnabled: true,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "auto",
embeddingProviderModel: null,
staticEnabled: true,
})
);
assert.strictEqual(res.source, "static");
assert.ok(res.model !== null);
});
it("auto + no model + staticEnabled=false + transformersEnabled=true => source transformers", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "auto",
embeddingProviderModel: null,
staticEnabled: false,
transformersEnabled: true,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "auto",
embeddingProviderModel: null,
staticEnabled: false,
transformersEnabled: true,
})
);
assert.strictEqual(res.source, "transformers");
});
it("explicit 'remote' + no model => source null with no_key reason", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "remote",
embeddingProviderModel: null,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "remote",
embeddingProviderModel: null,
})
);
assert.strictEqual(res.source, null);
// The reason must reference the missing key, not just be non-empty.
assert.ok(
@@ -70,43 +83,53 @@ describe("resolveEmbeddingSource", () => {
});
it("explicit 'remote' + model set => source remote (no fallback)", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "remote",
embeddingProviderModel: "openai/text-embedding-3-small",
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "remote",
embeddingProviderModel: "openai/text-embedding-3-small",
})
);
assert.strictEqual(res.source, "remote");
assert.strictEqual(res.model, "openai/text-embedding-3-small");
});
it("explicit 'static' + staticEnabled=true => source static", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "static",
staticEnabled: true,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "static",
staticEnabled: true,
})
);
assert.strictEqual(res.source, "static");
});
it("explicit 'static' + staticEnabled=false => source null", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "static",
staticEnabled: false,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "static",
staticEnabled: false,
})
);
assert.strictEqual(res.source, null);
});
it("explicit 'transformers' + transformersEnabled=true => source transformers", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "transformers",
transformersEnabled: true,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "transformers",
transformersEnabled: true,
})
);
assert.strictEqual(res.source, "transformers");
});
it("explicit 'transformers' + transformersEnabled=false => source null", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "transformers",
transformersEnabled: false,
}));
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "transformers",
transformersEnabled: false,
})
);
assert.strictEqual(res.source, null);
});
@@ -121,11 +144,16 @@ describe("resolveEmbeddingSource", () => {
});
it("signature contains source:model:dim components", () => {
const res = resolveEmbeddingSource(makeSettings({
embeddingSource: "static",
staticEnabled: true,
}));
assert.ok(res.signature.includes("static"), `signature should contain 'static': ${res.signature}`);
const res = resolveEmbeddingSource(
makeSettings({
embeddingSource: "static",
staticEnabled: true,
})
);
assert.ok(
res.signature.includes("static"),
`signature should contain 'static': ${res.signature}`
);
assert.ok(res.signature.includes(":"), "signature should contain colons");
});