<?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: Abuzar Zulfiqar</title>
    <description>The latest articles on DEV Community by Abuzar Zulfiqar (@abuzar18).</description>
    <link>https://dev.to/abuzar18</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%2F4260498%2Fb30be9de-ba80-4d92-8be7-bd7db82c67dc.jpg</url>
      <title>DEV Community: Abuzar Zulfiqar</title>
      <link>https://dev.to/abuzar18</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abuzar18"/>
    <language>en</language>
    <item>
      <title>From 126 Seconds to 4: The Unglamorous Fix Behind a 30x Speedup</title>
      <dc:creator>Abuzar Zulfiqar</dc:creator>
      <pubDate>Thu, 26 Nov 2026 08:00:57 +0000</pubDate>
      <link>https://dev.to/abuzar18/from-126-seconds-to-4-the-unglamorous-fix-behind-a-30x-speedup-38b7</link>
      <guid>https://dev.to/abuzar18/from-126-seconds-to-4-the-unglamorous-fix-behind-a-30x-speedup-38b7</guid>
      <description>&lt;p&gt;A matching feature I worked on took about 126 seconds to answer a single request at the median. After the fix it took 4. Nothing about the fix was clever, and I think that is the useful part of the story.&lt;/p&gt;

&lt;p&gt;The feature matched people against a table of about 1.24 million account records. It had to keep working with 100 requests in flight at once. When I started, the median response was a little over two minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the time went
&lt;/h2&gt;

&lt;p&gt;The code walked through records one after another and checked each one. With a few thousand rows that is fine. With 1.24 million rows and many users at once, every request paid for a full pass over the data, and the requests queued up behind each other.&lt;/p&gt;

&lt;p&gt;There was no hidden bug. The design simply didn't match the size of the data any more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Let the database do the searching.&lt;/strong&gt; I normalized the data the matching logic needed into proper tables and added indexes for the fields it filtered on. The application stopped scanning rows itself and asked PostgreSQL a precise question instead. This was the biggest single win.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Take heavy work off the request path.&lt;/strong&gt; Work that didn't need to finish before the user got an answer moved to an event-driven path: API Gateway receives the request, a message goes onto SQS, and Lambda workers process it. Large payloads go to S3, and only a reference travels through the queue, so messages stay small.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Protect the database from the fix.&lt;/strong&gt; Once work runs in parallel, the database becomes the bottleneck you created. I put PgBouncer in front of PostgreSQL for connection pooling and set concurrency limits on the workers, so a spike in traffic can't open hundreds of connections at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Make retries safe.&lt;/strong&gt; Queues deliver messages more than once, and networks fail. Every step became idempotent, so processing the same message twice does no harm, and failed calls retry with exponential backoff instead of hammering the service that just failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;p&gt;Median response time went from about 126 seconds to 4 seconds, across 1.24 million records at 100 concurrent requests. That is roughly 30 times faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Measure first.&lt;/strong&gt; The p50 number told me this was a design problem, not a tuning problem. Tweaking timeouts would have hidden it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indexes beat cleverness.&lt;/strong&gt; Most "slow AI feature" problems I've seen are ordinary data access problems wearing an AI label.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async is not free.&lt;/strong&gt; Moving work to queues helps only if you also handle duplicates, retries and database load. Otherwise you trade a slow system for a flaky one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the boring parts boring.&lt;/strong&gt; PgBouncer, SQS and an index are not exciting. They are why the system still behaves at 100 concurrent requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are looking at a feature that got slow as your data grew, start with the query plan before you reach for a bigger instance.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm Abuzar Zulfiqar, an AI/ML engineer who builds production AI agents, RAG assistants and the backends behind them. More case studies at &lt;a href="https://abuzar18.github.io/projects/" rel="noopener noreferrer"&gt;abuzar18.github.io&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>aws</category>
      <category>performance</category>
      <category>python</category>
    </item>
    <item>
      <title>Building a RAG System That Says "I Don't Know": Self-Correcting RAG with Llama 3.1 and LangGraph</title>
      <dc:creator>Abuzar Zulfiqar</dc:creator>
      <pubDate>Thu, 26 Nov 2026 08:00:06 +0000</pubDate>
      <link>https://dev.to/abuzar18/building-a-rag-system-that-says-i-dont-know-self-correcting-rag-with-llama-31-and-langgraph-h85</link>
      <guid>https://dev.to/abuzar18/building-a-rag-system-that-says-i-dont-know-self-correcting-rag-with-llama-31-and-langgraph-h85</guid>
      <description>&lt;p&gt;Most RAG demos have the same flaw: ask them something the documents never mention, and they answer anyway, confidently and wrongly. In a demo that is a curiosity. In production it is how a support bot invents a refund policy.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://github.com/abuzar18/llama-agentic-rag" rel="noopener noreferrer"&gt;Llama Agentic RAG&lt;/a&gt; around the opposite rule: &lt;strong&gt;an answer must be supported by cited sources, or the system says "I don't know."&lt;/strong&gt; It runs fully locally on Llama 3.1 8B through Ollama, which fits in 8 GB of VRAM, so private documents never leave the machine.&lt;/p&gt;

