<?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: Zihao Ding</title>
    <description>The latest articles on DEV Community by Zihao Ding (@samir2015dzh).</description>
    <link>https://dev.to/samir2015dzh</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%2F4282409%2F781b15b2-dff9-459c-a08a-3b34860deeff.png</url>
      <title>DEV Community: Zihao Ding</title>
      <link>https://dev.to/samir2015dzh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samir2015dzh"/>
    <language>en</language>
    <item>
      <title>Why My Equipment-Manual RAG Quotes the Manual Verbatim</title>
      <dc:creator>Zihao Ding</dc:creator>
      <pubDate>Sat, 05 Dec 2026 08:52:23 +0000</pubDate>
      <link>https://dev.to/samir2015dzh/why-my-equipment-manual-rag-quotes-the-manual-verbatim-2015</link>
      <guid>https://dev.to/samir2015dzh/why-my-equipment-manual-rag-quotes-the-manual-verbatim-2015</guid>
      <description>&lt;h1&gt;
  
  
  Why My Equipment-Manual RAG Quotes the Manual Verbatim
&lt;/h1&gt;

&lt;p&gt;I am an electrical maintenance engineer, and I also build private RAG knowledge bases for manufacturing teams. When a machine faults on the floor, nobody wants a chatty summary of how CNC spindles generally work. They want the alarm trigger, the recovery sequence, or the clamping force spec straight out of that machine's manual.&lt;/p&gt;

&lt;p&gt;Most RAG tutorials hand retrieved chunks to an LLM and let it rewrite the answer into smooth prose. That works for general office docs, not for equipment manuals. If a model alters a torque value, drops a step from an alarm-recovery procedure, or papers over a missing section by guessing from nearby text, the cost is real: scrapped parts, damaged tooling, extra downtime, or an injury. Even when a paraphrase happens to be right, technicians will not trust it blindly. They still open the manual to check the line themselves, wiping out the time the search was supposed to save.&lt;/p&gt;

&lt;p&gt;I published &lt;a href="https://github.com/samir2015dzh/cited-rag-demo" rel="noopener noreferrer"&gt;cited-rag-demo&lt;/a&gt; as a public, self-contained version of the retrieval architecture I run in production. It requires Python 3.10+, runs on a laptop CPU, and needs no LLM API key or external services. All sample data in the repo is fictional: three invented manuals for a made-up "VertexMach HX-500" CNC machine, split into 50 chunks, with 6 sample questions and 13 pytest smoke tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a real query returns
&lt;/h2&gt;

&lt;p&gt;Here is an unedited example from &lt;code&gt;sample-output.txt&lt;/code&gt; in the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q: What does alarm 1105 mean and how do I recover from it?
A:
- Trigger: spindle bearing temperature sensor exceeds 60 °C for more than 10 seconds. Likely causes: low spindle chiller oil level; chiller condenser clogged with dust; continuous cutting at maximum speed with heavy load. Recovery: stop the spindle and let it cool with the chiller running. [1]
Sources:
  [1] alarm-codes.md § 2.2 Alarm 1105 — Spindle Overtemperature  (score 0.0454)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No language model wrote that bullet. The server matched the section, quoted its sentences verbatim, attached &lt;code&gt;[1]&lt;/code&gt;, and printed the document name and section heading. Ask about pull-stud clamping force and it quotes the nominal &lt;code&gt;12 kN&lt;/code&gt; and acceptable &lt;code&gt;10–14 kN&lt;/code&gt; range straight from &lt;code&gt;maintenance-manual.md § 4.3 Pull-Stud Clamping Force Check&lt;/code&gt;. Anyone reading the output can open the manual to that exact heading and verify it in seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design choices behind the pipeline
&lt;/h2&gt;

&lt;p&gt;Everything in the codebase follows from one goal: make verification fast and keep the server out of the business of inventing prose.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chunking strictly at section boundaries
&lt;/h3&gt;

&lt;p&gt;Fixed-token sliding windows break procedures across chunks and lose track of where text came from. Here, Markdown manuals are split at section headings. A chunk never crosses a section boundary, and every chunk stores its document name, chapter, and section heading. Long sections split on paragraph boundaries above 1,200 characters by default while keeping the same metadata. That is why citations resolve to a real section heading instead of a raw chunk ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three retrieval signals fused with RRF
&lt;/h3&gt;

&lt;p&gt;Shop-floor questions mix plain English ("why does through-spindle coolant pressure drop?") with exact codes ("alarm 1105", "M88", program numbers). Embeddings handle phrasing differences well, but they are unreliable on exact numeric codes. Keyword search catches literal tokens, but misses symptom descriptions that use different words than the manual.&lt;/p&gt;

&lt;p&gt;Each query runs three signals against the SQLite index and combines the rankings with Reciprocal Rank Fusion (RRF):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local embeddings via &lt;code&gt;bge-small-en-v1.5&lt;/code&gt; (&lt;code&gt;fastembed&lt;/code&gt; / ONNX Runtime on CPU; ~67 MB model downloaded once from Hugging Face, offline after that).&lt;/li&gt;
&lt;li&gt;BM25 keyword search via SQLite FTS5.&lt;/li&gt;
&lt;li&gt;Exact identifier matching for alarm codes, M-codes, and program numbers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Determinism, verbatim answers, and honest "not found"
&lt;/h3&gt;

