# ValueError: Query vector dimension (384) does not match index dimension (768)

- **ID:** `llm/embedding-dimension-mismatch-in-vector-search`
- **Domain:** llm
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Embedding model used for query encoding has a different output dimension than the model used to build the vector index, often due to switching between models (e.g., from text-embedding-ada-002 to a smaller model).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| openai==1.10.0 | active | — | — |
| pinecone-client==3.0.0 | active | — | — |
| chromadb==0.4.22 | active | — | — |
| text-embedding-ada-002 | active | — | — |
| all-MiniLM-L6-v2 | active | — | — |
| sentence-transformers==2.2.2 | active | — | — |

## Workarounds

1. **Re-embed all documents using the same embedding model as the query. For example, if using text-embedding-ada-002 (1536 dimensions), ensure both index and query use that model.** (95% success)
   ```
   Re-embed all documents using the same embedding model as the query. For example, if using text-embedding-ada-002 (1536 dimensions), ensure both index and query use that model.
   ```
2. **Use a dimension-agnostic vector database (e.g., ChromaDB with auto-detection) that can handle different dimensions by storing metadata and filtering at query time.** (80% success)
   ```
   Use a dimension-agnostic vector database (e.g., ChromaDB with auto-detection) that can handle different dimensions by storing metadata and filtering at query time.
   ```

## Dead Ends

- **** — Resizing the query vector by padding with zeros or truncating corrupts the embedding and leads to poor search results. (90% fail)
- **** — Re-indexing all documents with the new model is correct but often skipped due to time constraints; partial re-indexing causes inconsistency. (70% fail)
- **** — Assuming the vector database automatically handles dimension conversion leads to silent failures or errors. (95% fail)
