Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why your RAG returns garbage (and it's not the model)

Your RAG bot just gave a confident, detailed answer. And it's completely wrong . Here's the part that'll annoy you: the model did nothing wrong. It answered perfectly — using the text you handed it. The bug isn't in the AI. It's in the five steps before the AI. Prefer to watch? Full 6-minute walkthrough with the "lost in the middle" animation: The pipeline, in one line of code RAG is simple on…

Your RAG bot gave a confident, detailed response that turned out to be completely wrong. The model did not make any mistakes; the problem lies before the AI in five crucial steps. It's easy to blame the model when the answer is garbage, but there are actually five potential issues before the model even runs:

1. Chunking: When long documents are split into smaller pieces, a fixed-length cut can split sentences or questions from their answers, rendering the chunks irrelevant for retrieval. To fix this, cut chunks based on structure, such as paragraphs and headers, and allow for overlap to prevent stranded information.

2. Embedding: Each chunk is turned into a vector using a model that captures its meaning. However, a question rarely resembles its answer, so the same model used for embedding may not produce similar vectors for related information. Using an embedding model specifically designed for retrieval and testing it on your data can improve the results.

3. Retrieval: Vector search matches meaning rather than exact words, which is beneficial for searching error codes, product names, or SKUs. However, it may not find exact strings, leading to irrelevant chunks being retrieved. Hybrid search, combining keyword search and vector search, can enhance the retrieval process.

4. Ranking: After retrieval, the model needs to rank the relevant chunks before generating the answer. However, the top-ranked chunk may not always be the correct one. Implementing a re-ranker, a second model that reads the question and each chunk together to re-score them, can help prioritize the most relevant chunks.

5. The prompt: The final step involves crafting the prompt for the model. People often make two common mistakes: including too much context, which can lead to noise and irrelevant information, or failing to instruct the model on what to do when the answer is not present in the context. The prompt should be explicit: "Answer only from the context below. If it's not there, say you don't know." This single instruction ensures the model provides accurate responses and acknowledges when it doesn't have the required information.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Six tests that passed for the wrong reason

My backup script told me the restore was verified. It restored ten tables with zero rows in every one, checked the schema, and printed VERIFIED.

  • Backup script reported successful restoration of ten tables with no rows
  • Stability gate flawed, recent-quiet rule mislabeled
  • Health-check scenario maintained low volume that never existed

What a Linux container really is (it's not a VM)

Right now, on your machine, a process is being lied to . It thinks it's alone on the computer. It thinks it owns the whole filesystem. It thinks its process ID is 1 . None of that is true.

  • Linux container is not a virtual machine, but a process on the same kernel
  • Namespaces and control groups manage process view and resource utilization
  • Docker creates containers by unpacking image, applying namespaces, cgroups, and executing process

More from Monday 31 August →