# chromadb.errors.DimensionError: Inserted embedding dimension (1536) does not match collection dimension (768)

- **ID:** `llm/embedding-length-mismatch-on-insert`
- **Domain:** llm
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The embedding model used for insertion produces vectors of a different size than the collection's expected dimension, often due to switching embedding models or mismatched model versions.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| chromadb>=0.4.0 | active | — | — |
| sentence-transformers>=2.2.0 | active | — | — |
| text-embedding-3-small | active | — | — |
| text-embedding-ada-002 | active | — | — |

## Workarounds

1. **Create a new collection with the correct dimension and re-embed all documents. Example: `collection = client.create_collection(name="my_collection", embedding_function=embedding_function, metadata={"hnsw:space": "cosine"})` where `embedding_function` outputs 1536 dimensions.** (95% success)
   ```
   Create a new collection with the correct dimension and re-embed all documents. Example: `collection = client.create_collection(name="my_collection", embedding_function=embedding_function, metadata={"hnsw:space": "cosine"})` where `embedding_function` outputs 1536 dimensions.
   ```
2. **If using a different embedding model temporarily, keep a mapping of model to collection, or use a router that selects the correct collection based on the model.** (80% success)
   ```
   If using a different embedding model temporarily, keep a mapping of model to collection, or use a router that selects the correct collection based on the model.
   ```
3. **Use a unified embedding model that supports variable dimensions (e.g., text-embedding-3-small with `dimensions` parameter) to enforce consistency.** (70% success)
   ```
   Use a unified embedding model that supports variable dimensions (e.g., text-embedding-3-small with `dimensions` parameter) to enforce consistency.
   ```

## Dead Ends

- **** — The collection dimension is fixed at creation time; upserting doesn't change the schema. (100% fail)
- **** — Padding or truncating destroys semantic meaning and leads to poor retrieval results; the vector space becomes inconsistent. (95% fail)
- **** — Different models have different output dimensions; you must use the same model for all inserts in a collection. (90% fail)
