<?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: henry</title>
    <description>The latest articles on DEV Community by henry (@henry_redfox).</description>
    <link>https://dev.to/henry_redfox</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3976988%2Fbc61215f-4947-44b6-844c-75570b29663a.png</url>
      <title>DEV Community: henry</title>
      <link>https://dev.to/henry_redfox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/henry_redfox"/>
    <language>en</language>
    <item>
      <title>How I Built a Chrome Extension That Analyzes Contracts Using 1,700+ Real Statutes as RAG Grounding</title>
      <dc:creator>henry</dc:creator>
      <pubDate>Wed, 10 Jun 2026 05:48:24 +0000</pubDate>
      <link>https://dev.to/henry_redfox/how-i-built-a-chrome-extension-that-analyzes-contracts-using-1700-real-statutes-as-rag-grounding-37fk</link>
      <guid>https://dev.to/henry_redfox/how-i-built-a-chrome-extension-that-analyzes-contracts-using-1700-real-statutes-as-rag-grounding-37fk</guid>
      <description>&lt;p&gt;Two months ago I signed a contract with an auto-renewal clause I didn't notice. When I tried to cancel, I owed another year. That $1,200&lt;br&gt;
  mistake turned into PactLens — a Chrome extension that reviews contracts before you sign.&lt;/p&gt;

&lt;p&gt;The core problem: LLMs hallucinate. You can't just ask an AI "is this clause risky" — it'll confidently make up laws that don't exist. So I&lt;br&gt;
  needed real statutes as a source of truth.&lt;/p&gt;

&lt;p&gt;The RAG Pipeline&lt;/p&gt;

&lt;p&gt;Here's how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User selects contract text on any page → right-clicks → "Review with PactLens"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The text hits our Cloudflare Worker backend, which extracts clause-level semantics&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We run semantic search against 1,700+ pre-loaded statutes using keyword matching + TF-IDF similarity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The top N most relevant statutes are injected into the prompt as context&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The AI generates analysis grounded in those &lt;em&gt;actual&lt;/em&gt; statutes, not hallucinations&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key insight: &lt;strong&gt;ground first, generate second&lt;/strong&gt;. The AI doesn't need to know every law — it just needs to know how to &lt;em&gt;apply&lt;/em&gt; the specific&lt;br&gt;
  statutes we feed it.&lt;/p&gt;

&lt;p&gt;Why Static Pre-Loading Over a Vector Database&lt;/p&gt;

&lt;p&gt;A vector DB would be "cleaner" architecturally. But:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Embedding 1,700+ statutes costs money and adds latency&lt;/li&gt;
&lt;li&gt;Cloudflare Workers don't have great vector DB support&lt;/li&gt;
&lt;li&gt;The statutes don't change daily — they're stable enough for pre-loading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I went with plain text matching + TF-IDF stored in KV. Simple, fast, and surprisingly effective.&lt;/p&gt;

&lt;p&gt;## What I'd Do Differently&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start with the Chrome Web Store review guidelines FIRST, not last&lt;/li&gt;
&lt;li&gt;Use a lighter embedding model for better semantic search&lt;/li&gt;
&lt;li&gt;Add a feedback loop — let users flag incorrect analysis&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stack&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hono + Cloudflare Workers (backend)&lt;/li&gt;
&lt;li&gt;WXT + TypeScript (extension)&lt;/li&gt;
&lt;li&gt;KV for statute storage&lt;/li&gt;
&lt;li&gt;DeepSeek for AI inference&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Links&lt;/p&gt;

&lt;p&gt;Chrome Store: [link]&lt;br&gt;
  Web App: &lt;a href="https://pactlens.net/contract" rel="noopener noreferrer"&gt;https://pactlens.net/contract&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Would love feedback from anyone who's worked on RAG systems — especially on making semantic search fast at the edge.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>typescript</category>
      <category>tutorial</category>
      <category>chromeextension</category>
    </item>
  </channel>
</rss>
