How to Fix 'embedding dimension mismatch during development' in AutoGen (TypeScript)
If you’re seeing embedding dimension mismatch during development in AutoGen TypeScript, it means the vector store and the embedding model are not speaking the same language. One side is producing vectors of one size, while the other side expects a different size.
This usually shows up when you switch embedding models, reuse an old index, or mix configs across local dev environments. The error often appears during retrieval, memory writes, or agent startup when AutoGen tries to persist or query embeddings.
The Most Common Cause
The #1 cause is changing the embedding model without rebuilding the index or collection.
If you created a vector store with text-embedding-3-small and later switched to text-embedding-3-large, your stored vectors may be 1536 dimensions while the new model returns 3072. AutoGen then throws something like:
- •
Error: embedding dimension mismatch - •
Expected vector of dimension 1536, got 3072 - •
VectorStoreError: InvalidArgument: embedding length does not match index dimension
Wrong pattern vs right pattern
| Broken code | Fixed code |
|---|---|
| ```ts | |
| import { OpenAIEmbeddingModel } from "@autogen/core"; | |
| import { MemoryVectorStore } from "langchain/vectorstores/memory"; |
const embedder = new OpenAIEmbeddingModel({ model: "text-embedding-3-large", });
const store = new MemoryVectorStore(); // existing store built with 1536 dims
await store.addDocuments(docs, embedder);
|ts
import { OpenAIEmbeddingModel } from "@autogen/core";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
const embedder = new OpenAIEmbeddingModel({ model: "text-embedding-3-small", // matches existing 1536-dim index });
const store = new MemoryVectorStore();
// OR rebuild the store if you want to use text-embedding-3-large await store.addDocuments(docs, embedder);
If you want to keep `text-embedding-3-large`, delete and rebuild the collection/index so its dimension matches 3072.
```ts
// Example: wipe and recreate your vector DB collection
await client.deleteCollection("dev-memory");
await client.createCollection("dev-memory", {
dimension: 3072,
});
Other Possible Causes
1) Reusing persisted embeddings from an older model
This happens a lot in local development when .db, .sqlite, Chroma, Pinecone, or Qdrant data survives between runs.
// Broken: old persisted vectors remain on disk
const memory = new MyPersistentMemory({
path: "./data/autogen-memory",
});
Fix it by clearing the persisted store or versioning it by model name.
const memory = new MyPersistentMemory({
path: "./data/autogen-memory-text-embedding-3-small",
});
2) Mixing embedding providers in one pipeline
You might embed documents with OpenAI but query with Azure OpenAI, Cohere, or a local model. Same API shape does not mean same vector size.
// Broken: ingest with one provider, query with another
const docEmbedder = new OpenAIEmbeddingModel({ model: "text-embedding-3-small" });
const queryEmbedder = new AzureOpenAIEmbeddingModel({ deployment: "embed-v2" });
Use one provider/model pair for both ingestion and retrieval.
const embedder = new OpenAIEmbeddingModel({ model: "text-embedding-3-small" });
// use embedder everywhere
3) Index dimension configured manually and incorrectly
Some backends require an explicit dimension. If that number is wrong, AutoGen will fail when writing vectors.
{
"vectorStore": {
"provider": "qdrant",
"collection": "support-bot",
"dimension": 1024
}
}
If your model returns 1536 dimensions, set it correctly:
{
"vectorStore": {
"provider": "qdrant",
"collection": "support-bot",
"dimension": 1536
}
}
4) Hidden dependency drift between dev machines
One developer may be running a newer AutoGen package or a different embedding wrapper version than another. The code looks identical, but defaults changed.
{
"dependencies": {
"@autogen/core": "^0.4.0"
}
}
Pin versions and lock them:
{
"dependencies": {
"@autogen/core": "0.4.0"
}
}
How to Debug It
- •
Print the embedding vector length Log the output length before inserting into the store.
const vector = await embedder.embedQuery("test"); console.log("embedding length:", vector.length);If this does not match your index dimension, you found the issue.
- •
Check what dimension your index expects Look at your vector DB collection config, schema migration, or startup logs.
- •Qdrant collection dimension
- •Pinecone index dimension
- •PostgreSQL pgvector column size assumptions
- •
Search for old persisted data Remove local dev storage and retry.
- •delete
.chroma/ - •clear SQLite files
- •recreate Qdrant/Pinecone collections in dev
- •delete
- •
Verify ingestion and retrieval use the same embedder Search your codebase for multiple embedding classes.
grep -R "EmbeddingModel\|embed" src/If ingestion and query paths use different models, unify them.
Prevention
- •Keep the embedding model name in one config file and reuse it everywhere.
- •Version your vector stores by embedding model so old data never mixes with new dimensions.
- •Add a startup check that compares
embedder.embedQuery("ping").lengthagainst the target index dimension before serving traffic.
If you are using AutoGen TypeScript with persistent memory or a real vector database, treat embedding dimensions as part of schema, not runtime behavior. Once that contract breaks, retrieval fails fast — which is good — but only if you catch it before shipping.
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