<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nagi</title>
    <description>The latest articles on DEV Community by nagi (@akikisai).</description>
    <link>https://dev.to/akikisai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3879615%2Fb1f30439-1e61-46ea-81a6-3b5aaf09ca6f.jpg</url>
      <title>DEV Community: nagi</title>
      <link>https://dev.to/akikisai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akikisai"/>
    <language>en</language>
    <item>
      <title>There Are Too Many RAG Optimization Techniques, So I Organized Them — and the Big Picture Finally Made Sense</title>
      <dc:creator>nagi</dc:creator>
      <pubDate>Wed, 15 Apr 2026 06:32:03 +0000</pubDate>
      <link>https://dev.to/akikisai/there-are-too-many-rag-optimization-techniques-so-i-organized-them-and-the-big-picture-finally-eba</link>
      <guid>https://dev.to/akikisai/there-are-too-many-rag-optimization-techniques-so-i-organized-them-and-the-big-picture-finally-eba</guid>
      <description>&lt;h2&gt;
  
  
  Why I Learned About RAG
&lt;/h2&gt;

&lt;p&gt;I came across a technique called RAG (Retrieval-Augmented Generation) and was intrigued by how search systems could use this kind of approach. It made me want to build a search app using RAG myself. So I went through a fairly detailed course that covered everything from the basics to advanced techniques. It was a lot of material.&lt;/p&gt;

&lt;p&gt;Before starting, my understanding was roughly this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You turn documents into vectors, search for similar ones when a question comes in, and pass them to an LLM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That was it.&lt;/p&gt;

&lt;p&gt;Not wrong, but as I went through the course material, optimization techniques started piling up one after another. Multi Query, RAG-Fusion, HyDE, Decomposition, Step Back, RAPTOR, ColBERT, CRAG, Self-RAG... close to ten just by name.&lt;/p&gt;

&lt;p&gt;Honestly, partway through I couldn't keep track of what made each one different.&lt;/p&gt;

&lt;p&gt;So I decided to write it all up. As an engineer who eventually wants to implement these, I wanted to organize what each technique does in my own words.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basics of RAG: Four Stages
&lt;/h2&gt;

&lt;p&gt;The RAG pipeline itself is straightforward.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wconir90hd6fg1ymwyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wconir90hd6fg1ymwyi.png" alt="Data Preparation to" width="800" height="71"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Preparation&lt;/strong&gt;: Gather documents (PDFs, web pages, databases, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index Construction&lt;/strong&gt;: Split into chunks → embed → store in a vector database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt;: Vectorize the user's question and run a similarity search&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation&lt;/strong&gt;: Pass the search results + question to an LLM to generate an answer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So far, nothing surprising. The chunking step (splitting documents into smaller blocks) has several strategies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fixed-length&lt;/strong&gt;: Mechanically split at, say, every 300 characters. Simplest to implement, but you risk cutting mid-sentence and losing meaning&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentence-based&lt;/strong&gt;: Split at natural boundaries like periods or newlines. Preserves meaningful units better, but chunk sizes can vary a lot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sliding window&lt;/strong&gt;: Split with some overlap between adjacent chunks. Information near boundaries is less likely to be lost, so this is the most commonly used approach in practice&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The recommended chunk size is around 200–500 tokens, with 10–20% overlap. How you split can change retrieval accuracy significantly — it's a subtle but important step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Vectorize?
&lt;/h3&gt;

&lt;p&gt;After splitting text into chunks, machines can't understand their "meaning" as-is. So each chunk gets converted into a numerical vector (something like &lt;code&gt;[0.12, 0.34, 0.56, ...]&lt;/code&gt;). This is called embedding.&lt;/p&gt;

&lt;p&gt;What makes embedding useful is that even if the wording differs — like "cold medicine" vs. "flu medication" — vectors for semantically similar text end up close together. Instead of exact keyword matching, you can search by "closeness in meaning." The metric used to measure this closeness is cosine similarity.&lt;/p&gt;

&lt;p&gt;These vectors are stored and searched in a vector database (Pinecone, Milvus, FAISS, etc.). A regular relational database is great at exact lookups like "find the record with ID=123," but it can't do "find the most similar vector." Vector databases use approximate nearest-neighbor algorithms like HNSW and IVF to find similar items among millions of vectors in milliseconds.&lt;/p&gt;

&lt;p&gt;That's the foundation. The challenge starts here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Too Many Optimization Techniques
&lt;/h2&gt;

&lt;p&gt;From the middle of the course, techniques for improving retrieval accuracy started coming in fast. This was the most confusing part.&lt;/p&gt;

&lt;p&gt;But after organizing them, I realized everything falls into two categories:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Make the query smarter before searching"&lt;/strong&gt; or &lt;strong&gt;"Filter the results smarter after searching."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just framing it that way made things much clearer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Query-Side Techniques: Don't Just Search With the Raw Question
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;What It Does&lt;/th&gt;
&lt;th&gt;One-liner&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Multi Query&lt;/td&gt;
&lt;td&gt;Rephrase a single question multiple ways and search in parallel&lt;/td&gt;
&lt;td&gt;Prevents misses from wording variations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RAG-Fusion&lt;/td&gt;
&lt;td&gt;Multi Query + merge results using RRF scores&lt;/td&gt;
&lt;td&gt;Rank-based fusion, like a voting system&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decomposition&lt;/td&gt;
&lt;td&gt;Break a complex question into sub-questions and search individually&lt;/td&gt;
&lt;td&gt;Works well for "compare A and B" type queries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Step Back&lt;/td&gt;
&lt;td&gt;Abstract a specific question one level up before searching&lt;/td&gt;
&lt;td&gt;"X in Jan 2024" → "X trends over time"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HyDE&lt;/td&gt;
&lt;td&gt;Have an LLM write a hypothetical answer, then search using that answer&lt;/td&gt;
&lt;td&gt;Closes the vector distance gap between questions and documents&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The common idea is this: &lt;strong&gt;a user's question is usually not optimized for search.&lt;/strong&gt; So you use an LLM to transform it into a more search-friendly form before running the query.&lt;/p&gt;

&lt;p&gt;The most interesting one for me was &lt;strong&gt;HyDE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Questions and answers, even on the same topic, have very different writing styles. Questions are short; answers are long and explanatory — so they end up far apart in vector space. HyDE has the LLM write a "hypothetical answer," which produces a vector much closer to the real answer. The idea is: even if the hypothetical answer is wrong, its "shape" helps the search find the right documents. That was a real shift in perspective.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;RRF (Reciprocal Rank Fusion)&lt;/strong&gt; in &lt;strong&gt;RAG-Fusion&lt;/strong&gt; was also eye-opening. It merges multiple search result lists, but instead of a simple majority vote, it sums the reciprocal of each document's rank across lists. Documents that appear frequently &lt;em&gt;and&lt;/em&gt; rank highly win. Think of it like asking several friends for restaurant recommendations and combining their rankings into a final list.&lt;/p&gt;

&lt;p&gt;One caveat with HyDE: if the LLM doesn't know much about the domain, the hypothetical answer will be garbage, and so will the search. It also adds an extra LLM call (&lt;code&gt;+200–500ms&lt;/code&gt; latency), so you need to be selective about when to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result-Side Techniques: Filter What Comes Back
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;What It Does&lt;/th&gt;
&lt;th&gt;One-liner&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Re-ranking&lt;/td&gt;
&lt;td&gt;Broad retrieval (Top-50) → precise model re-scores (Top-5)&lt;/td&gt;
&lt;td&gt;Same idea as rough filtering → precise scoring in recommendation systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Routing&lt;/td&gt;
&lt;td&gt;Route questions to different data sources by type&lt;/td&gt;
&lt;td&gt;Switch between vector DB / SQL / web search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid Search&lt;/td&gt;
&lt;td&gt;Vector search + BM25 keyword search&lt;/td&gt;
&lt;td&gt;Catches proper nouns and numbers that vectors miss&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Re-ranking&lt;/strong&gt; seemed like the best bang for the buck. The approach is simple: first, pull ~50 results with vector search, then use a precise model like CrossEncoder or Cohere Rerank to narrow it down to 5. According to the course material, Cohere Rerank alone improved NDCG@10 by 36%, at a cost of $0.002 per query. High impact for low effort — it's often recommended as the first optimization to add.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hybrid search&lt;/strong&gt; compensates for vector search's weaknesses using keyword search (BM25). Vector search is great at finding "semantically similar" content, but it struggles with exact matches for things like "October 15, 2023" or "Model A-7B." By combining BM25 keyword matching and merging results with RRF, you get the best of both worlds. This is considered a best practice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Routing&lt;/strong&gt; directs questions to different data sources depending on their type. At first I thought, "Can't we just use the vector DB for everything?" But for a query like "Top 10 sales in 2023," SQL gives a far more accurate result. For questions about the latest news, a web search makes more sense. The implementation uses an LLM to classify the question and route it to the appropriate source. Around 5–20 categories is considered appropriate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Most Interesting Takeaway: Using LLMs as "Tools" Throughout the Pipeline
&lt;/h2&gt;

&lt;p&gt;This is where my understanding changed the most.&lt;/p&gt;

&lt;p&gt;Within a RAG pipeline, the LLM isn't just "the thing that generates the final answer." It plays many different roles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An LLM that rephrases queries (Multi Query)&lt;/li&gt;
&lt;li&gt;An LLM that decomposes questions (Decomposition)&lt;/li&gt;
&lt;li&gt;An LLM that generates hypothetical answers (HyDE)&lt;/li&gt;
&lt;li&gt;An LLM that evaluates retrieval relevance (CRAG)&lt;/li&gt;
&lt;li&gt;An LLM that self-checks whether the generation is accurate (Self-RAG)&lt;/li&gt;
&lt;li&gt;An LLM that creates document summaries (Multi-representation)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Multiple LLMs with different roles appear within a single pipeline. And depending on the role, you might use a "small model (fast, cheap)" for some tasks and a "large model (high accuracy)" for others.&lt;/p&gt;

&lt;p&gt;Going from "LLM = all-purpose answer machine" to "LLM = a component in the pipeline" was the biggest mental shift for me. From a system design perspective as an engineer, this framing feels much more natural. I think this way of thinking can apply to other AI-related designs as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Research-Level Techniques (Brief Overview)
&lt;/h2&gt;

&lt;p&gt;The latter part of the course covered more research-oriented techniques. I may not use them immediately, but I want to at least know the keywords, so here are my notes.&lt;/p&gt;

&lt;p&gt;RAPTOR: Recursively builds a summary tree from documents&lt;/p&gt;

&lt;p&gt;Chunk the documents → soft-cluster with GMM → summarize each cluster with an LLM → re-cluster the summaries → repeat to build a hierarchical tree.&lt;/p&gt;

&lt;p&gt;Its strength is handling both specific questions like "Who attended the 1956 Dartmouth Conference?" and abstract ones like "What were the key stages of AI development?" For retrieval, "flattening" (searching all levels at once) is recommended.&lt;/p&gt;

&lt;p&gt;The trade-off: construction cost is ~7x higher than standard approaches, and storage increases by ~80%. It shines when dealing with large volumes of long documents.&lt;/p&gt;

&lt;p&gt;ColBERT: Multi-vector search at the token level&lt;/p&gt;

&lt;p&gt;Instead of the traditional one-document-one-vector approach, ColBERT assigns an individual vector to each token. The MaxSim algorithm sums the maximum similarity between each query token and each document token to produce a score.&lt;/p&gt;

&lt;p&gt;Accuracy improves by 17–20%, but storage goes up 12x and memory 24x. ColBERT v2 introduced residual compression, reducing index size to about 1/6. At scale, a practical approach is to first do a rough filter with standard vector search, then use ColBERT for precise scoring.&lt;/p&gt;

&lt;p&gt;CRAG: Classifies retrieval results as Correct / Ambiguous / Incorrect and handles each case&lt;/p&gt;

&lt;p&gt;An LLM evaluates the retrieval results → if correct, use them as-is; if incorrect, fall back to web search; if ambiguous, reorganize and supplement the knowledge.&lt;/p&gt;

&lt;p&gt;It reduced hallucination rates from 15% to 4% in a medical domain. Best suited for high-risk domains (healthcare, legal, finance). Latency increases by ~140%, so it's a trade-off with real-time requirements.&lt;/p&gt;

&lt;p&gt;Self-RAG: Self-evaluates during generation using reflection tokens&lt;/p&gt;

&lt;p&gt;The model uses special tokens (Reflection Tokens) to self-judge: "Is retrieval needed?" "Is this document relevant?" "Is the generated content grounded in facts?" It achieves even higher accuracy than CRAG.&lt;/p&gt;

&lt;p&gt;However, training costs are $50K–$100K, and currently only 7B and 13B models are available. Inference latency is the slowest of all approaches. This feels like a heavily research-oriented technique for now.&lt;/p&gt;

&lt;p&gt;All of these are interesting, and the approaches are well-reasoned. But for small-scale development, they seem like clear overkill. The right move is probably to keep them in your back pocket and pull them out when retrieval accuracy becomes a bottleneck.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd Actually Use as an Engineer
&lt;/h2&gt;

&lt;p&gt;Based on what I learned, here's what I'd want to adopt as I build things out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Basic RAG&lt;/strong&gt; (chunking + embedding + vector DB + LLM generation)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid search&lt;/strong&gt; (vector + BM25) → prevents misses on proper nouns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-ranking&lt;/strong&gt; → best cost-to-accuracy improvement&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Routing&lt;/strong&gt; → when supporting multiple data sources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the other hand, I'm choosing not to use RAPTOR, ColBERT, or Self-RAG for now. I just can't see a clear case where I'd need to go that far yet. But there may come a time when they're needed, so understanding &lt;em&gt;why&lt;/em&gt; they'd be needed feels worth keeping in mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Became Clear After Organizing All of This
&lt;/h2&gt;

&lt;p&gt;RAG isn't as simple as "search + generate." There are optimization opportunities at every stage, and the sheer number of techniques can feel overwhelming.&lt;/p&gt;

&lt;p&gt;But after organizing everything, it really comes down to two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Make the query smarter before searching&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filter the results smarter after searching&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And the "making it smarter" part is where LLMs are used as tools.&lt;/p&gt;

&lt;p&gt;Rather than memorizing technique names, understanding this structure seems more useful in the long run. When a new technique comes along, you can quickly classify it: "This is a query-side improvement" or "This is result-side filtering."&lt;/p&gt;

&lt;p&gt;I'd like to dig deeper into the advanced techniques when I have time. CRAG's "evaluate → fallback" pattern in particular feels like an idea that could apply well beyond RAG, to other system designs too.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>llm</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