&lt;p&gt;This post walks through the design and the choices that made it work on a small model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The workflow
&lt;/h2&gt;

&lt;p&gt;The pipeline is a LangGraph state machine with five stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Retrieve&lt;/strong&gt; the top-k chunks from a vector index. Every chunk has a stable id such as &lt;code&gt;handbook.md#3&lt;/code&gt;, so citations stay traceable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grade&lt;/strong&gt; each chunk for relevance with the LLM before anything is generated. Off-topic context never reaches the answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rewrite&lt;/strong&gt; the query once if no chunk is relevant. Vague questions often recover here; if they don't, the graph refuses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate&lt;/strong&gt; an answer only from the numbered context, citing &lt;code&gt;[n]&lt;/code&gt; after each claim.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check groundedness&lt;/strong&gt;: a judge prompt verifies the answer against the context. An unsupported answer is replaced by a refusal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key idea is that hallucinations become refusals, not wrong answers. A refusal is annoying; a confident wrong answer is expensive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it work on an 8B model
&lt;/h2&gt;

&lt;p&gt;Large models forgive sloppy prompts. Small models don't, so a few details mattered more than any framework choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One-word verdicts.&lt;/strong&gt; Llama 3.1 8B is unreliable with complex JSON schemas, so the grading and groundedness prompts ask for &lt;code&gt;yes&lt;/code&gt; or &lt;code&gt;no&lt;/code&gt;, and parsing is tolerant of extra words.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strip reasoning tags.&lt;/strong&gt; If you swap in a reasoning model, its &lt;code&gt;&amp;lt;think&amp;gt;&lt;/code&gt; blocks are removed before parsing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Citations are enforced, not requested.&lt;/strong&gt; An answer without valid &lt;code&gt;[n]&lt;/code&gt; citations is treated as ungrounded, even if it sounds right.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Config over code.&lt;/strong&gt; Every model, path and threshold is an environment variable, so trying another Ollama model is a one-line change.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Measure the refusals
&lt;/h2&gt;

&lt;p&gt;A RAG system that never says "I don't know" isn't production-ready, so the evaluation set deliberately includes unanswerable questions. The harness reports:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;What it tells you&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Retrieval hit rate&lt;/td&gt;
&lt;td&gt;Did we retrieve an expected source for answerable questions?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Citation precision&lt;/td&gt;
&lt;td&gt;Do cited chunks come from expected sources?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refusal accuracy&lt;/td&gt;
&lt;td&gt;Were unanswerable questions correctly refused?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;False-refusal rate&lt;/td&gt;
&lt;td&gt;Were answerable questions wrongly refused?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Judge correctness&lt;/td&gt;
&lt;td&gt;LLM-as-judge score against a reference answer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p50 / p95 latency&lt;/td&gt;
&lt;td&gt;What does it cost the user in time?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Refusal accuracy and false-refusal rate pull against each other, which is exactly why you need both. Tighten the groundedness check and refusals get safer while false refusals rise. The numbers make that trade-off visible instead of a matter of opinion.&lt;/p&gt;

&lt;p&gt;Treat prompt and model changes like code changes: they ship only if the evals hold.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests that don't need a GPU
&lt;/h2&gt;

&lt;p&gt;CI runs the full graph with scripted fake LLM replies and deterministic embeddings. That covers the happy path, query rewrite, refusal, ungrounded answers, missing citations and reasoning-tag stripping, all without a model or a GPU. It is the cheapest way to keep a graph's control flow honest as it grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use it from Claude with MCP
&lt;/h2&gt;

&lt;p&gt;The same graph is exposed as an MCP tool, &lt;code&gt;ask_documents&lt;/code&gt;, so Claude Desktop, Claude Code or any MCP client can query your documents and get cited answers back. The FastAPI service exposes &lt;code&gt;/ask&lt;/code&gt;, &lt;code&gt;/ingest&lt;/code&gt; and &lt;code&gt;/health&lt;/code&gt; for everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The roadmap is the usual path from reference to production: hybrid retrieval with BM25 and a cross-encoder reranker, a persistent vector database such as pgvector or Qdrant, tracing with Langfuse, streaming, and PDF and DOCX ingestion.&lt;/p&gt;

&lt;p&gt;The code is MIT-licensed: &lt;a href="https://github.com/abuzar18/llama-agentic-rag" rel="noopener noreferrer"&gt;github.com/abuzar18/llama-agentic-rag&lt;/a&gt;. If you are building RAG for a team that can't afford confident wrong answers, I'd be glad to compare notes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm Abuzar Zulfiqar, an AI/ML engineer who builds production AI agents, RAG assistants and LLM automation. More at &lt;a href="https://abuzar18.github.io/" rel="noopener noreferrer"&gt;abuzar18.github.io&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

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