Suppose a runbook chunk starts with restart instructions and ends with a rollback condition. If the embedding model only sees the beginning, retrieval loses the signal from that condition even though the index still stores the full text alongside the vector.
Ollama's /api/embed defaults to truncate: true. When input exceeds the model's context window, the server can shorten it and return a vector with a successful status. An ingestion job that counts vectors can pass while indexing only part of what it thinks it sent. Set truncate: false when the job needs every chunk to fit. Ollama embedding API.
Reproduce the difference with a local model
On Ubuntu-22.04, start a current Ollama server on the default loopback address. Pull the embedding model in another terminal. You'll also need Python 3, with no extra packages.
ollama pull all-minilm:22m Save the following as check_embeddings.py. The repeated text makes an oversized chunk for this model. The short batch gives you a successful case to check against the same endpoint. Ollama's all-minilm:22m model page.
import json from urllib.error import HTTPError from urllib.request import ProxyHandler, Request, build_opener API = "http://127.0.0.1:11434/api/embed" MODEL = "all-minilm:22m" LOCAL_HTTP = build_opener(ProxyHandler({})) def embed(chunks, *, truncate=False): request = Request( API, data=json.dumps({ "model": MODEL, "input": chunks, "truncate": truncate, }).encode("utf-8"), headers={"Content-Type": "application/json"}, method="POST", ) with LOCAL_HTTP.open(request, timeout=60) as response: vectors = json.load(response)["embeddings"] if len(vectors) != len(chunks): raise ValueError("Embedding count does not match chunk count") return vectors def main(): oversized = "word " * 2000 permissive = embed([oversized], truncate=True) print(f"Truncation enabled: {len(permissive)} vector") try: embed([oversized]) except HTTPError as error: if error.code != 400: raise with error: detail = error.read(1024).decode("utf-8", errors="replace") strict_error = f"HTTP {error.code}: {detail}" else: raise RuntimeError("Expected this model to reject the oversized input") chunks = ["Restart the worker after draining the queue.", "Roll back if the health check fails."] vectors = embed(chunks) print(f"Strict short batch: {len(vectors)} vectors") print(f"Strict oversized request was rejected ({strict_error})") if __name__ == "__main__": main() Run python3 check_embeddings.py. Expect one vector with truncation enabled, HTTP 400 for the same oversized input in strict mode, and two vectors for the short strict batch. The diagnostic prints the server body without relying on exact wording or JSON. The paired requests and short control isolate the expected failure in this setup. Review the body to confirm the cause, since HTTP 400 can also signal another invalid request. For production handling, treat an HTTP failure as a failed batch and inspect its cause before retrying. A status code alone can't tell you that a chunk was too long.
Put the write after the check
Give each chunk a stable ID before embedding. Split on document boundaries you can explain, such as paragraphs or headings, and apply a conservative size limit so one paragraph can't turn into a huge request. A character limit helps bound request size. Token counts also depend on the model and the text, so keep strict mode enabled for the final check.
Embed a bounded batch, validate the vector count and the dimensions your index expects, then commit the ID-to-vector rows together using your store's transaction or supported atomic write. On error, write none of that batch. Inspect the reported failure, split an oversized chunk at a smaller boundary, and embed the corrected batch. A timeout or a missing model calls for a different fix.
Use the same embedding model for indexing and querying. When a strict rejection occurs, you can repair the ingestion input while the existing index still points to the last vectors you successfully wrote. Ollama embeddings guide.