Updated ยท Sources & corrections
In this guide
Quick answer: If an Ollama-backed retrieval app reports a vector-dimension mismatch, compare the returned vector length with the index’s configured length and verify the embedding model used by both indexing and querying. Do not pad or cut vectors just to silence the error. If the encoder or its output configuration changed, prepare a separate index version and re-embed the source data before switching traffic.
This guide covers local embedding pipelines, not chat-output JSON or a missing model download. For those failures, start with our model and server checks or structured-output validation guide.
Check the embedding response before changing the index
The native embedding API accepts text or an array of texts and returns an array of vectors under embeddings. Inspect the actual returned dimensions rather than inferring them from a chat model’s parameter count.
For a small diagnostic request, send this body to your local server’s /api/embed endpoint. Replace the model placeholder with an installed embedding-capable model:
{
"model": "REPLACE_WITH_INSTALLED_EMBEDDING_MODEL",
"input": ["A short diagnostic sentence."],
"truncate": false
}
Setting truncate to false makes an over-context input fail instead of being silently shortened by the API’s default behavior. The request above is illustrative, not a captured model run. If it fails, investigate that error before rebuilding a database.
Treat dimensions and model identity as separate checks
Ollama’s embedding guide recommends using the same model for document indexing and queries. Matching vector length alone does not establish that two different encoders produce a compatible search space.
| Observation | Next step |
|---|---|
| Returned width differs from the index contract | Check the selected encoder and any requested output dimensions before inserting. |
| Widths match, but model identity changed | Do not mix the two encoders’ vectors; plan a model migration. |
| One batch has fewer vectors than source items | Stop that write and inspect the response and batching logic. |
| Contract matches, but results are irrelevant | Evaluate chunking, preprocessing, filters and retrieval relevance instead of assuming a dimension error. |
The API exposes a dimensions request field. Changing that output contract is an index-design choice, not a universal repair for old data. Confirm support for the chosen model and keep the configuration consistent across documents and queries.
Reject an unexpected batch before writing it
This small standard-library Python guard checks a response against an explicit contract. Save it as vector_guard.py and call it before your database write:
import math
def check_embedding_batch(reply, expected_model, expected_dimensions, expected_count):
if 'error' in reply:
raise RuntimeError(str(reply['error']))
if reply.get('model') != expected_model:
raise ValueError('Response model differs from the stored index contract')
vectors = reply.get('embeddings')
if not isinstance(vectors, list) or len(vectors) != expected_count:
raise ValueError('Unexpected embedding batch size')
if expected_dimensions < 1 or expected_count < 1:
raise ValueError('Expected dimensions and batch count must be positive')
for position, vector in enumerate(vectors):
if not isinstance(vector, list) or len(vector) != expected_dimensions:
raise ValueError(f'Vector {position} has the wrong dimension')
if any(type(value) not in (int, float) or not math.isfinite(value)
for value in vector):
raise ValueError(f'Vector {position} contains a non-finite or non-numeric value')
return vectors
Obtain the expected values from the index configuration you intend to serve, not from the response you are about to accept. Record the resolved model identity consistently; a tag or alias can be represented differently in a request and response. The exact-name check is deliberately strict, so resolve that naming convention before treating a mismatch as an actual encoder change.
This is a shape-and-metadata gate. It does not prove that the server’s claimed model identity is immutable, that vectors have useful meaning, or that a document and its stored text still agree. Retain model revision information and input-processing metadata alongside the index version.
Use a migration boundary instead of overwriting the working index
Qdrant’s migration tutorial describes separate collections and named vectors, depending on configuration and version. Consult your database’s procedures; this checklist is not an executable migration:
- Preserve source chunks, metadata and the working index.
- Version encoder, dimensions and input preparation together.
- Re-embed into a separate candidate rather than replacing working data.
- Synchronize changes or pause writes under a documented plan.
- Check coverage and labeled-query results before cutover.
- Switch query encoding and index routing together; retain rollback.
Plan storage and write coordination for your application. Passing a shape check is not permission to delete the old index.
What the local tests established
On 23 October 2026, the guard passed eight tests using constructed Python responses. No Ollama model or vector database was contacted.
| Fixture | Observed behavior |
|---|---|
| Expected model, count and width | Accepted. |
| Wrong width or empty unexpected batch | Rejected. |
| Different model with the same width | Rejected by the contract check. |
| NaN, boolean or text in a vector | Each rejected as invalid numeric content. |
| API error object | Raised instead of passing data onward. |
After those checks, test real retrieval separately: choose questions with known relevant documents and inspect ranked results. A complete item count is a coverage check, not a relevance score. Neither a successful database insert nor a plausible answer from the chat model proves that the right sources were retrieved.
For a frontend connected to Ollama, our connection guide helps verify the service address before you investigate index behavior.
Sources and verification scope
Reviewed against the linked official Ollama and Qdrant references on 23 October 2026. The Python guard was executed only against synthetic fixtures; the embedding request and migration checklist were not run against a live model or database. No retrieval-quality or hardware benchmark is claimed. The featured image is an original generated illustration. See our sourcing and correction policy.
If a long document loses coverage before retrieval, use our embedding truncation diagnostic to trace extraction, chunk boundaries and failed oversized inputs before changing the vector index.