How to Fix 'embedding dimension mismatch in production' in LangChain (TypeScript)
Embedding dimension mismatch means your vector store was built with one embedding size, then your app tried to query or insert vectors from a different embedding model. In LangChain TypeScript, this usually shows up after a model swap, a reindex, or when production and local environments are not using the same embedding provider.
The error often looks like one of these:
- •
Error: Vector dimensions 1536 do not match index dimensions 3072 - •
PineconeError: Vector dimension 1536 does not match the dimension of the index 3072 - •
QdrantClientError: expected vector size 1536, got 3072
The Most Common Cause
The #1 cause is simple: you changed embedding models, but kept using the old index.
This happens a lot when you move from text-embedding-3-small to text-embedding-3-large, or from one provider to another. The index was created with one dimension, and LangChain is now sending vectors with a different size.
Broken vs fixed
| Broken pattern | Fixed pattern |
|---|---|
| Create index with one embedding model, then query with another | Use the same embedding model for indexing and querying, or recreate the index |
| Assume all OpenAI embeddings are the same size | Check the actual dimension before provisioning your vector DB |
// BROKEN: index created with 1536-dim embeddings,
// later queried with 3072-dim embeddings
import { OpenAIEmbeddings } from "@langchain/openai";
import { PineconeStore } from "@langchain/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
const pinecone = new Pinecone({ apiKey: process.env.PINECONE_API_KEY! });
const index = pinecone.index("docs-index");
// Old code
const embedderV1 = new OpenAIEmbeddings({
model: "text-embedding-3-small", // 1536 dims
});
// New code after deploy
const embedderV2 = new OpenAIEmbeddings({
model: "text-embedding-3-large", // 3072 dims
});
await PineconeStore.fromExistingIndex(embedderV1, { pineconeIndex: index });
// Later in prod:
const store = await PineconeStore.fromExistingIndex(embedderV2, { pineconeIndex: index });
// Error: Vector dimension 3072 does not match the dimension of the index 1536
// FIXED: keep embedding model and index dimension aligned
import { OpenAIEmbeddings } from "@langchain/openai";
import { PineconeStore } from "@langchain/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
const pinecone = new Pinecone({ apiKey: process.env.PINECONE_API_KEY! });
const index = pinecone.index("docs-index");
const embeddings = new OpenAIEmbeddings({
model: "text-embedding-3-small", // keep this stable
});
await PineconeStore.fromExistingIndex(embeddings, { pineconeIndex: index });
If you want to change models, create a new index with the matching dimension and re-ingest everything.
Other Possible Causes
1. Mixed documents in the same collection
You indexed some docs with one embedder and added more docs later with another.
// Old ingestion job
await vectorStore.addDocuments(oldDocs); // text-embedding-ada-002
// New ingestion job after deploy
await vectorStore.addDocuments(newDocs); // text-embedding-3-large
Fix by reindexing the whole collection with one model.
2. Wrong vector DB schema or index settings
Your database expects a fixed vector size that doesn’t match your embedder.
// Qdrant collection created for 1536 dims
await client.createCollection("docs", {
vectors: {
size: 1536,
distance: "Cosine",
},
});
If your embedder returns 3072 dimensions, recreate the collection with size: 3072.
3. Accidental use of two different providers
You indexed with OpenAI but query with Cohere, Voyage, or a local model.
import { OpenAIEmbeddings } from "@langchain/openai";
import { CohereEmbeddings } from "@langchain/cohere";
const ingestEmbeddings = new OpenAIEmbeddings({ model: "text-embedding-3-small" });
const queryEmbeddings = new CohereEmbeddings({ model: "embed-v3.0" });
These are not interchangeable. Use one provider end-to-end unless you deliberately built a cross-model normalization layer.
4. Environment drift between dev and prod
Local uses one .env, production uses another.
# .env.local
EMBEDDING_MODEL=text-embedding-3-small
# production env
EMBEDDING_MODEL=text-embedding-3-large
This breaks when your deployment pipeline reuses an old index. Treat embedding config as part of schema versioning.
How to Debug It
- •
Print the embedding model name in both ingestion and query paths
- •Log
process.env.EMBEDDING_MODEL - •Log the class name too:
console.log(embeddings.constructor.name); - •Log
- •
Check the actual vector length before writing
- •Generate one sample embedding and inspect its size:
const vec = await embeddings.embedQuery("test"); console.log(vec.length);If this prints
3072, your DB must be configured for3072. - •
Inspect your vector DB index/collection dimensions
- •Pinecone index dimension
- •Qdrant collection size
- •Weaviate class/vectorizer settings
Compare that number againstvec.length.
- •
Search for stale ingestion jobs
- •Cron jobs
- •background workers
- •migration scripts
One old worker can keep inserting vectors with an outdated embedder long after your main app was fixed.
Prevention
- •
Version your embedding config like schema:
- •
embeddings:v1:text-embedding-3-small - •create a new namespace/index when it changes
- •
- •
Centralize embedder construction:
export function makeEmbeddings() {
return new OpenAIEmbeddings({
model: process.env.EMBEDDING_MODEL ?? "text-embedding-3-small",
});
}
- •Add a startup check that validates dimensions before serving traffic:
const sample = await embeddings.embedQuery("dimension check");
if (sample.length !== EXPECTED_DIMENSION) {
throw new Error(`Embedding dimension mismatch: got ${sample.length}, expected ${EXPECTED_DIMENSION}`);
}
If you hit this in production, don’t patch around it by truncating vectors or padding zeros. Fix the source of truth: one embedder, one expected dimension, one compatible vector store schema.
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