What it does
When the embedding model behind a vector index changes — a version bump, a provider switch, a chunking change — old vectors and new query vectors live in incompatible spaces. Similarity scores become meaningless, and nothing errors.
embedguard does not call an embedding provider. You bring vectors from the model you already use. It answers one question: is the model that produced this vector still the one this index was built with?
createFingerprint({ canaries, modelId? })- Builds a fingerprint from a handful of canary probes you embedded with the current model: their dimension, and the embeddings. Store it with the index metadata.
checkDimension(fingerprint, embedding)- Checks that a vector has the fingerprint's dimension. This catches an obviously different model immediately.
checkDrift(fingerprint, freshCanaries, { threshold? })- Catches a swap between models that share a dimension. Re-embed the fingerprint's exact probes and compare cosine similarity. A real swap shows up as a sharp drop.
Install
npm install embedguard
Requires Node.js 20 or newer. The package has zero runtime dependencies.
Usage
import { createFingerprint, checkDimension, checkDrift } from "embedguard";
// Once, when you build the index — embed a few probes yourself.
const fingerprint = createFingerprint({
modelId: "text-embedding-3-small",
canaries: [
{ probe: "return policy", embedding: await embed("return policy") },
{ probe: "shipping times", embedding: await embed("shipping times") },
],
});
// Later, before trusting new vectors, or on a schedule:
const freshCanaries = await Promise.all(
fingerprint.canaries.map(async (c) => ({
probe: c.probe,
embedding: await embed(c.probe),
}))
);
checkDimension(fingerprint, freshCanaries[0].embedding);
const drift = checkDrift(fingerprint, freshCanaries);
if (!drift.ok) {
throw new Error(
`embedding model drift detected: ${JSON.stringify(drift.probes)}`
);
}
The annotated demo simulates a same-dimension model swap that dimension checking alone would miss:
npx tsx examples/demo.ts