<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dmitry Stepanov on Medium]]></title>
        <description><![CDATA[Stories by Dmitry Stepanov on Medium]]></description>
        <link>https://medium.com/@stepdi?source=rss-bd8561a10a5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-4GPFXrfBUrB7G3EdPu1pQ.jpeg</url>
            <title>Stories by Dmitry Stepanov on Medium</title>
            <link>https://medium.com/@stepdi?source=rss-bd8561a10a5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:31:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stepdi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I turned 10 years of scattered health records into a personal medical assistant]]></title>
            <link>https://medium.com/@stepdi/i-turned-10-years-of-scattered-health-records-into-a-personal-medical-assistant-9bfd3cdd3da3?source=rss-bd8561a10a5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bfd3cdd3da3</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[health]]></category>
            <dc:creator><![CDATA[Dmitry Stepanov]]></dc:creator>
            <pubDate>Mon, 30 Mar 2026 14:14:55 GMT</pubDate>
            <atom:updated>2026-03-30T14:14:55.806Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfFnA0iMhYa_6s8jsWF8vg.png" /></figure><p>I’ve wanted to do this since 2023, back when ChatGPT 3.5 came out and everyone was building RAG pipelines. I had a decade of medical data spread across Gmail, a clinic app, and eight years of WhatsApp messages with my doctor. Lab results, prescriptions, consultation notes, photos of test printouts. None of it connected.</p><p>Every time I sat down to build something, I’d scope out the work: Gmail API integration, PDF parsers for a dozen lab formats, a data schema, retrieval system, interface. A few weeks of engineering, minimum. So it stayed on the “someday” list.</p><p>Last week I tried a different approach. I opened Claude Code and just described what I wanted. Two hours later, I had a working health assistant grounded in my actual medical records.</p><p>I didn’t write any code. Claude wrote the Gmail fetcher, PDF parsers, deduplication logic, LLM extraction pipeline, and the final database assembly. I directed the process, caught errors in parsing, and made judgment calls about what mattered. My engineering background helped me steer, but the execution was entirely Claude’s.</p><h4><strong>How it came together</strong></h4><p>On the data side: ~180 emails pulled via Gmail API (read-only), a WhatsApp export with 3,356 messages and 315 files, and 108 PDFs from a clinic app. About 500 documents total.</p><blockquote>- How come you have so much data on your health?<br>- I’ve been dealing with a lot, and I’ve tried not to switch doctors or medical centers.</blockquote><p>Parsing was the messy part. Clinic HTML files turned out to be in cp1251 encoding. Lab PDFs where every provider formats tables differently. Some with encrypted fonts that couldn’t be extracted at all. The same consultation sometimes existed in two formats, so Claude wrote merge logic that kept the structured data from one and the full text from the other. Regex extraction got 591 lab measurements across 96 markers, which was enough to plot trends over a decade.</p><p>Then I asked whether regex was missing anything, and the answer was obviously yes. I ran the full dataset through GPT-5.4-mini (cheap, fast, low reasoning): 181 weeks of WhatsApp conversations, 60 consultation documents, and 249 photos via vision. It caught medication changes discussed casually in chat, the doctor’s reasoning that never made it to formal records, and 171 medically relevant images that would have stayed buried as random JPEGs. Way more signal than regex alone.</p><p>The final step was loading the resulting 1.2MB structured database into Claude’s million-token context and asking it to produce a medical profile and a lab trends analysis covering every significant marker over the full decade.</p><h4><strong>What it found</strong></h4><p>The assistant cross-referenced records that no single doctor had seen together. Two things stood out.</p><p>A group of procedures I’d been getting regularly for years <strong>turned out to have no evidence base</strong> for my particular condition, which international guidelines classify as benign and not requiring treatment. A different set of procedures was well-justified, but for reasons tied to findings from a specialist, not the original prescribing doctor.</p><p>A medication I’d been taking for 3+ years has documented vascular effects in the literature. The assistant connected that to a finding on an MRI done earlier by a different provider. <em>I now have a specific, research-backed question for my next appointment.</em></p><p>Neither insight required medical expertise on my part. The assistant pulled published research, matched it against my records, and showed me where the dots connected.</p><p>This isn’t a replacement for doctors. I don’t self-diagnose or self-prescribe. But walking into an appointment with your complete history, the right questions, and relevant research links changes the conversation.</p><p>The tools for this are all commodity now. Email APIs, PDF parsers, vision models, million-token context windows. Two years ago I had the idea but not the leverage. That’s changed.</p><p>If you found this interesting, feel free to connect on LinkedIn: <a href="https://www.linkedin.com/in/stepdi/">https://www.linkedin.com/in/stepdi/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bfd3cdd3da3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Legal RAG System: Lessons from the ARLC 2026]]></title>
            <link>https://medium.com/@stepdi/building-a-legal-rag-system-lessons-from-the-arlc-2026-d3818deeb0c1?source=rss-bd8561a10a5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3818deeb0c1</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Dmitry Stepanov]]></dc:creator>
            <pubDate>Mon, 23 Mar 2026 16:10:10 GMT</pubDate>
            <atom:updated>2026-03-23T17:25:57.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebN7PulFQlLMDlsp0pGZKw.jpeg" /></figure><p>My score plateaued around 0.86–0.87 halfway through. I spent the remaining submissions trying to break past it — clause-aware chunking, agentic retrieval, smaller models, different embeddings — and most of them made things worse. The gap between “this should obviously help” and what actually moves the score was the hardest part of this competition.</p><p>This is a write-up of the <a href="https://agentic-challenge.ai/">Agentic RAG Legal Challenge 2026</a>: a competition where you build a RAG system over DIFC legal documents (court cases, legislation) and answer 900 questions. The scoring formula looks simple but hides traps:</p><pre>Total = (0.7 * Det + 0.3 * Asst) * Grounding * Telemetry * TTFT_factor</pre><p>70% of the questions are deterministic (booleans, numbers, names, dates — exact match). 30% are free-text (280-char legal summaries scored by an LLM judge you can’t inspect). Every answer must cite the exact document and page where the evidence lives. And the whole thing is multiplied by how fast your first token arrives.</p><h3>The first Sonnet pipeline was surprisingly good</h3><p>My first submission was the LangChain example from the starter kit — 0.323. My own pipeline (Claude Sonnet 4.6, Voyage AI embeddings, Qdrant, page-level chunks) scored 0.335. Answer quality was decent — deterministic 0.914, assistant 0.742 — but grounding was 0.391. I was citing ~15 pages per question when gold answers reference ~2.</p><p>Adding hybrid search (BM25 + dense with RRF fusion) and Cohere reranking pushed grounding to 0.840 and total to 0.735. Switching to structured output via Anthropic’s tool_use got deterministic to a perfect 1.000 that held across every subsequent submission.</p><p>By v8, with prompt tuning and citation trust improvements, I was at total 0.868 — all from grounding gains (0.937), with deterministic staying at 1.000 and assistant at 0.747. Page-level chunks, basic routing, nothing fancy. Sonnet is clever enough to parse legal text from raw PDF extraction and produce accurate answers. The simple approach was carrying most of the weight.</p><h3>Flying blind on free-text</h3><p>For deterministic questions I built a local gold dataset — once I hit 1.000, I knew all 70 correct answers and could evaluate without burning submissions. For the 30 free-text questions, the only feedback was submitting and reading the scores back. No rubric, no example graded answers, no local proxy.</p><p>I tried to build one. Wrote reference answers manually, generated them with other LLMs that had full access to the documents. Compared outputs, thought “these are clearly better.” Submitted. Score stayed the same or went down. This happened multiple times — with prompt rewrites, with chunking changes, with different context assembly strategies. Each time I was sure the answers improved. The judge disagreed.</p><p>You can’t use external knowledge to compensate either. The judge scores answers grounded in the specific corpus. A richer answer informed by legal knowledge outside the documents might actually score worse than a concise one that just cites what’s there.</p><p>The assistant score sat at ~0.74 for 15 submissions. Grounding (which has an objective, measurable formula) went from 0.391 to 0.946 in the same period. The difference: I could measure one locally and optimize it. The other was a black box I fed submissions into.</p><h3>“Agentic” in a TTFT-limited world</h3><p>The challenge has “Agentic” in the name. I tried an agentic routing step — using Cerebras’s fast inference (~3000 tok/s) with structured outputs to analyze each question before searching: extract case numbers, classify question type, rewrite queries. It made retrieval more precise but added ~800ms per question. Total dropped from 0.868 to 0.834 because the TTFT penalty ate the quality gain.</p><p>I replaced it with regex routing — case number extraction, “first page”/”last page” keyword detection. Zero latency, same results for this corpus.</p><h3>The reranker</h3><p>Cohere rerank-v3.5 was part of the first big improvement (v3), but the grounding jump from 0.391 to 0.840 came from multiple changes at once — hybrid search, better prompts for citation, trusting the model’s own page references. The reranker helped narrow 50 candidates to 10 relevant chunks with page-level chunking.</p><p>After switching to smaller, clause-aware chunks the picture changed. The reranker started burying chunks from small documents behind chunks from large ones in cross-case questions. Disabling it and relying on raw hybrid search (which balances results across documents via RRF fusion) fixed several retrieval failures, saved ~250–300ms per question, and simplified the pipeline.</p><h3>The smaller model surprise</h3><p>I tested Haiku, GPT-5.4, and GPT-5.4-mini. They all dropped deterministic questions — until I turned on reasoning_effort=low for GPT-5.4-mini. That got it back to 70/70 deterministic with avg TTFT of 1176ms. One gotcha: with reasoning models, the first streamed token is a reasoning token, not an answer token. My TTFT numbers looked amazing until I realized I was measuring the wrong thing.</p><p>The real surprise came on final. Mini with reasoning=low scored Asst 0.674 vs Sonnet’s 0.571 on the same 900-question corpus. Sonnet wrote longer, more nuanced answers with more legal context. The judge preferred mini’s shorter, more direct style. At 1020ms avg TTFT (63% under 1 second), mini scored 0.648 total vs Sonnet’s 0.641.</p><h3>Chunking and embeddings</h3><p>Page-level chunks worked well with Sonnet — the model finds the right paragraph in a full page of legal text. Smaller clause-aware and paragraph-level chunks improved grounding but hurt assistant quality. I never fully resolved that tradeoff.</p><p>One clear win: every chunk must map to exactly one page. Multi-page chunks made the LLM cite all pages when only one mattered.</p><p>I tried three embedding models (voyage-law-2, voyage-3-large, OpenAI text-embedding-3-large). No meaningful quality difference between them. The newer Voyage model was slightly faster on query embedding.</p><h3>The final phase</h3><p>On final (300 docs, 900 questions), everything dropped — grounding to 0.752, deterministic to 0.897. The 10x document increase exposed retrieval precision limits. GPT-5.4-mini outperformed Sonnet on assistant quality by a wide margin.</p><p>Two final submissions wasn’t enough. My best warmup config (Sonnet) lost to mini on the final corpus. The platform showed the deadline as Saturday, so I rushed to burn my second submission testing Sonnet against mini. It scored worse. The actual deadline turned out to be Sunday — but I’d already used both.</p><h3>Looking back</h3><p>Most of the pipeline code, experiments, and this post were built with Claude Code (Opus). After each phase I’d ask it to write up key findings — what changed, what the scores were, what we learned. That running log turned out to be more valuable than the code itself. When I needed to understand why v11 scored worse than v8, the notes were there. If you’re doing a competition like this, keep a detailed log as you go.</p><p>If I started over, I’d invest more in ingestion. I already use Haiku to generate document summaries and breadcrumbs per chunk, and Qdrant payload filters for routing by case number and page position. But the metadata is still basic. Going further — extracting parties, judges, dates, order types per chunk with an LLM, storing them as filterable payloads — would make both search and generation more precise. Other teams scoring 0.93+ have assistant scores around 0.84 with similar deterministic and grounding. The gap is in free-text quality, and I think richer ingestion is what separates their systems from mine.</p><p>This was a great experience. Strict deadlines, a leaderboard, moments of “why is this worse?” followed by moments of “wait, that actually worked.” High expectations that crash into reality when you submit.</p><p>There is no standard recipe for a perfect RAG system. I’ve built RAGs before — with agents, with small models like Qwen3 8B, and got great results. But every domain is different. What works for one corpus and scoring function fails for another. A competition RAG isn’t a production RAG either, though I tried to keep it as close as I could.</p><p>The main thing I took away: the interesting problems in RAG aren’t in the retrieval algorithm or the generation model. They’re in understanding your documents, your scoring function, and the gap between what you think is a good answer and what the system thinks is a good answer.</p><p>If you found this interesting, feel free to connect on LinkedIn: <a href="https://www.linkedin.com/in/stepdi/">https://www.linkedin.com/in/stepdi/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3818deeb0c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup your own fast ChatGPT with auth and SSL]]></title>
            <link>https://medium.com/@stepdi/setup-your-own-fast-chatgpt-with-auth-and-ssl-9ae842d7f646?source=rss-bd8561a10a5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ae842d7f646</guid>
            <category><![CDATA[it]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Dmitry Stepanov]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 17:16:18 GMT</pubDate>
            <atom:updated>2023-03-29T10:07:24.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgQV6GiSBuv-IN0QB4yv9w.png" /></figure><p>You can setup your own ChatGPT UI on a simplest virtual server. I use 1CPU, 512MB, 7GB – the most basic plan (almost free) and it is much faster than using the official OpenAI client (you can see huge speed difference when prompting not in English).</p><p>It supports both GPT-3.5 and GPT-4 but for the last one you will need access to its API (<a href="https://openai.com/waitlist/gpt-4-api">join the waitlist</a>). But GPT 3.5 is very good also.</p><p>You will need:</p><ul><li>Any virtual server — I prefer with Debian</li><li>chatbot-ui — <a href="https://github.com/mckaywrigley/chatbot-ui">https://github.com/mckaywrigley/chatbot-ui</a></li><li><a href="https://platform.openai.com/account/api-keys">OpenAI API key </a>— you can enjoy free $5 for tests (enough for so much prompts, I spent less than $1 for a week)</li><li><a href="https://caddyserver.com/">Caddy</a> – open-source web-server with HTTPS, auth and very simple configs</li></ul><p>Your server must be in one of supported countries by OpenAI (not in Belarus, Russia or China for example, see <a href="https://platform.openai.com/docs/supported-countries">the full list of supported countries</a>).</p><h4>Setup the UI</h4><p>You will need NodeJS and git installed in your server. If your NodeJS version is old consider using nvm. Then run the script:</p><pre>git clone https://github.com/mckaywrigley/chatbot-ui.git<br>cd chatbot-ui &amp;&amp; npm i</pre><p>Now you need OpenAI API key. Go get one in <a href="https://platform.openai.com/account/api-keys">API keys</a> section in your OpenAI profile with “Create new secret key” button. Create file .env.local in project’s folder with the following content:</p><pre>OPENAI_API_KEY=YOUR_KEY</pre><p>If your server is powerful enough to build the project build it and run:</p><pre>npm run build<br>nohup npm start -- -H 127.0.0.1 -p 3001 &amp;</pre><p>Additional parameters like -H needed to prevent unauthorised access to the UI. Nohup is needed to prevent the process from stopping when you close the console.</p><p>If this process takes too long try to build the project locally and then copy it to your server. On my server it was impossible to build the project so I needed to build it on my Mac with same NodeJS version and then transfer it to the server.</p><h4>Setup the web-server with auth and HTTPS (optional)</h4><p>I recommend to use <a href="https://caddyserver.com/">Caddy</a> because it maintains Let’s Encrypt SSL certificates automatically and it is very simple to config. Install it according to <a href="https://caddyserver.com/docs/install#debian-ubuntu-raspbian">the simple guide</a>. I also recommend to complete the <a href="https://caddyserver.com/docs/getting-started">Getting Started</a> tutorial (optional).</p><p>Create file named Caddyfile with following content (you can generate password hash <a href="https://bcrypt-generator.com/">here</a> or with <a href="https://unix.stackexchange.com/questions/307994/compute-bcrypt-hash-from-command-line">htpasswd</a>):</p><pre>your-host.com {<br>  reverse_proxy 127.0.0.1:3001<br>  basicauth {<br>    Bob your-generated-bcrypt-password-hash<br>  }<br>}</pre><p>And then run Caddy:</p><pre>caddy start</pre><p>Caddy will issue Let’s Encrypt SSL certificate for your domain and run.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpmiqmJjgZmE&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpmiqmJjgZmE&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FpmiqmJjgZmE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5586b5c645fd967ba89c4d7d7ca9b8cb/href">https://medium.com/media/5586b5c645fd967ba89c4d7d7ca9b8cb/href</a></iframe><p>Now you can enjoy your own fast ChatGPT UI and give access to your friends.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ae842d7f646" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>