Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Catch Ollama Embedding Truncation Before It Reaches Your RAG Index

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…

A runbook chunk containing both restart instructions at the start and a rollback condition at the end can cause retrieval to lose crucial information if the embedding model only sees the initial portion. Ollama's default /api/embed setting, truncate: true, will shorten the input beyond the model's context window and still return a vector. However, this can result in indexing only part of the actual content. To capture the complete chunk, set truncate: false during ingestion.

To verify this behavior, create a Python script (check_embeddings.py) that sends oversized input to Ollama's all-minilm:22m model. The script checks if the number of returned vectors matches the number of chunks. It should raise a ValueError if the embedding count doesn't align with the chunk count. The script also tests strict mode, expecting an HTTP 400 error for oversized requests while the short batch returns the expected number of vectors.

The script demonstrates that the server can accept the request but may omit parts of the input when truncate is true.

In production, treat an HTTP failure as a failed batch and inspect the cause before retrying. Make sure to give each chunk a stable ID before embedding, split the text on document boundaries (like paragraphs or headings), and limit the size per chunk. Validate the vector count and dimensions after embedding, then commit the ID-to-vector pairs securely. Proper handling involves writing only the successfully embedded chunks and reattempting the correction of oversized inputs.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Report a problem with this story

Get the day's news by email. Daily, weekly or monthly. Sign up

More in Tech

More from Wednesday, 2 December 2026 →