How to Fix 'embedding dimension mismatch in production' in AutoGen (TypeScript)
When AutoGen throws embedding dimension mismatch in production, it means the vector you’re inserting or querying does not match the embedding size your vector store index was built for. In practice, this usually shows up after a model swap, a stale index, or a config drift between environments.
You’ll typically see it when an agent starts retrieving memory, writing to a vector DB, or calling a tool that wraps embeddings. The failure is often buried under a larger stack trace from AssistantAgent, Memory, or your vector store client.
The Most Common Cause
The #1 cause is simple: you created the index with one embedding model, then later changed the model without rebuilding the index.
A common example is moving from text-embedding-3-small to text-embedding-3-large, or from one local embedding provider to another. The stored vectors and the live query vectors now have different dimensions.
| Broken pattern | Fixed pattern |
|---|---|
| Reuse old index after changing embedding model | Rebuild index whenever embedding dimension changes |
// BROKEN: index was created with 1536-dim embeddings,
// but the app now uses a different model/dimension.
import { AssistantAgent } from "@autogen/agent";
import { OpenAIEmbeddingClient } from "@autogen/embeddings";
const embeddingClient = new OpenAIEmbeddingClient({
model: "text-embedding-3-large", // 3072 dims
});
const agent = new AssistantAgent({
name: "support-agent",
// memory points to an existing vector store built with 1536 dims
memory: {
embeddingClient,
collectionName: "customer_notes",
},
});
// FIXED: use the same embedding model as the existing index,
// or rebuild the collection when changing models.
import { AssistantAgent } from "@autogen/agent";
import { OpenAIEmbeddingClient } from "@autogen/embeddings";
const embeddingClient = new OpenAIEmbeddingClient({
model: "text-embedding-3-small", // matches existing 1536-dim index
});
const agent = new AssistantAgent({
name: "support-agent",
memory: {
embeddingClient,
collectionName: "customer_notes_v2", // fresh collection for new dimension
},
});
If you see errors like:
- •
Error: embedding dimension mismatch - •
VectorStoreError: expected dimension 1536, got 3072 - •
PineconeBadRequestError: Vector dimension 3072 does not match the dimension of the index 1536
this is usually your issue.
Other Possible Causes
1) Different models in ingestion and query paths
You indexed documents with one client and queried with another. This happens when ingestion runs in a worker, but retrieval runs in the API process with a different .env.
// ingestion.ts
const embedder = new OpenAIEmbeddingClient({ model: "text-embedding-3-small" });
// api.ts
const embedder = new OpenAIEmbeddingClient({ model: "text-embedding-3-large" });
Fix: centralize embedding config and share it across services.
2) Stale cached vectors after deploy
If you cache embeddings or persist them locally, old vectors remain even after you change models.
// Old cache still contains vectors from previous dimension
await memory.add({ text: "policy renewal rules" });
Fix:
await memory.clear(); // or migrate to a new namespace/collection
If your store supports namespaces, version them:
namespace: `embeddings-v2-text-embedding-3-large`
3) Wrong vector store schema
Some stores require explicit dimension configuration at creation time. If that value is wrong, inserts fail immediately.
await pinecone.createIndex({
name: "customer-notes",
dimension: 1536,
});
If your embedder now returns 3072 dimensions, recreate the index with the correct value.
4) Mixed providers in one pipeline
You may be using OpenAI for documents and Azure OpenAI or a local model for queries. Same API shape, different output sizes.
const docEmbedder = new OpenAIEmbeddingClient({ model: "text-embedding-3-small" });
const queryEmbedder = new AzureOpenAIEmbeddingClient({ deploymentName: "embed-large" });
Fix: ensure both sides use identical dimensions, not just similar model names.
How to Debug It
- •
Log the actual embedding length
- •Print the output length before writing to storage and before querying.
- •Example:
const vector = await embeddingClient.embed("test"); console.log("embedding length:", vector.length); - •
Check the stored index dimension
- •Inspect your vector DB collection/index metadata.
- •Compare it against
vector.length. - •If they differ, rebuild or migrate.
- •
Trace both code paths
- •Confirm ingestion and retrieval use the same env vars.
- •Look for different
EMBEDDING_MODEL,AZURE_OPENAI_DEPLOYMENT, or provider configs between services.
- •
Search for stale collections
- •Check whether production is pointing at an old namespace, bucket, or collection name.
- •A renamed model without a renamed collection is a classic failure mode.
Prevention
- •Version your vector collections by embedding model and dimension.
- •Put embedding config in one shared module; do not duplicate it across workers and APIs.
- •Add a startup check that compares:
- •configured embedding model
- •expected dimension
- •target vector store index dimension
A simple guard saves hours of production debugging:
if (expectedDimension !== actualIndexDimension) {
throw new Error(
`Refusing to start: expected ${expectedDimension}, got ${actualIndexDimension}`
);
}
If you’re using AutoGen TypeScript with memory-backed retrieval, treat embeddings like schema. Change the model, and you need a migration plan.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit