<?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: HarinezumIgel</title>
    <description>The latest articles on DEV Community by HarinezumIgel (@harinezumigel).</description>
    <link>https://dev.to/harinezumigel</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3869250%2F534ab935-2794-401a-a495-842410054492.png</url>
      <title>DEV Community: HarinezumIgel</title>
      <link>https://dev.to/harinezumigel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harinezumigel"/>
    <language>en</language>
    <item>
      <title>One inference box (DGX Spark) and multiple use cases...</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:05:44 +0000</pubDate>
      <link>https://dev.to/harinezumigel/one-inference-box-dgx-spark-and-multiple-use-cases-5h9d</link>
      <guid>https://dev.to/harinezumigel/one-inference-box-dgx-spark-and-multiple-use-cases-5h9d</guid>
      <description>&lt;p&gt;While developing my &lt;a href="https://github.com/HarinezumIgel/RAG-LCC" rel="noopener noreferrer"&gt;RAG-LCC&lt;/a&gt; experimental RAG, I had multiple use cases:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAG-LCC uses LLMs for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prompt guard&lt;/li&gt;
&lt;li&gt;Inference (query answering)&lt;/li&gt;
&lt;li&gt;Reply judgement&lt;/li&gt;
&lt;li&gt;Query rewrite&lt;/li&gt;
&lt;li&gt;Query split&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although some of the tasks can be handled by the same LMM it is good practice to have other models then the inference one for prompt guard and judgement.&lt;/p&gt;

&lt;p&gt;I use 2 sets of configurations, which I want to switch as convenient as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coding assistance:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I tried different models, which would be a separate discussion. But when I use local coding assistance, I cannot run the RAG tests because my Spark DGX can't provide it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Two configuration files&lt;/li&gt;
&lt;li&gt;Starts and stops models. Pre-flight memory check before startup&lt;/li&gt;
&lt;li&gt;Uses the NVIDIA provided vLLM docker runtime&lt;/li&gt;
&lt;li&gt;Integrates LiteLLM as central entry point (AI reverse proxy)&lt;/li&gt;
&lt;li&gt;Supports model groups, e.g. rag and rag_old&lt;/li&gt;
&lt;li&gt;Define aliases. So you must not remember the model name, only what it does, e.g. "judge"&lt;/li&gt;
&lt;li&gt;Status shows running and stopped models&lt;/li&gt;
&lt;li&gt;Log interaction allows you to attach and detach from logs&lt;/li&gt;
&lt;li&gt;Container creation and recreation. You can protect a models container from beeing recreated&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Start group rag&lt;/strong&gt;&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq8wvcxtaq2pjindcrbsf.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq8wvcxtaq2pjindcrbsf.png" alt=" " width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Show status&lt;/strong&gt;&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0b307rvciygdgwwvdj4k.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0b307rvciygdgwwvdj4k.png" alt=" " width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop group rag&lt;/strong&gt;&lt;br&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdj0s7eck7dkw5vydrbsy.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdj0s7eck7dkw5vydrbsy.png" alt=" " width="595" height="1341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building a RAG system taught me that managing the LLMs I use is an important part of my development flow. What started as some lines of python code has become a GitHub repo on its own.&lt;/p&gt;

&lt;p&gt;If you want to have a look: &lt;a href="https://github.com/HarinezumIgel/harinezumigel-llm-stack" rel="noopener noreferrer"&gt;harinezumigel-llm-stack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback and ideas are welcome.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>nvidia</category>
      <category>rag</category>
    </item>
    <item>
      <title>What I did in the last 4 months on my retirement project RAG-LCC</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Sun, 22 Nov 2026 10:15:36 +0000</pubDate>
      <link>https://dev.to/harinezumigel/what-i-did-in-the-last-4-months-on-my-retirement-project-rag-lcc-3dp1</link>
      <guid>https://dev.to/harinezumigel/what-i-did-in-the-last-4-months-on-my-retirement-project-rag-lcc-3dp1</guid>
      <description>&lt;p&gt;This is a follow-up to my earlier post about the first 15 months of building RAG-LCC in retirement:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.reddit.com/r/Rag/comments/1valvk6/15_months_building_a_rag_system_in_retirement/" rel="noopener noreferrer"&gt;https://www.reddit.com/r/Rag/comments/1valvk6/15_months_building_a_rag_system_in_retirement/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project kept evolving over the last 4 months, so I thought it might be interesting to share what worked, what failed, and what I learnt along the way. Since the last writeup I had success and failure moments. Of course, I learnt more from the failures about RAG.&lt;/p&gt;

&lt;h2&gt;
  
  
  Orchestrators
&lt;/h2&gt;

&lt;p&gt;Because RAG-LCC provides a lab setup for RAG experimentation, I found it useful to introduce an Orchestrator component. The orchestrator defines RAG flows. Users can create new flows and then activate them during a RAGChat session.&lt;/p&gt;

&lt;h2&gt;
  
  
  Confidence scoring
&lt;/h2&gt;

&lt;p&gt;With orchestrators, confidence became an issue. So static and dynamic confidence evaluation was added. The latter uses a LLM judge call. There is currently no validation against "golden answers" implemented. The LLM judge rates internal consistency and explanation clarity but not factual correctness.&lt;/p&gt;

&lt;h2&gt;
  
  
  TableChunker
&lt;/h2&gt;

&lt;p&gt;With these new features, it was time to look at answer quality. There was a query asking for the details of PCIe card slots on my workstation's manual. The information is stored in a table. The goal was that the information is found and the grounder marks it.&lt;/p&gt;

&lt;p&gt;The first step was to introduce a specialized TableChunker class and wire it into the already existing content specific chunkers. These chunkers pass table blocks to the TableChunker.&lt;/p&gt;

&lt;p&gt;This showed partial success: The table was now consistently in the chunks. But it did not reliably show up in the query answers.&lt;br&gt;&lt;br&gt;
BTW, while looking for specific content in the chunk, the debug levels of RAG-LCC proved helpful. The levels can be changed mid-session so users get the information at the detail level they need currently. Here is an example output (original has more colors): &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/QUERY_OUTPUT_EXAMPLE.md" rel="noopener noreferrer"&gt;Debug output&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insight:&lt;/strong&gt; If retrieval signals are weak, think about adding the best matching table result. Do this only if there are chunks found. Adding the table result to an empty answer set could confuse the user. This rescue may help in a large but sparse candidate pool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer rendering
&lt;/h2&gt;

&lt;p&gt;RAGChatServices delivers answers to Open WebUI. In the browser, .md and even Mermaid diagrams are nicely rendered. However, RAGChat showed tables with unaligned content. It was not a nice sight. So using the Rich library, answers with Markdown can be displayed in the RAGChat CLI also. But the rendering broke grounding, so additional work was required to separate the raw and display ready answer.&lt;/p&gt;

&lt;p&gt;Raw answers gave the grounding signals and text to be grounded. The raw answer text is marked for grounding before Rich renders the resulting CLI text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insight:&lt;/strong&gt; Keep the original, unrendered LLM answer for grounding evaluation. Once the grounded text is available, apply the visual grounding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Document summarization
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fux0p1ltc8lm4t2lchdwk.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fux0p1ltc8lm4t2lchdwk.png" alt=" " width="800" height="639"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was a "you wake up in the night" and have an insight moment. RAGChat has a document pin option. So once you found the right document about hedgehogs, you pin it and ask to summarize it. Hmm... the query is "create a summary" and this will not retrieve the content you are looking for.&lt;/p&gt;

&lt;p&gt;So I introduced a &lt;code&gt;summarize:&lt;/code&gt; option, using the pinned document or allowing the user to enter a path to retrieve the specific document by its metadata. Very large documents required batches of &lt;em&gt;n&lt;/em&gt; chunks to be summarized and then summarize the batches in further passes until the final summary fits. This works, but it is admittedly slow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insight:&lt;/strong&gt; If you want a specific action to be performed on the retrieved context, the action should not be part of the query. This leads to the next topic:&lt;/p&gt;

&lt;h2&gt;
  
  
  Query and query action splitting
&lt;/h2&gt;

&lt;p&gt;With table, bullet point list and Mermaid rendering I wrote often queries like "Look for all animals contained in the documents and create a table containing animal, mammal yes, no, don't know".&lt;/p&gt;

&lt;p&gt;Thought by the document summarization experience, I wondered whether it would make sense to ask a LLM to determine the effective query, the required action on the query results and the query keywords. Yes, you assume it: Each decomposed retrieval query goes now to enabled local retrievers, including vector search. In addition, the keywords go in an extra BM25-only pass. The QuerySplitter class was born.&lt;/p&gt;

&lt;h2&gt;
  
  
  Translation
&lt;/h2&gt;

&lt;p&gt;Living in a multilingual country where you have 4 official languages and the unofficial English one, you have to bother about document languages. Luckily, during RAGLoad, the document language is added to metadata.&lt;/p&gt;

&lt;p&gt;The old flow translated the question into English. It was also rewritten using the conversation history. Vector and indexed retrieval used the rewritten English query. The resulting candidates were reranked against the rewritten query.&lt;/p&gt;

&lt;p&gt;The new flow rewrites the query with the conversation history in the user's language. The vector search runs the user language query against the ChromaDB collection. For reranking the rewritten original query is used. Indexed retrieval is for every active and present document-language bucket. When required, the query is translated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insight&lt;/strong&gt; Don't underestimate the capabilities of multilingual embedders. Querying in the users original language often produces the same or even better results than translating the user query to English first.&lt;/p&gt;

&lt;h2&gt;
  
  
  vLLM integration
&lt;/h2&gt;

&lt;p&gt;While inference calls were already supported using Ollama or vLLM backends, the embedder and reranker ran as local Hugging Face models previously.&lt;/p&gt;

&lt;h2&gt;
  
  
  What still works well
&lt;/h2&gt;

&lt;p&gt;The configuration first approach is an extensible pattern. A new class gets its own config file when required. Abstracting functionality into classes helps understanding and maintaining the code.&lt;/p&gt;

&lt;p&gt;Parallel to my work on RAG-LCC I worked on harinezumigel-llm-stack. I introduced groups such as &lt;code&gt;rag&lt;/code&gt; and &lt;code&gt;rag_old&lt;/code&gt;, which start up the required models after doing an available memory check.&lt;/p&gt;

&lt;p&gt;So this is at a high level what happened in the last 4 months. The journey is going on.&lt;/p&gt;

&lt;p&gt;If you want to have a look:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RAG-LCC: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC" rel="noopener noreferrer"&gt;https://github.com/HarinezumIgel/RAG-LCC&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;harinezumigel-llm-stack: &lt;a href="https://github.com/HarinezumIgel/harinezumigel-llm-stack" rel="noopener noreferrer"&gt;https://github.com/HarinezumIgel/harinezumigel-llm-stack&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As always, feedback, ideas and bug reports are welcome.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>architecture</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>How I Tune RAG Pipelines with RAG-LCC: A Hands-On Local Guide</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Tue, 06 Oct 2026 09:09:06 +0000</pubDate>
      <link>https://dev.to/harinezumigel/how-i-tune-rag-pipelines-with-rag-lcc-a-hands-on-local-guide-l8l</link>
      <guid>https://dev.to/harinezumigel/how-i-tune-rag-pipelines-with-rag-lcc-a-hands-on-local-guide-l8l</guid>
      <description>&lt;p&gt;Most RAG frameworks tell you whether an answer was generated. RAG-LCC tries to show you why that answer happened.&lt;/p&gt;

&lt;p&gt;Instead of treating retrieval as a black box, you can inspect retrieval decisions, grounding signals, safety checks, and confidence traces while tuning your pipeline. This article walks through a beginner-friendly way to explore and tune RAG behaviour using RAG-LCC. It is not just a chatbot. It is a small lab where you can see why an answer happened, then improve it step by step. Instead of guessing, you can observe retrieval, safety checks, grounding, and confidence signals in plain output.&lt;/p&gt;

&lt;p&gt;By default, RAG-LCC is designed to work well with local AI stacks. When combined with a locally hosted LLM, documents, retrieval, and inference can stay on your own machine without requiring cloud-based model calls.&lt;/p&gt;

&lt;p&gt;It is designed for learning, trying ideas, experimentation, and tuning. It is not intended as a production-ready platform.&lt;br&gt;
For legal and licensing details, see &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/LEGAL.md" rel="noopener noreferrer"&gt;LEGAL.md&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Who is this for?
&lt;/h2&gt;

&lt;p&gt;RAG-LCC may be useful if you want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;learn how retrieval actually works&lt;/li&gt;
&lt;li&gt;compare retrieval strategies&lt;/li&gt;
&lt;li&gt;experiment with grounding&lt;/li&gt;
&lt;li&gt;evaluate confidence signals&lt;/li&gt;
&lt;li&gt;understand why a RAG answer changed after tuning&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The big picture first
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl0d0wpkdmvnxd8xzgkey.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl0d0wpkdmvnxd8xzgkey.png" alt="RAG-LCC overview" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows the full system. Here is the simpler mental model:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    A[DocClassify: understand your corpus] --&amp;gt; F[Optional filter: classification criteria]
    F --&amp;gt; B[RAGLoad: prepare searchable stores]
    B --&amp;gt; C[RAGChat: ask questions in CLI]
    C --&amp;gt; D[RAGChatService: serve the same flow via API]
    D --&amp;gt; E[OpenWebUI or clients]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;How to read this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DocClassify helps you understand what is in your documents before indexing.&lt;/li&gt;
&lt;li&gt;Optional filter step: use DocClassify results as classification criteria to choose what RAGLoad should ingest.&lt;/li&gt;
&lt;li&gt;RAGLoad builds the searchable memory (vector, keyword, graph, regex).&lt;/li&gt;
&lt;li&gt;RAGChat is the interactive place where you test and tune behavior.&lt;/li&gt;
&lt;li&gt;RAGChatService lets you use the same tuned behavior in OpenWebUI or API clients.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why beginners might like RAG-LCC
&lt;/h2&gt;

&lt;p&gt;Many RAG tools feel like a black box. RAG-LCC is different because it shows its work.&lt;/p&gt;

&lt;p&gt;You can open &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/QUERY_OUTPUT_EXAMPLE.md" rel="noopener noreferrer"&gt;QUERY_OUTPUT_EXAMPLE.md&lt;/a&gt; and literally watch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;startup checks&lt;/li&gt;
&lt;li&gt;retrieval decisions&lt;/li&gt;
&lt;li&gt;Query rewrite and translation&lt;/li&gt;
&lt;li&gt;safety/compliance checks&lt;/li&gt;
&lt;li&gt;grounding hints&lt;/li&gt;
&lt;li&gt;confidence-style signals&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That makes learning faster and more fun, because each tweak has visible effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  A gentle way to start (no deep config knowledge needed)
&lt;/h2&gt;

&lt;p&gt;Before running the apps, use the guided installer once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python ./src/Scripts/Setup.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Setup.py&lt;/code&gt; supports both installation paths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker-based setup&lt;/li&gt;
&lt;li&gt;Native host setup in a local &lt;code&gt;.venv&lt;/code&gt; (Windows or Unix)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run the apps in this order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python ./src/Apps/DocClassify.py --doc-dir TestDocs
python ./src/Apps/RAGLoad.py --doc-dir TestDocs
python ./src/Apps/RAGChat.py --doc-dir TestDocs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Optional filter step between DocClassify and RAGLoad (replace the default RAGLoad line above):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python ./src/Apps/RAGLoad.py --doc-dir TestDocs --load-from-classify-csv logs/DocClassify_OK_YYYYMMDD_HHMMSS.csv --classify-csv-query &lt;span class="s2"&gt;"Animal LIKE '%hedgehog%' OR Animal LIKE '%cat%'"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets you load only documents that match your classification criteria.&lt;/p&gt;

&lt;p&gt;During a RAGChat session, relevant settings can be overwritten interactively (for example &lt;code&gt;strategy=...&lt;/code&gt;, &lt;code&gt;threshold=...&lt;/code&gt;, &lt;code&gt;web_search=...&lt;/code&gt;, &lt;code&gt;collection=...&lt;/code&gt;, or picker commands like &lt;code&gt;strategy!&lt;/code&gt;, &lt;code&gt;orchestrator_flow!&lt;/code&gt;, and &lt;code&gt;collection!&lt;/code&gt;).&lt;br&gt;
That makes experimentation user-friendly, because you can try changes live without editing config files between turns.&lt;/p&gt;

&lt;p&gt;Then ask one simple question in chat. Keep that same question while you try different options.&lt;/p&gt;
&lt;h2&gt;
  
  
  Options you can explore without getting lost
&lt;/h2&gt;

&lt;p&gt;You do not need to memorize config keys to start. Think in terms of behavior:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Focused vs broad retrieval
You can move from very focused (&lt;code&gt;NARROW&lt;/code&gt;) to very broad (&lt;code&gt;ULTRA_WIDE&lt;/code&gt;) search behavior.&lt;/li&gt;
&lt;li&gt;More strict vs more flexible safety behavior
RAG-LCC can be tuned to block/mask more aggressively or more permissively.&lt;/li&gt;
&lt;li&gt;Local-only vs web-assisted retrieval
Keep answers local, or allow internet-assisted retrieval when needed.&lt;/li&gt;
&lt;li&gt;Short context vs long context
Keep responses tight, or allow broader evidence gathering.&lt;/li&gt;
&lt;li&gt;CLI-first vs service-first workflow
Tune in RAGChat, then serve the same behavior through RAGChatService.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you are ready for details, the deep reference is here:&lt;br&gt;
&lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/CONFIGURATION_REFERENCE.md" rel="noopener noreferrer"&gt;CONFIGURATION_REFERENCE.md&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The configuration files are "Theme" oriented. This helps finding the right knobs.&lt;/p&gt;
&lt;h2&gt;
  
  
  For experts: orchestrator and query rewrite
&lt;/h2&gt;

&lt;p&gt;If you already know RAG patterns and want finer control, RAG-LCC has two advanced power areas.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Orchestrator flows
You can shape how each turn runs: which retrieval legs activate, when reranking applies, how fallback behavior works, and whether grounding is enforced.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query rewrite&lt;br&gt;
You can refine follow-up understanding: pronoun resolution, topic carry-over, language normalization, and alternate-query expansion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Content filtering at two stages (reality check)&lt;br&gt;
RAG-LCC supports filtering at prompt level and pipeline level, and each app uses this differently:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- RAGLoad: can reject/skip chunks with undesired content before they are inserted into retrieval stores.
- RAGChat: filters prompts before answering and applies pipeline checks to answer/result content.
- DocClassify: filters prompts used for classification; document text can also pass through pipeline checks.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Illustrative rejection example (expert behavior check):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User query: "How can I rob or steal llamas without getting caught?"
Expected behavior: Rejected at PROMPT_CHECK stage before retrieval.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In runtime traces, watch for safety-stage status lines (PROMPT_CHECK and PIPELINE_CHECK)&lt;br&gt;
to verify where the decision happened.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo8swy3hjyb9cw2jlv4c5.jpg" 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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo8swy3hjyb9cw2jlv4c5.jpg" alt="OpenWebUI animal docs illustration" width="800" height="1168"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Reading query output like a story
&lt;/h2&gt;

&lt;p&gt;Open &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/QUERY_OUTPUT_EXAMPLE.md" rel="noopener noreferrer"&gt;QUERY_OUTPUT_EXAMPLE.md&lt;/a&gt; and look for these moments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Environment and startup checks
This tells you if your runtime is healthy and consistent.&lt;/li&gt;
&lt;li&gt;Retrieval plan and strategy lines
This shows how wide or narrow the system searched.&lt;/li&gt;
&lt;li&gt;Grounding-related output
This helps you see whether answer text is tied to retrieved evidence.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You do not need to tune everything at once. Change one option family, run the same question again, and compare.&lt;/p&gt;
&lt;h2&gt;
  
  
  Confidence log: your progress diary
&lt;/h2&gt;

&lt;p&gt;A useful tuning feature in RAG-LCC is the confidence output.&lt;/p&gt;

&lt;p&gt;After answers, RAGChat shows a confidence block (for example HIGH, MEDIUM, or LOW) and a final confidence score (&lt;code&gt;C_final&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;It also writes a CSV log so you can compare runs over time.&lt;/p&gt;

&lt;p&gt;Example of the kind of confidence summary you may see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Answer confidence: MEDIUM
C_final=0.63  C_top=0.71  C_coverage=0.58  C_fallback_penalty=0.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You do not need to overanalyze every field. A simple reading is enough:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;C_final&lt;/code&gt;: overall confidence for this answer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;C_coverage&lt;/code&gt;: how well the answer seems covered by retrieved evidence.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;C_fallback_penalty&lt;/code&gt;: whether the system had to rely on fallback behavior.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Typical location:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;logs/RAGChat/RAGChat_CONFIDENCE_YYYYMMDD_HHMMSS.csv&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of this log as a diary of retrieval quality, not as a single "truth number."&lt;/p&gt;

&lt;p&gt;What to look for first:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is confidence level becoming more stable for your key questions?&lt;/li&gt;
&lt;li&gt;Are grounding signs improving at the same time?&lt;/li&gt;
&lt;li&gt;Did quality improve without making answers too long or noisy?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you like simple workflows, this is enough:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep one fixed benchmark question.&lt;/li&gt;
&lt;li&gt;Save output before tuning.&lt;/li&gt;
&lt;li&gt;Apply one change.&lt;/li&gt;
&lt;li&gt;Re-run question.&lt;/li&gt;
&lt;li&gt;Compare confidence trend and answer quality.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What grounded output looks like
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CLI example
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwe6bkdcxtnegetdn2g6s.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwe6bkdcxtnegetdn2g6s.png" alt="Hedgehog grounded CLI output" width="619" height="1750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This view helps you see where answer sentences connect back to source text.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenWebUI example
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foabx6lfkvrqemxa645ih.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foabx6lfkvrqemxa645ih.png" alt="OpenWebUI grounded output" width="800" height="1229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same idea carries into service mode through RAGChatService.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the four apps work together in practice
&lt;/h2&gt;

&lt;h3&gt;
  
  
  DocClassify
&lt;/h3&gt;

&lt;p&gt;Use this when your corpus is large or mixed. It gives you a structured understanding of what documents are about.&lt;/p&gt;

&lt;h3&gt;
  
  
  RAGLoad
&lt;/h3&gt;

&lt;p&gt;Use this to load only what should be searchable. It is your quality gate before chat.&lt;/p&gt;

&lt;h3&gt;
  
  
  RAGChat
&lt;/h3&gt;

&lt;p&gt;Use this as your tuning cockpit. Try strategies, inspect output, compare behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  RAGChatService
&lt;/h3&gt;

&lt;p&gt;Use this when you want the same tuned pipeline in API/OpenWebUI form.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical tuning example
&lt;/h2&gt;

&lt;p&gt;Here is a gentle, realistic example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;You ask:&lt;/p&gt;

&lt;p&gt;"what do hedgehogs eat and where do they live?"&lt;/p&gt;

&lt;h3&gt;
  
  
  Round 1: baseline
&lt;/h3&gt;

&lt;p&gt;Run with defaults and keep:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the answer text&lt;/li&gt;
&lt;li&gt;the grounding behavior&lt;/li&gt;
&lt;li&gt;the confidence output&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Round 2: make retrieval broader
&lt;/h3&gt;

&lt;p&gt;Switch from a more focused style to a broader style (for example from DEFAULT toward WIDE).&lt;/p&gt;

&lt;p&gt;Run the exact same question again.&lt;/p&gt;

&lt;h3&gt;
  
  
  What usually changes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;More candidate evidence is considered.&lt;/li&gt;
&lt;li&gt;Coverage for multi-part questions often improves.&lt;/li&gt;
&lt;li&gt;Confidence and grounding may improve together.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Round 3: if the answer becomes noisy
&lt;/h3&gt;

&lt;p&gt;Keep broader retrieval, but tighten response behavior slightly (for example, move back one step from very broad to balanced).&lt;/p&gt;

&lt;p&gt;This helps keep gains in recall without turning the answer into a wall of text.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it demonstrates
&lt;/h3&gt;

&lt;p&gt;It demonstrates the whole RAG-LCC idea with one question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Observe baseline.&lt;/li&gt;
&lt;li&gt;Make one controlled change.&lt;/li&gt;
&lt;li&gt;Compare evidence quality, confidence trend, and readability.&lt;/li&gt;
&lt;li&gt;Keep only the change that helps.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A newcomer-friendly tuning loop
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Pick one question that matters to you.&lt;/li&gt;
&lt;li&gt;Run it with default settings and keep the output.&lt;/li&gt;
&lt;li&gt;Change one behavior option (for example: broader retrieval).&lt;/li&gt;
&lt;li&gt;Run the same question again.&lt;/li&gt;
&lt;li&gt;Compare answer quality and grounding signals.&lt;/li&gt;
&lt;li&gt;Keep the change only if it clearly improved the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Core idea:&lt;br&gt;
RAG-LCC lets you learn RAG behavior by observing it, not by blindly tweaking hidden internals.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you want to go one step deeper
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Hands-on flow: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/HANDS_ON_TOUR.md" rel="noopener noreferrer"&gt;HANDS_ON_TOUR.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Full query-output walkthrough: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/QUERY_OUTPUT_EXAMPLE.md" rel="noopener noreferrer"&gt;QUERY_OUTPUT_EXAMPLE.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Full options reference: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/CONFIGURATION_REFERENCE.md" rel="noopener noreferrer"&gt;CONFIGURATION_REFERENCE.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Project overview: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC/blob/main/README.md" rel="noopener noreferrer"&gt;README.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rag</category>
      <category>llm</category>
      <category>ai</category>
      <category>python</category>
    </item>
    <item>
      <title>Adding web search to our RAG pipeline: what broke and why</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Tue, 02 Jun 2026 08:11:49 +0000</pubDate>
      <link>https://dev.to/harinezumigel/adding-web-search-to-our-rag-pipeline-what-broke-and-why-4ge5</link>
      <guid>https://dev.to/harinezumigel/adding-web-search-to-our-rag-pipeline-what-broke-and-why-4ge5</guid>
      <description>&lt;p&gt;We added web search to a local RAG pipeline. It looked straightforward.&lt;/p&gt;

&lt;p&gt;It wasn’t.&lt;/p&gt;

&lt;p&gt;What followed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;broken assumptions about scoring
&lt;/li&gt;
&lt;li&gt;a safety model that behaved differently than we expected
&lt;/li&gt;
&lt;li&gt;a “temporary” bypass that stuck around way too long
&lt;/li&gt;
&lt;li&gt;and a cross-encoder that happily ranked navigation menus instead of content
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s what actually broke, and how we ended up fixing it.&lt;/p&gt;




&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Treat web retrieval as another retrieval leg—not a special case
&lt;/li&gt;
&lt;li&gt;Safety needs layers, but the baseline can’t be configurable away
&lt;/li&gt;
&lt;li&gt;Fix score normalization before touching thresholds
&lt;/li&gt;
&lt;li&gt;Pre-filter aggressively before the expensive steps
&lt;/li&gt;
&lt;li&gt;Any workaround will outlive the issue it was meant to patch
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  1. Adding a fourth retrieval leg
&lt;/h2&gt;

&lt;p&gt;The starting point was a pretty standard hybrid RAG setup: vector search (ChromaDB), BM25, and a graph index, all merged via Reciprocal Rank Fusion.&lt;/p&gt;

&lt;p&gt;Adding web search felt like an obvious extension: just another retriever. Fetch results, wrap them, feed them into RRF, then let the same reranking and filtering pipeline handle everything.&lt;/p&gt;

&lt;p&gt;That part worked fine. Web results flowed through the system exactly like local ones.&lt;/p&gt;

&lt;p&gt;The important part, in retrospect, was this:&lt;br&gt;&lt;br&gt;
Nothing downstream needed to know whether a document came from the web or from the local corpus. That kept the architecture clean—but it also meant that any flaws in scoring or filtering would affect everything at once.&lt;/p&gt;


&lt;h2&gt;
  
  
  2. Safety isn’t just “a filter” (safeguards)
&lt;/h2&gt;

&lt;p&gt;One thing that became clear quickly: web retrieval isn’t just retrieval. It’s a side-effect. You’re turning a user query into a network call.&lt;/p&gt;

&lt;p&gt;Once you look at it that way, safety becomes part of system correctness.&lt;/p&gt;

&lt;p&gt;We ended up with a layered set of safeguards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hard blocks for categories that should never pass
&lt;/li&gt;
&lt;li&gt;pattern filters for injection and obvious attacks
&lt;/li&gt;
&lt;li&gt;a lightweight intent classifier for borderline cases
&lt;/li&gt;
&lt;li&gt;query sanitation before sending anything externally
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key decision was where the baseline lives. We kept it in code, not config. Config can only tighten things—never relax them.&lt;/p&gt;

&lt;p&gt;That wasn’t about compliance as much as predictability. If behavior can change silently via config, it becomes difficult to reason about what the system will actually do in production.&lt;/p&gt;


&lt;h2&gt;
  
  
  3. The two-booleans trap
&lt;/h2&gt;

&lt;p&gt;We made the classic mistake of representing one concept with two booleans.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_ALLOW_WEB_SEARCH
_WEB_SEARCH_DRY_RUN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We wanted three states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;off&lt;/li&gt;
&lt;li&gt;dry run&lt;/li&gt;
&lt;li&gt;live&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two booleans give you four. One of them didn’t mean anything, but it existed anyway.&lt;/p&gt;

&lt;p&gt;We eventually replaced this with a single explicit mode flag. In practice, once the rest of the pipeline stabilized and safeguards were in place, the dry-run mode turned out not to be necessary anymore and was removed.&lt;/p&gt;

&lt;p&gt;The broader lesson still holds: control flow should make invalid states impossible to express.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Filtering before reranking
&lt;/h2&gt;

&lt;p&gt;Once web results were in the system, the next issue showed up in performance.&lt;/p&gt;

&lt;p&gt;Cross-encoder reranking is expensive, and web results are noisy. Running a batch of mediocre snippets through it just to discard most of them later was wasteful.&lt;/p&gt;

&lt;p&gt;We added two lightweight filters before reranking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BM25 over the snippets themselves
&lt;/li&gt;
&lt;li&gt;cosine similarity using the embedding model
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing fancy—just cheap ways to discard obviously weak candidates early.&lt;/p&gt;

&lt;p&gt;That reduced load on the cross-encoder and improved output quality at the same time. Probably the lowest-effort, highest-impact change in the whole pipeline.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. The bypass that stayed too long
&lt;/h2&gt;

&lt;p&gt;Early on, we let web results skip the rerank threshold entirely.&lt;/p&gt;

&lt;p&gt;The reasoning seemed fine: search engines already rank results, and snippets often look worse to a cross-encoder than full documents.&lt;/p&gt;

&lt;p&gt;In practice, this was compensating for something else—our normalization was wrong.&lt;/p&gt;

&lt;p&gt;Once we fixed normalization, the bypass became a problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;low-quality snippets passed straight through
&lt;/li&gt;
&lt;li&gt;they crowded out better local results
&lt;/li&gt;
&lt;li&gt;the model started favoring short, clean web content over more relevant local data
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We removed the bypass and introduced a separate threshold for web results instead.&lt;/p&gt;

&lt;p&gt;The important bit wasn’t the solution—it was realizing that the bypass had outlived its purpose.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A workaround introduced for a broken system will still be there after the system is fixed, unless you remove it deliberately.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  6. Fixing normalization
&lt;/h2&gt;

&lt;p&gt;This was the biggest issue.&lt;/p&gt;

&lt;p&gt;Cross-encoders output raw logits, and we initially applied a sigmoid to map them into [0, 1]. It looked principled.&lt;/p&gt;

&lt;p&gt;It didn’t work.&lt;/p&gt;

&lt;p&gt;Technical content—especially non-Q&amp;amp;A-style text—ended up with low scores everywhere. After thresholding, nothing survived. The system quietly fell back to the model’s internal knowledge.&lt;/p&gt;

&lt;p&gt;What worked instead was splitting the approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local documents: min–max normalization, relative within the result pool
&lt;/li&gt;
&lt;li&gt;web results: sigmoid, treated as absolute
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This isn’t mathematically perfect, but it matched the behavior we actually needed in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local results compete with each other
&lt;/li&gt;
&lt;li&gt;web results are judged on their own merit
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. What the cross-encoder actually sees
&lt;/h2&gt;

&lt;p&gt;At one point we enabled full-page fetching for web results, thinking it would improve relevance.&lt;/p&gt;

&lt;p&gt;It didn’t.&lt;/p&gt;

&lt;p&gt;The cross-encoder only sees ~512 tokens. For a web page, that’s usually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;headers
&lt;/li&gt;
&lt;li&gt;navigation
&lt;/li&gt;
&lt;li&gt;metadata
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The useful paragraph is often much further down.&lt;/p&gt;

&lt;p&gt;So the model was effectively ranking page chrome.&lt;/p&gt;

&lt;p&gt;The fix was simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;always keep the original search snippet
&lt;/li&gt;
&lt;li&gt;use the snippet for reranking
&lt;/li&gt;
&lt;li&gt;optionally send the full page to the LLM
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Different stages need different inputs. That became obvious only after trying to unify them.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Intent filtering, narrowly scoped
&lt;/h2&gt;

&lt;p&gt;The intent classifier ended up being a small guardrail.&lt;/p&gt;

&lt;p&gt;It doesn’t try to be perfect—it just catches things that slip past the other safeguards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;entity + action combinations
&lt;/li&gt;
&lt;li&gt;queries that are syntactically clean but clearly problematic
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two constraints kept it predictable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the baseline is fixed in code
&lt;/li&gt;
&lt;li&gt;config can only add to it or tighten it
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s not a replacement for other safety measures—just an additional layer.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Things we didn’t optimize (yet)
&lt;/h2&gt;

&lt;p&gt;There are a few obvious extensions we didn’t pursue immediately:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple search providers
&lt;/li&gt;
&lt;li&gt;translating queries before filtering
&lt;/li&gt;
&lt;li&gt;multi-query expansion for web search
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of those have tradeoffs, especially once network side-effects are involved. We chose to stabilize the core pipeline first.&lt;/p&gt;




&lt;h2&gt;
  
  
  The one-liner
&lt;/h2&gt;

&lt;p&gt;Web search isn’t a feature you bolt on. It changes the behavior of the entire pipeline.&lt;/p&gt;

&lt;p&gt;Once queries turn into network calls, scoring, filtering, and safeguards all become coupled in ways they weren’t before. Most of the complexity came from making that interaction predictable.&lt;/p&gt;

&lt;p&gt;Curious how others handle this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you normalize cross-encoder scores globally or per-query?&lt;/li&gt;
&lt;li&gt;Has anyone had success calibrating logits instead of mixing normalization strategies?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to dig into the implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/HarinezumIgel/RAG-LCC" rel="noopener noreferrer"&gt;https://github.com/HarinezumIgel/RAG-LCC&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rag</category>
      <category>ai</category>
      <category>architecture</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Speaking the Corpus's Language: How Multilingual RAG Stays Coherent Across Turns</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Thu, 23 Apr 2026 18:03:50 +0000</pubDate>
      <link>https://dev.to/harinezumigel/speaking-the-corpuss-language-how-multilingual-rag-stays-coherent-across-turns-4pf5</link>
      <guid>https://dev.to/harinezumigel/speaking-the-corpuss-language-how-multilingual-rag-stays-coherent-across-turns-4pf5</guid>
      <description>&lt;p&gt;This article assumes you already run a multi-turn RAG pipeline and have query rewriting enabled.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multilingual RAG breaks in more places than just query translation&lt;/li&gt;
&lt;li&gt;Query rewriting can re‑introduce the wrong language&lt;/li&gt;
&lt;li&gt;Treat rewritten queries as raw input and re‑detect + re‑translate&lt;/li&gt;
&lt;li&gt;Cheap detection + caching makes this practical&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most RAG tutorials quietly assume this works. In production, it fails in ways that look like “bad retrieval” but are actually language drift.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A German user asks a question in German.&lt;/li&gt;
&lt;li&gt;The corpus is in English.&lt;/li&gt;
&lt;li&gt;A query rewriter pulls English entity names out of earlier answers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Somewhere in the middle, translation has to happen — twice.&lt;/p&gt;

&lt;p&gt;This article walks through the two translation passes that keep a multilingual RAG pipeline working correctly across multiple turns, why each one is necessary, and what breaks without them. It also documents the places where things still go wrong — because they do.&lt;/p&gt;




&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;A typical local RAG stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Embeddings + vector store&lt;/strong&gt;:  An embedding model primarily optimized for English, but with usable multilingual similarity + Chroma DB&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt;: Hybrid (vector + BM25 + graph), fused with Reciprocal Rank Fusion&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation&lt;/strong&gt;: local LLM via Ollama&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query rewriting&lt;/strong&gt;: instruction-style rewriting of follow-up queries into self-contained questions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The corpus is English. Users are not.&lt;/p&gt;

&lt;p&gt;That single asymmetry — &lt;strong&gt;English internals, multilingual edges&lt;/strong&gt; — forces translation into more places than people expect.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pass 1 — Translating the user query (every turn)
&lt;/h2&gt;

&lt;p&gt;A user might ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Was für Tiere sind beschrieben?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Embeddings, BM25, and the corpus all operate in English. Sending the raw German query straight to retrieval yields poor results for a simple reason: &lt;strong&gt;there is no overlap signal&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Each turn therefore runs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;detect language → translate to English → retrieve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Language detection happens &lt;strong&gt;on every turn&lt;/strong&gt;, not once per session. Users frequently code-switch inside a single query, especially when technical terms or entity names appear in previous answers.&lt;/p&gt;

&lt;p&gt;The detected source language is stored in the session so the final LLM call can be instructed to answer in the user's language.&lt;/p&gt;

&lt;p&gt;Here is what that first turn looks like in the running system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;💬 Your query&amp;gt;  what animals are described?

🔵 UserQuery      Original user query: 'what animals are described?'
🔵 LangDetect     Detected language: English (en) — confidence: 100%
🔵 QueryRewrite   No conversation history — skipping rewrite
🔵 FinalQuery     Final query for retrieval: 'what animals are described?' (unchanged)

💡 ### Answer
   The following distinct animal species are described in the context:
   - Hedgehogs, Cats, Fish, Dogs, Lions, Apes (Gorillas and Orangutans),
     Elephants, Pferde (Horses)

   ### Sources
   Hedgehogs.pdf · Cats.md · Fish.txt · Dogs.png · Lions.pptx
   Apes.docx · Elephants.jpg · Pferde.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No rewrite happens on turn 1 — there is no history yet, so the query goes straight through.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pass 2 — Re-translation after rewriting
&lt;/h2&gt;

&lt;p&gt;Multi-turn RAG breaks on pronouns. A query rewrite step fixes that, but introduces a subtler problem.&lt;/p&gt;

&lt;p&gt;When entity names are copied from English history into a non-English sentence template, the rewritten query can be mixed-language:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Sind elephants, hedgehogs Säugetiere?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That output is internally consistent. It is also unusable by an English-only retriever.&lt;/p&gt;

&lt;p&gt;A concrete turn-by-turn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. User (DE):       Was für Tiere sind beschrieben?
2. Translated:      What animals are described?
3. Assistant (EN):  Cats, horses, hedgehogs, dogs, fish, apes, elephants, lions.
4. User (EN):       Are they mammals?
5. Rewritten:       Are Hedgehogs, Cats, Fish, Dogs, Lions, Gorillas,
                    Orangutans, Elephants, and Horses mammals?
6. Re-translated:   (already English — pass short-circuits)
7. Retrieval:       Are Hedgehogs, Cats, Fish, Dogs, Lions, Gorillas,
                    Orangutans, Elephants, and Horses mammals?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 5 is what makes retrieval work. The pronoun &lt;em&gt;"they"&lt;/em&gt; is gone; explicit entity names from the previous answer replace it. Here is the log for turn 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;💬 Your query&amp;gt;  are they mammals?

🔵 UserQuery      Original user query: 'are they mammals?'
🔵 LangDetect     Detected language: English (en) — confidence: 100%
🔵 QueryRewrite   Rewriting query using 1 history turns
🔵 QueryRewrite   'are they mammals?' → 'are Hedgehogs, Cats, Fish, Dogs,
↳                 Lions, Gorillas, Orangutans, Elephants, and Horses mammals?'
🔵 QueryRewrite   Final query: are Hedgehogs, Cats, Fish, Dogs, Lions,
↳                 Gorillas, Orangutans, Elephants, and Horses mammals?
🔵 LangDetect     Detected language: English (en) — confidence: 100%
🔵 FinalQuery     Final query for retrieval: 'are Hedgehogs, Cats, Fish,
↳                 Dogs, Lions, Gorillas, Orangutans, Elephants, and Horses mammals?'
                  (was: 'are they mammals?')

💡 ### Answer
   Hedgehogs, Cats, Dogs, Lions, Gorillas, Orangutans, and Elephants are
   mammals. The context is silent on whether Horses are explicitly stated
   as mammals in the provided text.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rewriter resolves the coreference correctly. Retrieval gets a self-contained query with real entity names.&lt;/p&gt;

&lt;p&gt;The pattern holds across deeper turns too. On turn 3, &lt;em&gt;"these mammals"&lt;/em&gt; gets resolved against the confirmed mammal list from the previous answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;💬 Your query&amp;gt;  give me details you find about these mammals

🔵 QueryRewrite   Rewriting query using 2 history turns
🔵 QueryRewrite   'give me details you find about these mammals' →
↳                 'give me details about Hedgehogs, Cats, Dogs, Lions,
                  Gorillas, Orangutans, and Elephants'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why the second translate pass is worth running
&lt;/h3&gt;

&lt;p&gt;It is reasonable to ask whether a second translation pass is really necessary. After all, the user query was already translated to English before the rewriter ran — so the rewriter should have only English material to work with.&lt;/p&gt;

&lt;p&gt;In practice, two things keep this from holding:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The rewriter's context is mixed.&lt;/strong&gt; It reads recent stored turns as &lt;code&gt;USER: … / ASSISTANT: …&lt;/code&gt; pairs, which means it sees the user's original-language wording &lt;em&gt;and&lt;/em&gt; the assistant's English answers. Whichever side it copies from, the result can land in either language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rewriting is not translation.&lt;/strong&gt; Rewriting models are tuned to resolve references and stay close to the user's phrasing, not to enforce a target language. When entity names from one language are dropped into a sentence template from another, the output is faithful to its inputs but no longer monolingual.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A short detect-and-translate pass on the rewritten query is cheap when the output is already English (detection runs; translation skips) and rescues the mixed-language case when it is not.&lt;/p&gt;

&lt;p&gt;The fix is simple but often skipped:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Treat rewritten queries as raw input and run language detection and translation again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Known failure mode: the rewriter over-triggers
&lt;/h3&gt;

&lt;p&gt;The rewriter assumes that any query arriving alongside chat history &lt;em&gt;must&lt;/em&gt; contain a reference worth resolving. Small LLMs do not reliably detect the absence of coreference, so a self-contained query — one that never actually pointed at anything — can still get entity-substituted from history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concrete example.&lt;/strong&gt; A new chat session starts. The user's first message is &lt;em&gt;"Was für Tiere sind beschrieben?"&lt;/em&gt; ("What animals are described?"). One history turn exists from a previous session whose answer listed hedgehogs, cats, fish, and so on. (This is a realistic condition in any setup where history is stored externally — shared session stores, reconnecting clients, or persistent memory features — rather than being cleared when a browser tab closes.) The rewriter reads that turn, finds entity candidates, and produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What animals are Hedgehogs, Cats, Fish, Dogs, Lions, Apes, and Elephants?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query is now semantically broken: instead of asking the corpus what animals it mentions, it asks whether a specific hardcoded list of animals are animals. The LLM answers as a taxonomy question and ignores the documents entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigations and their tradeoffs&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Prevents over-triggering?&lt;/th&gt;
&lt;th&gt;Downsides&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;use_chat_context: false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅ fully — no history, no rewrite&lt;/td&gt;
&lt;td&gt;Loses all coreference resolution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;max_history_turns: 1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;⚠️ partially — only if the bad turn falls outside the 1-turn window&lt;/td&gt;
&lt;td&gt;If the prior answer is the immediately preceding turn, the material is still there&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jaccard overlap gate&lt;/td&gt;
&lt;td&gt;⚠️ partially — very similar queries (overlap ≥ threshold) are skipped&lt;/td&gt;
&lt;td&gt;False-skips valid coreference on translated queries: German &lt;em&gt;"welches sind Säugetiere?"&lt;/em&gt; → &lt;em&gt;"What are mammals?"&lt;/em&gt; after the translation model drops the determiner → overlap ≈ 0 → the gate fires and skips a query that genuinely needs rewriting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explicit follow-up phrasing&lt;/td&gt;
&lt;td&gt;✅ user-side — &lt;em&gt;"which of those are mammals?"&lt;/em&gt; always has a clear referent&lt;/td&gt;
&lt;td&gt;Requires user discipline&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Jaccard gate was the original gating mechanism in this codebase and was removed precisely because of the translated-query false-skip problem. It solves the over-triggering case but breaks the core use case the rewriter exists for. There is no free lunch here; the right setting depends on whether your users mix sessions or always start fresh.&lt;/p&gt;




&lt;h2&gt;
  
  
  The full pipeline
&lt;/h2&gt;

&lt;p&gt;If you don’t read flowcharts fluently, you can skip this and continue—the conclusions don’t depend on it.&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%2Fkp1y5lromfyps77wn85u.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%2Fkp1y5lromfyps77wn85u.png" alt="Multilingual RAG pipeline" width="800" height="2697"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three blue nodes are translation steps. The rewrite node (green) sits between them — it is what makes pass 2 necessary.&lt;/p&gt;




&lt;h2&gt;
  
  
  Putting it together
&lt;/h2&gt;

&lt;p&gt;In the worst case, a single multi-turn query involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one user-query translation (Pass 1)&lt;/li&gt;
&lt;li&gt;an LLM rewrite using stored history&lt;/li&gt;
&lt;li&gt;an optional re-translation of the rewritten query (Pass 2)&lt;/li&gt;
&lt;li&gt;the final LLM answer, returned in the user's original language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Careful detection and caching keep the total overhead manageable. When the query and the rewritten query are both already English, both translation calls short-circuit immediately.&lt;/p&gt;




&lt;h2&gt;
  
  
  The retrieval–generation asymmetry
&lt;/h2&gt;

&lt;p&gt;The two translation passes described here keep the &lt;em&gt;query&lt;/em&gt; in a language the vector store and reranker can match against. They say nothing about the &lt;em&gt;documents&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A corpus document in a language different from English (say, a PDF written entirely in German) will still be retrieved correctly — the embedding model handles multilingual similarity — but the generation LLM may silently skip or ignore that chunk when composing its answer in English. The retrieval log will show the chunk selected; the answer will omit the information.&lt;/p&gt;

&lt;p&gt;This is visible in practice: with all other test documents in English and one German document (&lt;code&gt;Pferde.pdf&lt;/code&gt;), the query &lt;em&gt;"what animals are described?"&lt;/em&gt; retrieves three &lt;code&gt;Pferde.pdf&lt;/code&gt; chunks above threshold, yet the answer lists every other animal and omits horses entirely.&lt;/p&gt;

&lt;p&gt;The root cause is the asymmetry between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt; — handled by embedding and reranking models that were trained multilingually and score cross-lingual similarity well&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation&lt;/strong&gt; — handled by the chat LLM, which is given chunks in whatever language they were indexed in and is expected to synthesize them into a coherent answer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The two fixes are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Translate documents to English at ingestion time&lt;/td&gt;
&lt;td&gt;Retrieval and generation both work&lt;/td&gt;
&lt;td&gt;Permanent content transformation; original language lost in storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add an explicit instruction to the system prompt to handle multilingual chunks&lt;/td&gt;
&lt;td&gt;LLM is reminded to use all chunks regardless of language&lt;/td&gt;
&lt;td&gt;Costs tokens; not guaranteed; LLM may still miss content&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The translation passes in this article do not solve this — they fix the &lt;em&gt;query&lt;/em&gt; path. The document path is a separate problem.&lt;/p&gt;

&lt;p&gt;Below an example of a conversation with query translation and rewrite:&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%2Fbkt96ns16unmdh668pfc.jpg" 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%2Fbkt96ns16unmdh668pfc.jpg" alt="Example of a conversation" width="800" height="601"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Detect first; translate only when needed&lt;/strong&gt; — language detection on every turn, not once per session&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not assume rewriting preserves language&lt;/strong&gt; — rewritten queries must be treated as raw input&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The rewriter's context is mixed-language by nature&lt;/strong&gt; — users write in one language, answers reference entities from another&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A second translate pass is cheap&lt;/strong&gt; — it is a no-op for English output and a correctness fix for mixed output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pronoun and coreference rewriting is essential for multi-turn chat — without it, follow-up questions like &lt;em&gt;"are they mammals?"&lt;/em&gt; lose their referent the moment they are translated. The two translation passes described above are what keep that rewrite step working once users stop typing in English.&lt;/p&gt;




&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;The complete implementation is available here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/HarinezumIgel/RAG-LCC" rel="noopener noreferrer"&gt;github.com/HarinezumIgel/RAG-LCC&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you find the approach useful and think it could help other people building multilingual RAG systems, leaving a star on the repository can make it easier for them to discover it.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>python</category>
      <category>opensource</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Experimenting with RAG on Constrained Hardware</title>
      <dc:creator>HarinezumIgel</dc:creator>
      <pubDate>Sun, 12 Apr 2026 15:34:28 +0000</pubDate>
      <link>https://dev.to/harinezumigel/experimenting-with-rag-lcc-on-constrained-hardware-3dlg</link>
      <guid>https://dev.to/harinezumigel/experimenting-with-rag-lcc-on-constrained-hardware-3dlg</guid>
      <description>&lt;h2&gt;
  
  
  When Context Windows Meet Reality
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Experimenting with RAG on Constrained Hardware
&lt;/h2&gt;




&lt;p&gt;Large context windows are often treated as the solution to RAG problems. On constrained hardware (a second‑hand Tesla T4 in my case), that assumption breaks down quickly. This post explores using document classification as semantic compression to make RAG work without large contexts.&lt;/p&gt;

&lt;p&gt;In other words: Large context windows are a convenience feature, not an architectural solution.&lt;/p&gt;

&lt;p&gt;What initially felt like a disadvantage turned out to be a forcing function. Instead of chasing ever larger context windows, I started questioning whether the model actually needs to see entire documents at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context limits are often a hardware problem, not a model problem&lt;/li&gt;
&lt;li&gt;Simply “increasing context” is rarely viable on modest GPUs&lt;/li&gt;
&lt;li&gt;Constraints can lead to better architectural decisions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Rethinking context: classification instead of brute force
&lt;/h2&gt;

&lt;p&gt;The obvious approach to large documents is to feed more text into the model. On a Tesla T4, that idea breaks down quickly. Rather than pushing context size, I flipped the problem around and asked a different question: &lt;em&gt;why does the model need to see all of this text in the first place?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This shift led me to treat document classification not as a side task, but as a core architectural element. Instead of sending full documents downstream, I focused on extracting their meaning in a compact form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context size should be minimized, not maximized&lt;/li&gt;
&lt;li&gt;Classification can act as a form of semantic compression&lt;/li&gt;
&lt;li&gt;Architecture often matters more than raw model capability&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Using KeyBERT to reduce documents to meaning
&lt;/h2&gt;

&lt;p&gt;To make classification practical, I used &lt;strong&gt;KeyBERT&lt;/strong&gt;. Rather than passing full documents to an LLM, KeyBERT reduces each document to a small list of meaning‑dense keywords. This allows downstream components to understand what a document is about without reading it in its entirety.&lt;/p&gt;

&lt;p&gt;In practice, this worked far better than expected. However, it introduced a smaller but important usability issue: stemming. Words such as &lt;em&gt;predator&lt;/em&gt; became &lt;em&gt;predat&lt;/em&gt;, which is technically useful but confusing when results are presented to users.&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%2Ffb468w7zpkbzzd7k5t6p.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%2Ffb468w7zpkbzzd7k5t6p.png" alt="KeyBERT document classification flow" width="800" height="891"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 1: KeyBERT document classification flow&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To address this, I added a reverse‑stemming step. For each stem, candidate original words are tracked and weighted. The reconstruction is approximate—and can never be perfect—but it produces output that is readable and meaningful in CSV and Excel exports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keyword extraction dramatically reduces effective context size&lt;/li&gt;
&lt;li&gt;Stemming helps matching but hurts human readability&lt;/li&gt;
&lt;li&gt;Reverse stemming is a pragmatic compromise, not a perfect solution&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When classification turned into routing
&lt;/h2&gt;

&lt;p&gt;For a long time, classification and RAG felt like parallel ideas that never fully aligned. The breakthrough came with a simple question: &lt;em&gt;why not use classification results to decide which documents even enter the RAG pipeline?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since classification results were already stored in CSV files, SQLite’s CSV reader made them easy to query.&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%2F6sy0xrge2o1mfbatqn4r.jpg" 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%2F6sy0xrge2o1mfbatqn4r.jpg" alt="Mammal classification" width="799" height="125"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 2: Classification “mammal yes/no” of the TestDocs corpus&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This effectively turned classification into a routing mechanism. Documents are first classified, results are stored, and structured queries determine which files are worth ingesting.&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%2Fffwt41uusmz63v3nm27p.jpg" 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%2Fffwt41uusmz63v3nm27p.jpg" alt="Rout documents" width="800" height="255"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 3: Route documents about mammals in English language to RAGLoad.py&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This approach became &lt;strong&gt;query‑driven document routing&lt;/strong&gt;. Instead of loading everything and filtering later, only relevant documents are sent downstream.&lt;br&gt;&lt;br&gt;
&lt;code&gt;RAGChat&lt;/code&gt; and &lt;code&gt;RAGChatService&lt;/code&gt; also allow on‑the‑fly switching of the collections a user is chatting with, which nicely complements the routing functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classification output is useful far beyond simple labeling&lt;/li&gt;
&lt;li&gt;Ingestion is an architectural decision, not a default step&lt;/li&gt;
&lt;li&gt;Early routing significantly reduces cost and complexity&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Building the ingestion pipeline
&lt;/h2&gt;

&lt;p&gt;Text extraction was the next challenge. Documents arrived in many formats, including scanned PDFs and images, so a reliable baseline was needed. &lt;strong&gt;Tesseract OCR&lt;/strong&gt; provided consistent text extraction across heterogeneous sources.&lt;/p&gt;

&lt;p&gt;Once extracted, the text is chunked and prepared for embedding. Early versions of the pipeline simply loaded everything into the vector database. That approach turned out to be costly and hard to reason about: irrelevant or low‑quality material consumed storage, embedding compute, and downstream context budget.&lt;/p&gt;

&lt;p&gt;Addressing that led to introducing lightweight, deterministic filtering &lt;em&gt;before&lt;/em&gt; ingestion. By rejecting unsuitable inputs early, the ingestion pipeline stays smaller, cheaper to operate, and easier to debug—especially on constrained hardware.&lt;/p&gt;

&lt;p&gt;The filters are intentionally simple and deterministic, and run before any embedding or LLM inference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OCR is foundational when working with diverse document formats&lt;/li&gt;
&lt;li&gt;Chunking alone is insufficient—selectivity matters&lt;/li&gt;
&lt;li&gt;Not every document deserves a vector embedding&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Filter chains: combining depth and breadth
&lt;/h2&gt;

&lt;p&gt;Instead of relying on a single filtering signal, each chunk is evaluated by multiple algorithms. These include BM25, cosine similarity, Jaccard similarity, KeyBERT, and regular expressions combined with Levenshtein distance.&lt;/p&gt;

&lt;p&gt;The crucial insight was that filtering requires two dimensions.&lt;br&gt;&lt;br&gt;
&lt;em&gt;Depth&lt;/em&gt; defines how strong a single signal must be to count, while &lt;em&gt;breadth&lt;/em&gt; defines how many independent algorithms must agree before a decision is taken.&lt;/p&gt;

&lt;p&gt;One lesson became clear very quickly: a minimum depth threshold is essential. Without it, noise causes breadth triggers to fire constantly. Once tuned correctly, however, the depth‑and‑breadth combination proved far more reliable than simple keyword blocking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single filters are unreliable when used in isolation&lt;/li&gt;
&lt;li&gt;Depth prevents noise from dominating decisions&lt;/li&gt;
&lt;li&gt;Breadth enforces consensus across algorithms&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Multilingual documents and semantic drift
&lt;/h2&gt;

&lt;p&gt;Handling non‑English documents added another layer of complexity. Banned words are maintained in English, while content may be German or written in other languages. &lt;strong&gt;Argos Translate&lt;/strong&gt; is used to translate banned terms and cache the results.&lt;/p&gt;

&lt;p&gt;KeyBERT naturally accounts for semantic similarity, while other algorithms rely on &lt;strong&gt;WordNet&lt;/strong&gt; to expand synonyms. In practice, this combination allowed translated concepts to be detected without overly aggressive filtering.&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%2Fq0b7wh8drcgupt3mpfjl.jpg" 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%2Fq0b7wh8drcgupt3mpfjl.jpg" alt="Banned words translation" width="799" height="325"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 4: “horse”, “saddle” and “western riding” are recognized in German also&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Translation must be contextual, not absolute&lt;/li&gt;
&lt;li&gt;Multiple weak signals outperform single strong assumptions&lt;/li&gt;
&lt;li&gt;Multilingual filtering benefits from redundancy&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Sanitizing instead of blocking
&lt;/h2&gt;

&lt;p&gt;Not all problematic content needs to be rejected. In some cases, sanitization is sufficient. For this purpose, a masking step applies &lt;strong&gt;regular‑expression‑based&lt;/strong&gt; sanitization early in the pipeline, directly to the extracted text.&lt;/p&gt;

&lt;p&gt;This ensures that all downstream consumers automatically work with cleaned input, without duplicating sanitization logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blocking is not always the correct response&lt;/li&gt;
&lt;li&gt;Early sanitization simplifies downstream processing&lt;/li&gt;
&lt;li&gt;Pipelines benefit from clear responsibility boundaries&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Avoiding unnecessary work
&lt;/h2&gt;

&lt;p&gt;Document ingestion is expensive, especially during experimentation. To avoid reprocessing unchanged documents, each file is hashed and the hash is stored as metadata. Unchanged documents are skipped entirely.&lt;/p&gt;

&lt;p&gt;The same concept applies to documents flagged for human review. These are placed on an exclusion list and can be ignored in subsequent runs, preventing repeated processing of known problem cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hashing is a simple but powerful optimization&lt;/li&gt;
&lt;li&gt;Skipping unnecessary work matters as much as doing work&lt;/li&gt;
&lt;li&gt;Human‑review flags should influence pipelines, not just reports&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Chat interfaces and usability
&lt;/h2&gt;

&lt;p&gt;Interaction started with a simple CLI‑style chat interface. Over time, features such as session‑based history, named chat contexts, and dynamic collection switching were added.&lt;/p&gt;

&lt;p&gt;When I decided to open‑source the project, I integrated &lt;strong&gt;Open WebUI&lt;/strong&gt; to provide a more accessible GUI. This also marked the point where thread safety became a requirement and singleton patterns had to be removed.&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%2F9wfq8g9h5d49r4gn3d3d.jpg" 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%2F9wfq8g9h5d49r4gn3d3d.jpg" alt="Open WebUI integration" width="800" height="1168"&gt;&lt;/a&gt;&lt;br&gt;
*Figure 5: Open WebUI integration through RAGChatService.py&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Usability evolves together with the project&lt;/li&gt;
&lt;li&gt;GUI integration forces architectural maturity&lt;/li&gt;
&lt;li&gt;Thread safety becomes unavoidable in real‑world usage&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Prompt validation and safety
&lt;/h2&gt;

&lt;p&gt;User prompts go through two validation stages. First, they are checked by the same filter chains used for documents. If they pass, a dedicated prompt‑checking LLM performs a second evaluation.&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%2Fjiv9g9p1a9fpsxttf5ho.jpg" 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%2Fjiv9g9p1a9fpsxttf5ho.jpg" alt="User prompt validation" width="800" height="610"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 6: The first prompt is caught by the filter chain, the second by the prompt‑guarding LLM&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This two‑stage approach proved significantly more reliable than relying on a single mechanism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prompts deserve the same level of scrutiny as documents&lt;/li&gt;
&lt;li&gt;Combining heuristics with LLM checks improves reliability&lt;/li&gt;
&lt;li&gt;Layered decisions improve safety&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Compliance and licensing
&lt;/h2&gt;

&lt;p&gt;Releasing software for others to use comes with responsibilities. Downloaders for Hugging Face and Argos include explicit license checks. Once accepted, licenses are recorded so users only need to go through the process once.&lt;/p&gt;

&lt;p&gt;For me, this was not just a legal requirement, but a matter of respect for upstream projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;License compliance should be automated&lt;/li&gt;
&lt;li&gt;One‑time acceptance improves the user experience&lt;/li&gt;
&lt;li&gt;Open source includes ethical obligations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Configuration as a design philosophy
&lt;/h2&gt;

&lt;p&gt;Nearly every aspect of the system is configurable, from debug verbosity to model selection and reranking behavior. Reranking, in particular, had an outsized impact on result quality.&lt;/p&gt;

&lt;p&gt;Over time, configuration files became cluttered. Grouping related settings under higher‑level blocks improved clarity and enabled rapid switching between predefined setups.&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%2Fkobp2owsfiuzgtvw5sgn.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%2Fkobp2owsfiuzgtvw5sgn.png" alt="Chunk selection strategies" width="800" height="804"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 7: Two of the predefined chunk selection strategies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuration enables experimentation without code changes&lt;/li&gt;
&lt;li&gt;Reranking often matters more than retrieval&lt;/li&gt;
&lt;li&gt;Structure matters as much in config files as in code&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Offline‑first by design
&lt;/h2&gt;

&lt;p&gt;Operating without an internet connection was a hard requirement. After the initial setup, the system should run entirely offline. To validate this, a network tracer reports any external connections at runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offline capability must be verified, not assumed&lt;/li&gt;
&lt;li&gt;Visibility into network behavior builds trust&lt;/li&gt;
&lt;li&gt;Constraints simplify threat models&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Documentation and reflection
&lt;/h2&gt;

&lt;p&gt;Significant effort went into documentation, including class diagrams, flow charts, and markdown guides. RAG‑LCC follows a configuration‑first approach, which can feel overwhelming at first but ultimately empowers users to experiment deeply.&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%2Fwwz1tx2yu64gqiq82uoa.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%2Fwwz1tx2yu64gqiq82uoa.png" alt="DocClassify.py overview" width="800" height="485"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 8: DocClassify.py overview&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Looking back, several decisions stood out. Reranking was worth every hour invested.&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%2Ft3kyd6cn386tayb2qvhe.jpg" 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%2Ft3kyd6cn386tayb2qvhe.jpg" alt="Query output example" width="800" height="1266"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 9: Output at standard debug level for a hedgehog query with reranking&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Two‑stage prompt validation improved robustness, and hash‑based ingestion avoidance dramatically reduced iteration time. On the other hand, implementing both blocking and non‑blocking Ollama calls turned out to be more interesting than useful under tight hardware constraints.&lt;/p&gt;

&lt;p&gt;Along the way, I also explored IBM’s &lt;strong&gt;Docling&lt;/strong&gt;, an excellent RAG framework and a valuable source of inspiration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Constraints reward architectural thinking&lt;/li&gt;
&lt;li&gt;Not every technically interesting idea is worth keeping&lt;/li&gt;
&lt;li&gt;Learning sometimes matters more than outcomes&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Closing thoughts
&lt;/h2&gt;

&lt;p&gt;Every hour spent on this project was worth it. Working under tight constraints shaped the architecture in ways that brute‑force approaches never would have.&lt;/p&gt;

&lt;p&gt;The biggest lesson is simple: on constrained hardware, increasing context size is often the wrong optimization. Classification, filtering, and routing can deliver better results at lower cost—and lead to systems that are easier to reason about.&lt;/p&gt;

&lt;p&gt;Interestingly, modern LLM systems also rely heavily on selection, prioritization, and compression before generation. Raw context size alone is rarely the deciding factor.&lt;/p&gt;

&lt;p&gt;The journey continues.&lt;/p&gt;




&lt;h2&gt;
  
  
  Project &amp;amp; Source Code
&lt;/h2&gt;

&lt;p&gt;RAG‑LCC is open source and available on GitHub.&lt;br&gt;&lt;br&gt;
If you’d like to explore the code, experiment with the configuration, or provide feedback, you can find it here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/harinezumigel/rag-lcc" rel="noopener noreferrer"&gt;https://github.com/harinezumigel/rag-lcc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>architecture</category>
      <category>python</category>
    </item>
  </channel>
</rss>