&lt;p&gt;Embedding, ranking, and RRF fusion are deterministic functions of the index and the query. Ask the same question twice and you get the same passages in the same order, and a pytest test in &lt;code&gt;tests/test_smoke.py&lt;/code&gt; verifies that. The server never generates prose. Its HTTP endpoint builds answers by quoting verbatim sentences with numbered citations. If nothing in the index is similar enough, it says not found instead of returning the closest unrelated passage. Getting no answer is much safer than getting a confident paragraph from the wrong subsystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  MCP first, client-side reasoning, and human review
&lt;/h3&gt;

&lt;p&gt;Most teams do not want yet another standalone chat window. The primary interface here is an MCP stdio server exposing one tool, &lt;code&gt;search_text&lt;/code&gt;. It takes &lt;code&gt;query&lt;/code&gt; and &lt;code&gt;top_k&lt;/code&gt; (1–10, default 4) and returns ranked passages with citation, document, chapter, section, verbatim text, and score. A FastAPI service (&lt;code&gt;POST /ask&lt;/code&gt; and &lt;code&gt;GET /healthz&lt;/code&gt;) sits alongside it for scripts, integrations, and quick checks.&lt;/p&gt;

&lt;p&gt;Keeping reasoning inside the client model via MCP means the retrieval server holds zero LLM credentials, and swapping models later requires no server changes. Human review stays the quality gate. In production, answers written into maintenance records are approved by a person first, and verbatim quotes with section citations make that check take seconds instead of turning into a second investigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running it locally
&lt;/h2&gt;

&lt;p&gt;With Python 3.10+, clone the repo, install it, build the index, and run the six built-in sample questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/samir2015dzh/cited-rag-demo.git
&lt;span class="nb"&gt;cd&lt;/span&gt; cited-rag-demo
python -m venv .venv
&lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate        &lt;span class="c"&gt;# Windows: .venv\Scripts\activate&lt;/span&gt;
pip install -e &lt;span class="s2"&gt;".[dev]"&lt;/span&gt;
python -m citedrag.ingest
python -m citedrag.demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run downloads the ~67 MB embedding model; after that everything runs offline on CPU. &lt;code&gt;citedrag.ingest&lt;/code&gt; indexes the three fictional HX-500 manuals (&lt;code&gt;alarm-codes.md&lt;/code&gt;, &lt;code&gt;maintenance-manual.md&lt;/code&gt;, &lt;code&gt;operator-guide.md&lt;/code&gt;) into 50 chunks in &lt;code&gt;data/index.sqlite&lt;/code&gt;. Run &lt;code&gt;pytest -v&lt;/code&gt; to run the 13 smoke tests.&lt;/p&gt;

&lt;p&gt;For the HTTP API, start &lt;code&gt;uvicorn citedrag.api:app --port 8000&lt;/code&gt; and call &lt;code&gt;POST /ask&lt;/code&gt; or &lt;code&gt;GET /healthz&lt;/code&gt;. For MCP, point a client like Claude Desktop at &lt;code&gt;.venv/bin/python -m citedrag.mcp_server&lt;/code&gt; with &lt;code&gt;CITEDRAG_DB_PATH&lt;/code&gt; pointed at &lt;code&gt;index.sqlite&lt;/code&gt;, or run &lt;code&gt;python examples/mcp_client.py "alarm 4012 tool unclamp"&lt;/code&gt; to test the stdio flow directly. To index your own Markdown manuals, put files with &lt;code&gt;#&lt;/code&gt; / &lt;code&gt;##&lt;/code&gt; / &lt;code&gt;###&lt;/code&gt; headings in a folder and run &lt;code&gt;python -m citedrag.ingest --docs &amp;lt;folder&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo vs. the production original
&lt;/h2&gt;

&lt;p&gt;The production system this demo mirrors runs privately on-premises and is not public. Production uses PostgreSQL with &lt;code&gt;pgvector&lt;/code&gt; for vectors and PostgreSQL &lt;code&gt;tsvector&lt;/code&gt; full-text search for keywords, indexing real customer manuals and service records with local embeddings so no documents leave the site. This demo swaps storage to SQLite BLOBs + numpy and SQLite FTS5 so it installs in one step with no database server. The chunking rules, RRF fusion, verbatim citations, and MCP/HTTP split stay the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Known weaknesses
&lt;/h2&gt;

&lt;p&gt;Two gaps are still open. First, tables and diagrams are not indexed. Real equipment manuals put plenty of critical data inside torque charts, parameter tables, and wiring diagrams, so indexing only Markdown text sections misses important recall. Second, conflicting manual revisions are not surfaced side by side. If two manual versions disagree on a limit or step, the retriever ranks one above the other instead of showing both revisions together so the technician can spot the discrepancy.&lt;/p&gt;

&lt;p&gt;If you build retrieval over technical manuals or safety-sensitive docs, I would like to hear how you handle tables, conflicting revisions, and review gates.&lt;/p&gt;

&lt;p&gt;I take freelance projects building private RAG and MCP systems deployed on the client's own server, starting with a fixed-price pilot. Details are in the "Work with me" section of the &lt;a href="https://github.com/samir2015dzh/cited-rag-demo#work-with-me" rel="noopener noreferrer"&gt;cited-rag-demo README&lt;/a&gt;.&lt;/p&gt;

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