<?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: overthelex</title>
    <description>The latest articles on DEV Community by overthelex (@overthelex).</description>
    <link>https://dev.to/overthelex</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%2F4014092%2F77686e8e-9386-45c3-99d4-c0e9eaff9029.png</url>
      <title>DEV Community: overthelex</title>
      <link>https://dev.to/overthelex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/overthelex"/>
    <language>en</language>
    <item>
      <title>340 Million Records and 64 Tools: The Complete Data Map of LEX AI</title>
      <dc:creator>overthelex</dc:creator>
      <pubDate>Fri, 03 Jul 2026 21:52:42 +0000</pubDate>
      <link>https://dev.to/overthelex/340-million-records-and-64-tools-the-complete-data-map-of-lex-ai-4kef</link>
      <guid>https://dev.to/overthelex/340-million-records-and-64-tools-the-complete-data-map-of-lex-ai-4kef</guid>
      <description>&lt;p&gt;The LEX AI platform is built on a simple idea: lawyers shouldn't waste time manually searching across dozens of websites. Instead — one question in chat, and the AI finds the right data from every available source.&lt;/p&gt;

&lt;p&gt;Today in production we serve &lt;strong&gt;340+ million records&lt;/strong&gt; from 30+ sources, unified through &lt;strong&gt;64 MCP tools&lt;/strong&gt; (Model Context Protocol). This article is the complete overview: what we have, where it comes from, and how it works.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Big Picture
&lt;/h2&gt;

&lt;p&gt;| Category | Records | Tools |&lt;br&gt;
|———-|———|——-|&lt;br&gt;
| EDRSR (court decisions) | ~208M | 6 |&lt;br&gt;
| Court system | 30.5M+ | 7 |&lt;br&gt;
| OpenReyestr + NAIS | 41.8M | 24 |&lt;br&gt;
| Sanctions &amp;amp; anti-corruption | 1.7M | 4 |&lt;br&gt;
| ARMA + Due Diligence | 2M+ | 5 |&lt;br&gt;
| Intellectual property | 295K | 3 |&lt;br&gt;
| Public finance | 1M+ | 4 |&lt;br&gt;
| Verkhovna Rada | 85K | 4 |&lt;br&gt;
| Legislation | 318K | 3 |&lt;br&gt;
| Attorneys &amp;amp; judges | 73K+ | 3 |&lt;br&gt;
| &lt;strong&gt;Total&lt;/strong&gt; | &lt;strong&gt;~340M+&lt;/strong&gt; | &lt;strong&gt;64&lt;/strong&gt; |&lt;/p&gt;




&lt;h2&gt;
  
  
  1. EDRSR — The Heart of the Platform (208M Records)
&lt;/h2&gt;

&lt;p&gt;The Unified State Register of Court Decisions is the largest data source on the platform. Two datasets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;edrsr_documents&lt;/strong&gt; — 93M metadata records (court, judge, date, category, parties)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;edrsr_fulltext&lt;/strong&gt; — 115M full decision texts (~1 TB)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What You Can Do
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"Find Supreme Court decisions on moral damages compensation&lt;br&gt;
for 2024-2025"&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The AI selects one of 6 tools:&lt;/p&gt;

&lt;p&gt;| Tool | Purpose |&lt;br&gt;
|——|———|&lt;br&gt;
| &lt;code&gt;search_edrsr_decisions\&lt;/code&gt; | Filtered search by metadata |&lt;br&gt;
| &lt;code&gt;search_edrsr_fulltext\&lt;/code&gt; | Full-text search with highlighting |&lt;br&gt;
| &lt;code&gt;search_edrsr_semantic\&lt;/code&gt; | Semantic search by meaning (Voyage AI) |&lt;br&gt;
| &lt;code&gt;get_edrsr_decision_fulltext\&lt;/code&gt; | Full text of a decision |&lt;br&gt;
| &lt;code&gt;get_court_decision\&lt;/code&gt; | Text split into FACTS / REASONING / DECISION |&lt;br&gt;
| &lt;code&gt;get_citation_graph\&lt;/code&gt; | Citation graph between decisions |&lt;/p&gt;

&lt;p&gt;Semantic search means you describe a situation in your own words, and the system finds decisions with similar circumstances — even when not a single keyword matches.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Court System (30.5M+ Records)
&lt;/h2&gt;

&lt;p&gt;Beyond the decisions themselves, the platform holds data on the entire judicial process:&lt;/p&gt;

&lt;p&gt;| Source | Records | Contents |&lt;br&gt;
|——–|———|———-|&lt;br&gt;
| Court sessions | 30.5M | Date, court, judge, parties, outcome |&lt;br&gt;
| Judges (HQCJ) | 417K | Dossiers, tenure, decisions, disciplinary actions |&lt;br&gt;
| Case status | 1.25M | Tracking case movement across instances |&lt;br&gt;
| Session schedule | 480K | Scheduled hearings for 2026 |&lt;br&gt;
| Court experts | 80K | MOJ-certified experts |&lt;br&gt;
| ECHR practice | 11K | European Court of Human Rights decisions |&lt;br&gt;
| HCJ decisions | 16.5K | Disciplinary decisions regarding judges |&lt;br&gt;
| HQCJ (extended) | 4.8K | Qualification, evaluation, vacancies |&lt;br&gt;
| Automatic assignment | 71K | SJAU protocols |&lt;/p&gt;

&lt;h3&gt;
  
  
  Procedural Tools
&lt;/h3&gt;

&lt;p&gt;A separate group of tools assists with procedural work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;calculate_procedural_deadlines\&lt;/code&gt;&lt;/strong&gt; — calculate appeal deadlines by procedural code (CPC, CC, CAS, CrPC)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;search_procedural_norms\&lt;/code&gt;&lt;/strong&gt; — find relevant articles of procedural codes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;build_procedural_checklist\&lt;/code&gt;&lt;/strong&gt; — generate a checklist for a specific case stage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"What is the deadline for appealing a commercial court decision?"&lt;br&gt;
→ Article 256 CC: 20 days from the date of the full text&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  3. OpenReyestr + NAIS (41.8M Records)
&lt;/h2&gt;

&lt;p&gt;11 state registries from data.gov.ua plus EDR data — the most comprehensive database for due diligence:&lt;/p&gt;

&lt;p&gt;| Registry | Records |&lt;br&gt;
|———-|———|&lt;br&gt;
| Enforcement proceedings (ASVP) | 29M |&lt;br&gt;
| Debtors registry | 10.4M |&lt;br&gt;
| Individual entrepreneurs (FOP) | 6.9M |&lt;br&gt;
| Company founders | 3M |&lt;br&gt;
| Authorized signatories | 2.8M |&lt;br&gt;
| Legal entities | 2M |&lt;br&gt;
| Notarial special forms | 1.8M |&lt;br&gt;
| Streets (address registry) | 1.5M |&lt;br&gt;
| Administrative-territorial units | 924K |&lt;br&gt;
| Tax debt | 861K |&lt;br&gt;
| Social contribution (SSC) debt | 669K |&lt;br&gt;
| VAT payers | 264K |&lt;br&gt;
| Simplified taxation | 153K |&lt;br&gt;
| Bankruptcy | 36K |&lt;br&gt;
| Notaries | 5.8K |&lt;br&gt;
| Arbitration managers | 3.4K |&lt;br&gt;
| Forensic examination methods | 1.5K |&lt;/p&gt;

&lt;p&gt;24 OpenReyestr tools cover: company search, beneficial owners, debtors, enforcement proceedings, bankruptcy, notaries, experts, VAT, SSC, and address data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Due Diligence in 30 Seconds
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"Check counterparty by EDRPOU 12345678"&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The AI automatically checks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Registration in EDR (legal entity / individual entrepreneur)&lt;/li&gt;
&lt;li&gt;Enforcement proceedings (ASVP)&lt;/li&gt;
&lt;li&gt;Debtors registry&lt;/li&gt;
&lt;li&gt;Bankruptcy&lt;/li&gt;
&lt;li&gt;Sanctions lists&lt;/li&gt;
&lt;li&gt;Court decisions (EDRSR)&lt;/li&gt;
&lt;li&gt;Tax debt&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The result is a structured report from all sources in a single window.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Sanctions &amp;amp; Anti-Corruption (1.7M Records)
&lt;/h2&gt;

&lt;p&gt;| Source | Records | Coverage |&lt;br&gt;
|——–|———|———-|&lt;br&gt;
| OpenSanctions | 1.25M | NSDC, OFAC, EU, UN, UK + 340 programs |&lt;br&gt;
| NAPC declarations | 322K | Official asset declaration checks |&lt;br&gt;
| Corruption registry | 107.5K | Registry of persons involved in corruption |&lt;br&gt;
| Declaration audits | 2K | NAPC audit results |&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"Is Ivanov Petro Serhiyovych on any sanctions lists?"&lt;br&gt;
→ Search across 1.25M records: NSDC, OFAC, EU, UN, UK, and 340+ other programs&lt;br&gt;
→ Fuzzy matching by name, TIN, passport, EDRPOU&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Intellectual Property (295K Records)
&lt;/h2&gt;

&lt;p&gt;| Source | Records |&lt;br&gt;
|——–|———|&lt;br&gt;
| Patents (Ukrpatent) | 118K |&lt;br&gt;
| Trademarks | 176K |&lt;br&gt;
| Shareholders (NSSMC) | 1.3K |&lt;/p&gt;

&lt;p&gt;Search by name, owner, NICE class (for trademarks) or IPC (for patents), application number.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"Find trademarks containing 'Legal' in class 42"&lt;br&gt;
→ 3 results: LEX AI (certificate No. 345678), LegalTech Pro...&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Public Finance (1M+ Records)
&lt;/h2&gt;

&lt;p&gt;| Source | Records |&lt;br&gt;
|——–|———|&lt;br&gt;
| Prozorro tenders | 1M |&lt;br&gt;
| Spending.gov.ua contracts | 2.8K |&lt;br&gt;
| SSSU financial data | 8.4K |&lt;br&gt;
| Inspection plans | 32K |&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Verkhovna Rada (85K Records)
&lt;/h2&gt;

&lt;p&gt;4 tools for monitoring parliamentary activity:&lt;/p&gt;

&lt;p&gt;| Data | Records |&lt;br&gt;
|——|———|&lt;br&gt;
| Bills | 14.8K |&lt;br&gt;
| Votes | 21.9K |&lt;br&gt;
| Deputies | 463 |&lt;br&gt;
| Deputies' assistants | 4.4K |&lt;br&gt;
| Full legislative texts | 44K |&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
"Which deputies voted for bill 1234?"&lt;br&gt;
→ Full list broken down by faction&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Legislation (318K Records)
&lt;/h2&gt;

&lt;p&gt;| Source | Records |&lt;br&gt;
|——–|———|&lt;br&gt;
| EDRNPA (cards) | 141K |&lt;br&gt;
| EDRNPA (texts) | 141K |&lt;br&gt;
| Law sections (chunks) | 25K |&lt;br&gt;
| Articles (structured) | 12K |&lt;/p&gt;

&lt;p&gt;3 tools for working with legislation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;search_legislation\&lt;/code&gt;&lt;/strong&gt; — semantic search across legislative texts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;get_legislation_article\&lt;/code&gt;&lt;/strong&gt; — specific article ("Art. 625 CC")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;get_legislation_history\&lt;/code&gt;&lt;/strong&gt; — amendment and revision history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system understands aliases: "Constitution", "CC" (Civil Code), "CrPC" (Criminal Procedure Code), "CommC" (Commercial Code), etc.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Analytical Tools
&lt;/h2&gt;

&lt;p&gt;Beyond search, the platform includes tools for legal analysis:&lt;/p&gt;

&lt;p&gt;| Tool | What It Does |&lt;br&gt;
|——|————-|&lt;br&gt;
| &lt;code&gt;analyze_case_pattern\&lt;/code&gt; | Analyzes arguments, risks, and outcome statistics |&lt;br&gt;
| &lt;code&gt;compare_practice_pro_contra\&lt;/code&gt; | Compares case law "for" and "against" a thesis |&lt;br&gt;
| &lt;code&gt;find_similar_reasoning\&lt;/code&gt; | Finds decisions with similar reasoning sections |&lt;br&gt;
| &lt;code&gt;check_precedent_status\&lt;/code&gt; | Checks whether a precedent is valid / overturned / limited |&lt;br&gt;
| &lt;code&gt;validate_response\&lt;/code&gt; | Anti-hallucination verification of AI responses |&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture: How It Works
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;&lt;br&gt;
Lawyer → Chat → AI Model → Intent Classifier&lt;br&gt;
                              ↓&lt;br&gt;
                    Tool Selection (1-5 out of 64)&lt;br&gt;
                              ↓&lt;br&gt;
                    PostgreSQL / Qdrant / Redis&lt;br&gt;
                              ↓&lt;br&gt;
                    Structured Response&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Each tool is an MCP tool (Model Context Protocol). The AI model autonomously selects which tools to call based on the query context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Three transports:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MCP stdio&lt;/strong&gt; — for Claude Desktop&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP API&lt;/strong&gt; — for web applications&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSE&lt;/strong&gt; — for streaming results&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;Coming up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Completing UIPV import&lt;/strong&gt; — trademarks (46% loaded), utility models (162K), industrial designs (48K)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DRRP (real estate registry)&lt;/strong&gt; — agreement with NAIS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DRORM (movable property encumbrances)&lt;/strong&gt; — agreement with NAIS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SLC (State Land Cadastre)&lt;/strong&gt; — agreement with the State Geocadastre&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spending.gov.ua&lt;/strong&gt; — acts, supplementary agreements, penalties (API ready)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bulk download RTF&lt;/strong&gt; — full texts of EDRSR decisions&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;LEX AI is more than search. It's a single access point to all of Ukraine's open legal data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;340M+ records&lt;/strong&gt; from 30+ sources&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;64 MCP tools&lt;/strong&gt; for search, analysis, and verification&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic search&lt;/strong&gt; — describe the situation, find the decisions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Due diligence&lt;/strong&gt; — counterparty check in 30 seconds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Procedural calculators&lt;/strong&gt; — deadlines, checklists, norms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of this is live right now at &lt;a href="https://legal.org.ua" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Register: &lt;a href="https://legal.org.ua" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://legal.org.ua/blog/open-data-340m-production" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>opendata</category>
      <category>mcp</category>
      <category>sanctions</category>
      <category>ip</category>
    </item>
    <item>
      <title>Distributed Monolith: When Microservices Are Just a Monolith with Network Latency</title>
      <dc:creator>overthelex</dc:creator>
      <pubDate>Fri, 03 Jul 2026 21:47:30 +0000</pubDate>
      <link>https://dev.to/overthelex/distributed-monolith-when-microservices-are-just-a-monolith-with-network-latency-57kh</link>
      <guid>https://dev.to/overthelex/distributed-monolith-when-microservices-are-just-a-monolith-with-network-latency-57kh</guid>
      <description>&lt;p&gt;&lt;em&gt;You split your code into services. You have separate containers. You even have a gateway. So why does deploying one service still break the other?&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a distributed monolith
&lt;/h2&gt;

&lt;p&gt;A distributed monolith is an architecture that &lt;em&gt;looks&lt;/em&gt; like microservices but &lt;em&gt;behaves&lt;/em&gt; like a monolith. Services are separated at the code level but remain coupled at the infrastructure, data, or deployment level.&lt;/p&gt;

&lt;p&gt;Classic symptoms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shared database&lt;/strong&gt; – different services read/write to the same PostgreSQL instance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared library without versioning&lt;/strong&gt; – a change in a common package breaks everyone simultaneously&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One docker-compose&lt;/strong&gt; – all services are deployed together, even if only one changed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous HTTP calls&lt;/strong&gt; – service A cannot function if service B is unresponsive&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared cache&lt;/strong&gt; – one Redis for everyone, LRU eviction from one service kills another's cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sound familiar? That's our architecture. And we believe that right now – it's the &lt;em&gt;right choice&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  When a distributed monolith is the right choice
&lt;/h2&gt;

&lt;p&gt;Here's an unpopular opinion: &lt;strong&gt;a distributed monolith isn't always a problem&lt;/strong&gt;. At a certain scale, it's the optimal architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits we get
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Operational simplicity&lt;/strong&gt; – One docker compose up brings everything up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Development speed&lt;/strong&gt; – A shared package means DRY.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Transactional integrity&lt;/strong&gt; – One PostgreSQL = the ability to JOIN across schemas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Debuggability&lt;/strong&gt; – One docker compose logs shows the entire request flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Cost&lt;/strong&gt; – One server instead of three.&lt;/p&gt;

&lt;h3&gt;
  
  
  The formula: when a distributed monolith is enough
&lt;/h3&gt;

&lt;p&gt;Team &amp;lt; 5 developers, load &amp;lt; 1000 RPS, deploys &amp;lt; 5/day, one server handles it, no requirements for independent scaling.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step-by-step evolution plan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Phase 1: Hardening (effort: low, impact: 80%)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Split Redis into separate instances per service&lt;/li&gt;
&lt;li&gt;Version the shared package with semver&lt;/li&gt;
&lt;li&gt;Add circuit breaker in RemoteServiceClient&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Phase 2: Infrastructure independence
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Separate PostgreSQL instances&lt;/li&gt;
&lt;li&gt;Split docker-compose per service&lt;/li&gt;
&lt;li&gt;API contracts between services&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Phase 3: True microservices (team &amp;gt; 5)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Service discovery instead of env vars&lt;/li&gt;
&lt;li&gt;Message queue for async operations&lt;/li&gt;
&lt;li&gt;Independent CI/CD pipelines&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;A distributed monolith is not a diagnosis. It's a stage in architectural evolution. &lt;strong&gt;80% of microservice benefits can be achieved with 20% of the effort&lt;/strong&gt; – by splitting Redis, adding a circuit breaker, and versioning your shared package.&lt;/p&gt;




&lt;p&gt;Sign up: &lt;a href="https://legal.org.ua" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://legal.org.ua/blog/distributed-monolith" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>monolith</category>
      <category>scaling</category>
    </item>
    <item>
      <title>Opus + RAG vs Fine-tuned LLM + RAG: Two Approaches to Legal AI — LEX vs Harvey</title>
      <dc:creator>overthelex</dc:creator>
      <pubDate>Fri, 03 Jul 2026 21:42:18 +0000</pubDate>
      <link>https://dev.to/overthelex/opus-rag-vs-fine-tuned-llm-rag-two-approaches-to-legal-ai-lex-vs-harvey-19b</link>
      <guid>https://dev.to/overthelex/opus-rag-vs-fine-tuned-llm-rag-two-approaches-to-legal-ai-lex-vs-harvey-19b</guid>
      <description>&lt;p&gt;&lt;em&gt;Harvey spent $100M+ and trained a custom model on the entire US case law corpus. We connected Claude Opus to 100M+ court decisions from EDRSR via RAG. Both work. But these are fundamentally different engineering and business decisions.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When an ordinary AI startup from Ukraine applies to Google for Startups Cloud Program and receives a five-figure dollar grant — that's not luck. It's validation of the approach. Google saw the same thing we see: 100M+ court decisions, an open data corpus unmatched in scale anywhere in Europe, and a team that has already built a production RAG system on top of it. Google Cloud resources — TPU pods, compute credits, engineering support — are not charity. It's an investment in Ukraine's jurisdiction becoming the first proving ground for open-weight legal AI based on DeepSeek v3, trained on real data from a real legal system. Harvey spent $100M on a partnership with OpenAI for US case law. We're doing the same for Ukraine — with a grant from Google, an open model, and a corpus assembled from public registries.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Context: Why This Comparison Matters
&lt;/h2&gt;

&lt;p&gt;Harvey AI is the most prominent legal AI company in the world. $5B+ valuation, 42% of the US top-100 law firms as clients, a partnership with OpenAI at the level of custom model training. Their approach is the industry benchmark.&lt;/p&gt;

&lt;p&gt;LEX AI is a Ukrainian legal AI platform built on a fundamentally different architecture: a foundation model (Claude Opus) + RAG over the complete corpus of the Unified State Register of Court Decisions (EDRSR) — 100+ million documents.&lt;/p&gt;

&lt;p&gt;Both systems solve the same problem: help a lawyer find relevant case law, analyze it, and apply it. But their architectural approaches are diametrically opposed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Harvey's Approach: Fine-tuned LLM + RAG
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;Harvey built a three-tier system:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Foundation Layer&lt;/strong&gt; — GPT-4/GPT-5 as the base model, deployed on Azure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Domain Fine-tuning Layer&lt;/strong&gt; — pre-training and post-training on 10 billion tokens of legal data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The complete US case law corpus (starting with Delaware, then expanding nationwide)&lt;/li&gt;
&lt;li&gt;Legal reasoning patterns&lt;/li&gt;
&lt;li&gt;Specialized terminology and citation formats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Client Customization Layer&lt;/strong&gt; — adaptation for specific firms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Firm document templates&lt;/li&gt;
&lt;li&gt;Style guides&lt;/li&gt;
&lt;li&gt;Internal precedents&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Search System
&lt;/h3&gt;

&lt;p&gt;Separately from the model, Harvey built a custom retrieval system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Voyage AI embeddings&lt;/strong&gt; (&lt;code&gt;voyage-law-2-harvey&lt;/code&gt;) — trained on 20B+ tokens of case law&lt;/li&gt;
&lt;li&gt;Custom legal embeddings achieved &lt;strong&gt;25% reduction in irrelevant results&lt;/strong&gt; compared to generic embeddings&lt;/li&gt;
&lt;li&gt;Hybrid search (vector + keyword)&lt;/li&gt;
&lt;li&gt;Legal-specific preprocessing and postprocessing&lt;/li&gt;
&lt;li&gt;Integration with LexisNexis for Shepardization (checking whether a precedent is still good law)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;97%&lt;/strong&gt; — the rate at which lawyers in blind testing chose the fine-tuned model's response over GPT-4&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0.2%&lt;/strong&gt; hallucination rate (vs. 17-33% for generic models)&lt;/li&gt;
&lt;li&gt;Every sentence backed by a citation to an actual case&lt;/li&gt;
&lt;li&gt;Multi-model orchestration: different models for drafting, research, and jurisdiction-specific queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cost of This Approach
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;$100M+ in investment (Series C from Sequoia, Google Ventures, et al.)&lt;/li&gt;
&lt;li&gt;Partnership with OpenAI at the level of custom model training&lt;/li&gt;
&lt;li&gt;Team of 200+ engineers&lt;/li&gt;
&lt;li&gt;Months of training and verification per iteration&lt;/li&gt;
&lt;li&gt;Lock-in to a single jurisdiction (US case law) with enormous effort required to scale&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  LEX's Approach: Opus + RAG
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;Our approach is fundamentally different — we &lt;strong&gt;don't train the model&lt;/strong&gt;, we build infrastructure around it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Foundation Model&lt;/strong&gt; — Claude Opus (as-is, no fine-tuning)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1M context window&lt;/li&gt;
&lt;li&gt;Strongest reasoning among publicly available models&lt;/li&gt;
&lt;li&gt;Native understanding of Ukrainian language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. RAG over the complete EDRSR corpus&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;100+ million&lt;/strong&gt; court decisions&lt;/li&gt;
&lt;li&gt;Full-text search (PostgreSQL GIN indexes with &lt;code&gt;'simple'&lt;/code&gt; language for Cyrillic)&lt;/li&gt;
&lt;li&gt;Semantic search (Qdrant + OpenAI embeddings)&lt;/li&gt;
&lt;li&gt;Semantic Sectionizer — splits documents into logical sections (articles, parts, clauses)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. MCP (Model Context Protocol)&lt;/strong&gt; — structured interface between model and data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;QueryPlanner classifies intent and selects search strategy&lt;/li&gt;
&lt;li&gt;DocumentService retrieves and caches documents&lt;/li&gt;
&lt;li&gt;LegislationService handles legislation (understands "Article 124 of the Constitution")&lt;/li&gt;
&lt;li&gt;EdsrFtsService — full-text search across the entire EDRSR&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Search System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lawyer's query
    │
    ▼
QueryPlanner (intent classification)
    │
    ├── Semantic Search (Qdrant)
    │   └── embeddings: text-embedding-ada-002
    │
    ├── Full-text Search (PostgreSQL)
    │   └── GIN indexes, 'simple' language config
    │
    └── Legislation Lookup (RADA API)
        └── intelligent sectioning
    │
    ▼
Context Assembly (relevant chunks)
    │
    ▼
Claude Opus (reasoning + generation)
    │
    ▼
Response with source citations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Full coverage of Ukrainian jurisdiction (100M+ decisions — the entire EDRSR)&lt;/li&gt;
&lt;li&gt;Citations with references to specific cases&lt;/li&gt;
&lt;li&gt;Understanding of martial law context, mobilization, new legislation&lt;/li&gt;
&lt;li&gt;Real-time corpus updates (new decisions enter the system automatically)&lt;/li&gt;
&lt;li&gt;Legislation, registries, and parliamentary data in a single interface&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cost of This Approach
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Team: 1 developer + Claude Code (735 commits in 25 days)&lt;/li&gt;
&lt;li&gt;Zero model training costs&lt;/li&gt;
&lt;li&gt;API costs: pay-per-use (Opus + embeddings)&lt;/li&gt;
&lt;li&gt;Infrastructure: 1 prod server, Docker Compose, PostgreSQL + Qdrant&lt;/li&gt;
&lt;li&gt;Time to production: weeks, not months&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Comparison: What Actually Differs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Where Legal Knowledge Lives
&lt;/h3&gt;

&lt;p&gt;| | Harvey (Fine-tuned) | LEX (Opus + RAG) |&lt;br&gt;
|—|—|—|&lt;br&gt;
| &lt;strong&gt;In model weights&lt;/strong&gt; | Yes — 10B tokens of case law baked into the model | No — the model is generic |&lt;br&gt;
| &lt;strong&gt;In retrieval&lt;/strong&gt; | Yes — custom embeddings + search | Yes — Qdrant + PostgreSQL FTS |&lt;br&gt;
| &lt;strong&gt;In context&lt;/strong&gt; | Partially — reasoning is already trained | Fully — everything via prompt |&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;fine-tuned model&lt;/strong&gt; "knows" jurisprudence at an intuitive level. It has seen millions of cases during training and developed patterns of legal reasoning. When a lawyer asks about &lt;em&gt;piercing the corporate veil&lt;/em&gt;, the model doesn't just search — it "remembers" the key precedents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opus + RAG&lt;/strong&gt; "knows" jurisprudence through context. The model receives relevant case fragments via RAG and applies its generic reasoning to analyze them. Opus doesn't "remember" case law — but it can read and analyze it better than any specialized model of smaller scale.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Hallucinations and Reliability
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Harvey&lt;/strong&gt; achieved a 0.2% hallucination rate through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fine-tuning on real cases (the model has "seen" them)&lt;/li&gt;
&lt;li&gt;Post-processing with citation verification&lt;/li&gt;
&lt;li&gt;Shepardization via LexisNexis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;LEX&lt;/strong&gt; minimizes hallucinations through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grounding — the model responds only based on provided context&lt;/li&gt;
&lt;li&gt;Explicit instructions — the system prompt requires source citations&lt;/li&gt;
&lt;li&gt;Verification — QueryPlanner checks that real documents were found&lt;/li&gt;
&lt;li&gt;Constitutional constraints — the model is explicitly instructed not to draw conclusions beyond the provided data&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  3. Updatability
&lt;/h3&gt;

&lt;p&gt;This is &lt;strong&gt;the biggest advantage of the RAG approach&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A fine-tuned model is a snapshot of the corpus at the time of training. A new Supreme Court decision handed down yesterday doesn't exist for the model until the next fine-tuning cycle (weeks to months).&lt;/p&gt;

&lt;p&gt;A RAG system updates in real time. A decision entered into EDRSR this morning is available for search by tonight. For a jurisdiction under martial law, where new legislation appears every week, this is critical.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Scaling to New Jurisdictions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Harvey&lt;/strong&gt; scales with difficulty: each new jurisdiction means a new cycle of data collection, training, and verification. US case law ≠ EU case law ≠ Ukrainian judicial practice. Reasoning patterns differ. Legal terminology differs. The hierarchy of sources differs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAG&lt;/strong&gt; scales easily: connect a new document corpus, configure embeddings, update the search pipeline. We've already connected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EDRSR (100M+ decisions)&lt;/li&gt;
&lt;li&gt;Legislation via RADA API&lt;/li&gt;
&lt;li&gt;OpenReyestr (business entity registry)&lt;/li&gt;
&lt;li&gt;Parliamentary data (deputies, bills, votes)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5. Reasoning Customization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Fine-tuning&lt;/strong&gt; lets you embed legal reasoning into the model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The model "understands" legal argumentation&lt;/li&gt;
&lt;li&gt;It can independently build chains of precedents&lt;/li&gt;
&lt;li&gt;Less dependent on search quality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prompt engineering + RAG&lt;/strong&gt; lets you control reasoning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transparent logic (you can read the prompt)&lt;/li&gt;
&lt;li&gt;Easy to change strategy (update the prompt, not retrain the model)&lt;/li&gt;
&lt;li&gt;Constitutional constraints via RLHF principles in the prompt&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Why We Chose RAG Over Fine-tuning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Economic Reality
&lt;/h3&gt;

&lt;p&gt;Fine-tuning a legal model is a $10M+ project even for a minimum viable product. Harvey raised $100M+ and has a team of 200+ people. For the Ukrainian market, where the entire legal tech TAM is a fraction of what a single Am Law 100 firm earns, such investment makes no economic sense.&lt;/p&gt;

&lt;p&gt;The RAG approach let us ship to production with a one-person team and a budget for API calls.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Iteration Speed
&lt;/h3&gt;

&lt;p&gt;Fine-tuning cycle: collect data → clean → train → evaluate → deploy. Weeks to months.&lt;/p&gt;

&lt;p&gt;RAG cycle: update the prompt → deploy. Minutes.&lt;/p&gt;

&lt;p&gt;When the Grand Chamber of the Supreme Court adopts a new legal position that changes interpretation across an entire field — a RAG system adapts in hours, not months.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Foundation Model Quality
&lt;/h3&gt;

&lt;p&gt;In 2023, when Harvey started fine-tuning, GPT-4 was the best model available, and its reasoning on legal tasks was "good but not sufficient." Fine-tuning made sense.&lt;/p&gt;

&lt;p&gt;In 2026, Claude Opus has a 1M context window and reasoning that surpasses specialized models. The gap between "generic Opus + the right context" and "fine-tuned GPT + retrieval" has narrowed significantly. Foundation models have caught up with fine-tuned specialized models on reasoning quality — and continue improving with every release.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Ukrainian Jurisdiction
&lt;/h3&gt;

&lt;p&gt;Ukrainian law is not common law. There is no stare decisis (binding precedent). Case law is advisory in nature. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Precise precedent citation is less critical than in US law&lt;/li&gt;
&lt;li&gt;Knowing current legislation + Supreme Court legal positions matters more&lt;/li&gt;
&lt;li&gt;The corpus changes constantly (martial law, new statutes every week)&lt;/li&gt;
&lt;li&gt;RAG with real-time updates is a perfect fit for this context&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5. Transparency and Control
&lt;/h3&gt;

&lt;p&gt;A fine-tuned model is a black box. You don't know why it generated a particular response. Which weights fired? Which cases did it "recall"?&lt;/p&gt;

&lt;p&gt;RAG is transparent. You can see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which documents were found (search results)&lt;/li&gt;
&lt;li&gt;What entered the context (retrieved chunks)&lt;/li&gt;
&lt;li&gt;What the model received as input (prompt)&lt;/li&gt;
&lt;li&gt;How it arrived at the answer (reasoning in output)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a legal system where every response can affect a person's fate, transparency is not a nice-to-have — it's a requirement.&lt;/p&gt;


&lt;h2&gt;
  
  
  Where Fine-tuning Still Wins
&lt;/h2&gt;

&lt;p&gt;Honesty demands acknowledgment: there are tasks where Harvey's fine-tuned model is objectively better:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Legal reasoning without context&lt;/strong&gt; — when a lawyer asks a general legal question without a specific case, a fine-tuned model gives a better answer because it "knows" jurisprudence. RAG depends on search quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Chains of precedent&lt;/strong&gt; — a fine-tuned model can independently build an argument through a series of related precedents because it "saw" those connections during training. RAG may miss a precedent if the search didn't find it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Legal document stylistics&lt;/strong&gt; — a model trained on millions of legal texts better mimics the style of legal writing. A generic model requires more prompt engineering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Scale&lt;/strong&gt; — when processing hundreds of contracts at once (due diligence), a fine-tuned model is more efficient because it doesn't need retrieval at every step.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Future: Convergence of Approaches
&lt;/h2&gt;

&lt;p&gt;The boundary between RAG and fine-tuning is blurring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Harvey&lt;/strong&gt; is building RAG on top of its fine-tuned model (their case law search is RAG)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;We&lt;/strong&gt; are exploring domain-specific embeddings (an analogue of voyage-law, but for Ukrainian jurisprudence)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Both&lt;/strong&gt; are moving toward agentic workflows — multi-step systems where the model decides what to search for&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The truth is that "fine-tuning vs RAG" is a false dichotomy. Harvey uses &lt;strong&gt;both&lt;/strong&gt; fine-tuning &lt;strong&gt;and&lt;/strong&gt; RAG. We use RAG and will be adding elements of domain adaptation (custom embeddings, constitutional RLHF).&lt;/p&gt;

&lt;p&gt;The ultimate architecture for legal AI is a spectrum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pure RAG ←──────────────────────────────────→ Pure Fine-tuning
  │                                                    │
  LEX (Opus + EDRSR)            Harvey (custom GPT + RAG)
  │                                                    │
  Cheap, fast,                          Expensive, slow,
  transparent, updatable                deep, precise
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The optimum for each jurisdiction, team, and budget lies somewhere between these poles.&lt;/p&gt;




&lt;h2&gt;
  
  
  LEX + Google + DeepSeek v3: Fine-tuning for Ukrainian Jurisdiction
&lt;/h2&gt;

&lt;p&gt;We're not just comparing approaches — we're moving toward fine-tuning ourselves. LEX AI is working with Google on a task analogous to Harvey + OpenAI, but for Ukrainian law.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why DeepSeek v3
&lt;/h3&gt;

&lt;p&gt;DeepSeek v3 is an open-weight model with a Mixture-of-Experts architecture (671B parameters, 37B active per query). For fine-tuning on Ukrainian jurisdiction, it's the ideal foundation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Open weights&lt;/strong&gt; — full control over training, no API provider lock-in&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MoE efficiency&lt;/strong&gt; — inference cost is several times lower than dense models of comparable scale&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strong multilingual capabilities&lt;/strong&gt; — quality Cyrillic and Ukrainian language support out of the box&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Legal reasoning&lt;/strong&gt; — baseline reasoning on par with GPT-4o, providing a high starting point for domain adaptation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What We're Training
&lt;/h3&gt;

&lt;p&gt;The fine-tuning corpus: 100M+ court decisions from EDRSR, Ukrainian legislation, Supreme Court legal positions. This is the same dataset that currently lives in our RAG system — but instead of feeding it into context every time, we're embedding legal knowledge directly into the model weights.&lt;/p&gt;

&lt;p&gt;Key directions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pre-training&lt;/strong&gt; on the full EDRSR corpus — the model will "see" all of Ukraine's case law&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Post-training&lt;/strong&gt; on "lawyer query → quality response" pairs with legal annotators&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constitutional RLHF&lt;/strong&gt; — reward signal based on the Constitution of Ukraine (described in our &lt;a href="https://legal.org.ua/blog/constitutional-rlhf" rel="noopener noreferrer"&gt;previous article&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom embeddings&lt;/strong&gt; for Ukrainian legal text (analogous to Harvey's voyage-law-2-harvey)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Google's Role
&lt;/h3&gt;

&lt;p&gt;Google Cloud provides training infrastructure: TPU pods for pre-training on hundreds of millions of documents, distributed training tools, and expertise in optimizing MoE models. The partnership enables us to do work that previously required a team of 200+ engineers.&lt;/p&gt;

&lt;h3&gt;
  
  
  How This Changes LEX
&lt;/h3&gt;

&lt;p&gt;The final LEX architecture will be hybrid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lawyer's query
    │
    ▼
Fine-tuned DeepSeek v3 (legal reasoning in weights)
    +
RAG (current decisions, new legislation)
    +
Constitutional RLHF (ethical constraints)
    │
    ▼
Response with deep legal reasoning
+ current sources
+ constitutional guarantees
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what Harvey built for US common law at $100M+ with OpenAI. We're building the same for Ukrainian jurisdiction with Google and DeepSeek — on open data, with an open model, for a market where access to justice is not a business metric but a matter of survival.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;| Criterion | Harvey (Fine-tuned + RAG) | LEX (Opus + RAG) |&lt;br&gt;
|———-|—————————|——————-|&lt;br&gt;
| Reasoning quality | Embedded legal reasoning | Generic reasoning + context |&lt;br&gt;
| Hallucinations | 0.2% (verified) | Low (grounded RAG) |&lt;br&gt;
| Updatability | Weeks to months | Hours |&lt;br&gt;
| New jurisdictions | New training cycle | New document corpus |&lt;br&gt;
| Launch cost | 10M+ | 10K |&lt;br&gt;
| Transparency | Black box | Full transparency |&lt;br&gt;
| Time to production | Months | Weeks |&lt;br&gt;
| Reasoning customization | Via training (slow) | Via prompt (fast) |&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Ukrainian legal tech in 2026, RAG + Opus is the right choice.&lt;/strong&gt; Not because fine-tuning is bad. But because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Foundation models have become smart enough for RAG to perform on par with fine-tuned specialized models&lt;/li&gt;
&lt;li&gt;Ukrainian jurisdiction demands real-time updates that fine-tuning cannot provide&lt;/li&gt;
&lt;li&gt;The economics of the Ukrainian market don't allow spending $100M on model training&lt;/li&gt;
&lt;li&gt;RAG transparency is critical for a legal system where an error is not a bug but a human rights violation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Harvey took the right path for their context: US common law, 500B market, 100M in investment. We're taking the right path for ours: Ukrainian law, martial law, a team of one person and an AI partner.&lt;/p&gt;

&lt;p&gt;Different realities — different architectures. But the goal is one: to make justice more accessible.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Sources:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://openai.com/index/harvey/" rel="noopener noreferrer"&gt;Customizing models for legal professionals — OpenAI&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://newsletter.himanshuramchandani.co/p/harvey-ai-5b-legal-fine-tuning-case-study" rel="noopener noreferrer"&gt;Harvey AI's $5B Legal Fine-Tuning Case Study&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://medium.com/@takafumi.endo/how-harvey-built-trust-in-legal-ai-a-case-study-for-builders-786cc23c3b6d" rel="noopener noreferrer"&gt;How Harvey Built Trust in Legal AI — Medium&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://www.microsoft.com/en/customers/story/19750-harvey-azure-open-ai-service" rel="noopener noreferrer"&gt;Harvey makes lawyers more efficient with Azure AI — Microsoft&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Registration: &lt;a href="https://legal.org.ua" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://legal.org.ua/blog/opus-rag-vs-finetuned-llm" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>finetuning</category>
      <category>rag</category>
      <category>claudeopus</category>
    </item>
    <item>
      <title>How We Vectorize 33.7M Ukrainian Court Decisions via Voyage AI</title>
      <dc:creator>overthelex</dc:creator>
      <pubDate>Fri, 03 Jul 2026 21:35:48 +0000</pubDate>
      <link>https://dev.to/overthelex/how-we-vectorize-337m-ukrainian-court-decisions-via-voyage-ai-3hlc</link>
      <guid>https://dev.to/overthelex/how-we-vectorize-337m-ukrainian-court-decisions-via-voyage-ai-3hlc</guid>
      <description>&lt;p&gt;&lt;em&gt;EDRSR — the Unified State Register of Court Decisions — is effectively all of Ukraine's judicial practice in open access. Today Qdrant holds **44M+ vectors&lt;/em&gt;&lt;em&gt;: criminal (19M), civil (14.3M), commercial (5.1M), misdemeanors (5.6M). Vectorization of civil cases (CPC, justice_kind=1) — the largest cohort at 33.7M documents — runs on a dedicated EC2 instance (r6a.xlarge, 32 GB RAM, 2 TB gp3). Here's what's under the hood: models, pipeline, cost, rakes, and current status.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Vectorize Courts
&lt;/h2&gt;

&lt;p&gt;When a lawyer searches "is there case law on recovering bank prepayment fees" — they don't want to open 40 decisions and read them through. They want the system to surface the top 5 most relevant ones, pull out key paragraphs, and show how courts reasoned. Full-text search (FTS) over keywords doesn't give that — it returns every document containing the word "fee", and there are thousands.&lt;/p&gt;

&lt;p&gt;For this semantic task you need vector representations of text. The model turns a paragraph from a decision into a point in a 1024-dimensional space; semantically similar paragraphs sit near each other. A kNN search in Qdrant returns the top K nearest, and an LLM composes the answer from exactly those relevant fragments.&lt;/p&gt;

&lt;p&gt;The only problem: the register is big. Very big.&lt;/p&gt;




&lt;h2&gt;
  
  
  Scale
&lt;/h2&gt;

&lt;p&gt;Our prod database holds full texts of decisions starting from 2006. Breakdown by procedural type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Civil (CPC)&lt;/strong&gt; — 33.7M documents. The largest category. Consumer, housing, labor, family.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Criminal (CrPC)&lt;/strong&gt; — 12M+&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Administrative (CAS)&lt;/strong&gt; — 14M+&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commercial (CC)&lt;/strong&gt; — 6M+&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Misdemeanors (CUaP)&lt;/strong&gt; — 6M+&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Qdrant collection &lt;code&gt;edrsr_decisions&lt;/code&gt; on a dedicated EC2 currently holds &lt;strong&gt;44M+ vectors&lt;/strong&gt; (122 segments, on_disk=true):&lt;/p&gt;

&lt;p&gt;| Proceeding type | justice_kind | Vectors |&lt;br&gt;
|—|—|—|&lt;br&gt;
| Criminal (CrPC) | 2 | 19,036,347 |&lt;br&gt;
| Civil (CPC) | 1 | 14,328,427 |&lt;br&gt;
| Misdemeanors (CUaP) | 5 | 5,579,432 |&lt;br&gt;
| Commercial (CC) | 3 | 5,098,662 |&lt;br&gt;
| &lt;strong&gt;Total&lt;/strong&gt; | | &lt;strong&gt;44,042,868&lt;/strong&gt; |&lt;/p&gt;

&lt;p&gt;Civil cases processed: 14.3M out of 33.7M — that's 42%. After CPC completes there will be roughly &lt;strong&gt;63M+ vectors&lt;/strong&gt; in a single collection.&lt;/p&gt;

&lt;p&gt;For scale: a typical RAG project holds 100K — 1M vectors. Ours is two orders of magnitude bigger.&lt;/p&gt;




&lt;h2&gt;
  
  
  Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Embedding model.&lt;/strong&gt; &lt;code&gt;voyage-3.5&lt;/code&gt; from Voyage AI. 1024-dimensional output, 6 cents per million tokens. We tested Voyage 3 Large and OpenAI text-embedding-3-large, but the quality gain on legal text didn't justify the cost difference (Voyage 3 Large is 3x more expensive). We already had an index on 3.5 for prior jurisdictions, so we stay on it for compatibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector DB.&lt;/strong&gt; Qdrant v1.17, self-hosted in Docker on a dedicated EC2 (r6a.xlarge — 4 CPU, 32 GB RAM, 2 TB gp3). Collection &lt;code&gt;edrsr_decisions&lt;/code&gt; with HNSW index, on_disk=true for both vectors and payload. Payload carries doc_id, court_code, judge, justice_kind, adjudication_date, plus chunk_index/total_chunks and chunk text. Dedicated instance because 44M+ points with HNSW were killing RAM on prod and blocking the chat service (OOM kills during segment optimization).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source-of-truth.&lt;/strong&gt; PostgreSQL 15, partitioned tables: RANGE by adjudication_date, LIST by adj_year. Full texts live in &lt;code&gt;edrsr_fulltext&lt;/code&gt;, metadata in &lt;code&gt;edrsr_documents&lt;/code&gt;. A JOIN across all partitions is 30M+ rows, so the pipeline walks year by year.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Runtime.&lt;/strong&gt; Python 3.11, asyncio, aiohttp. No frameworks — direct HTTP to Voyage and Qdrant. 440 lines of code, one file.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chunking
&lt;/h2&gt;

&lt;p&gt;Court decisions are long. Average CPC ruling is 8–12K characters, longest reach 200K. Voyage accepts up to 32K tokens per input, but quality falls off on long contexts, and one long vector is poor for retrieval — the LLM can't tell which paragraph is relevant.&lt;/p&gt;

&lt;p&gt;So we chunk: up to 2048 characters per chunk, 50-word overlap between neighbors. We split on paragraph boundaries to keep semantic coherence. On average one decision yields 2.7 chunks.&lt;/p&gt;

&lt;p&gt;Each chunk in Qdrant gets a composite ID (doc_id × 1000 + chunk_index) — no collisions, and a single payload filter query pulls all chunks of a specific decision.&lt;/p&gt;




&lt;h2&gt;
  
  
  Concurrency and Throttling
&lt;/h2&gt;

&lt;p&gt;Voyage has a rate limit — 2000 RPM per key for voyage-3.5. We have two keys and round-robin between them, giving a theoretical 4000 RPM ceiling. In practice we hold concurrency 50 and get a steady &lt;strong&gt;63 documents per second&lt;/strong&gt;. That's ~170 requests per minute per key — comfortably under the rate limit.&lt;/p&gt;

&lt;p&gt;We tried concurrency 70 — first two million were fine, then the process stalled on the GIL (13% CPU, no progress, no errors — just stuck on a thread lock). Dropped to 50 — ran smooth, no deadlocks, no 429s.&lt;/p&gt;

&lt;p&gt;Every 100 documents triggers a batch to Voyage (batch_size=500 chunks/request), gets embeddings, composes Qdrant points, and does one upsert. On Voyage error (429, network) — exponential backoff with jitter, max 5 retries. On Qdrant error — retry the same batch.&lt;/p&gt;




&lt;h2&gt;
  
  
  Checkpoint and Resume
&lt;/h2&gt;

&lt;p&gt;At 33.7M documents any failure — network, OOM, container crash — means hours of lost work. So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every 1000 processed documents the pipeline writes a checkpoint JSON: &lt;code&gt;{last_doc_id, processed_docs, total_chunks, total_tokens, timestamp}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;On startup — reads checkpoint, resumes with &lt;code&gt;WHERE doc_id &amp;gt; last_doc_id&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;All metrics (docs, chunks, tokens, cost) accumulate across checkpoints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This has saved us twice. First time — when postgres-prod ran out of memory (more on that below). Second time — when Qdrant restarted and lost its API key from env. Both times we just restarted from the same checkpoint with no duplicated work.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prod Incident: Postgres OOM
&lt;/h2&gt;

&lt;p&gt;At 2.86M documents postgres-prod fell into recovery mode. Root cause: config mismatch — &lt;code&gt;shared_buffers=16GB&lt;/code&gt;, container memory limit 12G. PG tried to allocate more than it had; OOM killer killed the process.&lt;/p&gt;

&lt;p&gt;Fix in PR #1453: &lt;code&gt;mem_limit: 24G&lt;/code&gt;, &lt;code&gt;shm_size: 16g&lt;/code&gt;. After restarting the container with the new limits PG came up in 4 seconds and stopped falling over. The episode highlighted an infra pattern: postgresql.conf parameters (shared_buffers, work_mem, maintenance_work_mem) must align with container limits. Otherwise the system runs fine until the first load spike, then falls into recovery.&lt;/p&gt;

&lt;p&gt;We also bumped swap on the local dev machine from 8GB to 24GB — heavy Voyage API traffic generates a lot of temporary objects in the Python process memory, especially while Qdrant is rebuilding its index in the background.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cost
&lt;/h2&gt;

&lt;p&gt;One civil document averages 2.7 chunks × 850 tokens = 2300 tokens. At voyage-3.5 pricing of 6 cents per million tokens, one document costs &lt;strong&gt;0.014 cents&lt;/strong&gt; — roughly 138 microdollars.&lt;/p&gt;

&lt;p&gt;As of today, 14.3M documents out of 33.7M are processed — that's 42% of the cohort. We've spent approximately &lt;strong&gt;1,980 dollars&lt;/strong&gt; on the Voyage API and about 63 hours of pipeline runtime. Remaining 19.4M documents cost roughly &lt;strong&gt;2,680 dollars&lt;/strong&gt; and &lt;strong&gt;85 hours&lt;/strong&gt; (3.5 days of continuous processing). Total cost of the full CPC cohort vectorization — around &lt;strong&gt;4,660 dollars&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Plus the EC2 r6a.xlarge for Qdrant — ~\0.20/hr (on-demand), roughly \145/month. Cheaper than OOM incidents on prod.&lt;/p&gt;

&lt;p&gt;For scale: the same budget on OpenAI text-embedding-3-large would get us only a quarter of the volume. Voyage wins specifically at this scale.&lt;/p&gt;




&lt;h2&gt;
  
  
  What It Gives Users
&lt;/h2&gt;

&lt;p&gt;Semantic search already works across 44M+ vectors today. Once the civil cohort is fully indexed, the collection will hold 63M+ chunks. A lawyer types a natural-language query — "case law on voiding a sale contract due to seller incapacity" — and the system returns the most relevant decisions from the right jurisdiction, with key paragraph extracts and EDRSR links.&lt;/p&gt;

&lt;p&gt;That's a different class of product compared to FTS. FTS finds documents where a phrase appears. Semantic search finds documents where your situation is being discussed — even when the court used entirely different words.&lt;/p&gt;




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

&lt;ul&gt;
&lt;li&gt;33.7M civil EDRSR cases → Voyage voyage-3.5 → Qdrant (14.3M / 33.7M = 42% done)&lt;/li&gt;
&lt;li&gt;44M+ vectors in Qdrant on a dedicated EC2 (r6a.xlarge, 32 GB RAM)&lt;/li&gt;
&lt;li&gt;63 docs/sec, concurrency 50, two API keys round-robin&lt;/li&gt;
&lt;li&gt;~4,660 dollars total cost for full CPC vectorization + ~\$145/mo EC2&lt;/li&gt;
&lt;li&gt;Checkpoint/resume JSON, survived two incidents already&lt;/li&gt;
&lt;li&gt;After completion — 63M+ vectors in one collection, unified semantic search over all Ukrainian judicial practice&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Runs in tmux on a dedicated EC2, checkpoint fires every 1000 docs. Snapshot sync to prod Qdrant every 6 hours via cron. Boring reliable engineering, not heroics.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://legal.org.ua/blog/edrsr-vectorization-voyage" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>voyageai</category>
      <category>qdrant</category>
      <category>rag</category>
      <category>vectorsearch</category>
    </item>
    <item>
      <title>2 TB of Ukrainian Law + DeepSeek V3 860B on GCP: What We'd Get</title>
      <dc:creator>overthelex</dc:creator>
      <pubDate>Fri, 03 Jul 2026 21:35:47 +0000</pubDate>
      <link>https://dev.to/overthelex/2-tb-of-ukrainian-law-deepseek-v3-860b-on-gcp-what-wed-get-2jj5</link>
      <guid>https://dev.to/overthelex/2-tb-of-ukrainian-law-deepseek-v3-860b-on-gcp-what-wed-get-2jj5</guid>
      <description>&lt;p&gt;&lt;em&gt;In production we have ~1.5 TB of full-text court decisions and their vector embeddings, plus another ~550 GB of other legal data: registries, legislation, business entities, a Spanish case law corpus, EU-Lex. If we take this corpus and train an MoE model the size of DeepSeek V3, scaled to 860B parameters, on GCP — what comes out? We break down the dataset, architecture, compute cost, and the properties such a model would have on Ukrainian law.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What's in the Dataset
&lt;/h2&gt;

&lt;p&gt;The entire corpus is what's already running in SecondLayer's production. No extra scrapes, no Common Crawl, no noise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDRSR — the dataset core, ~1.5 TB.&lt;/strong&gt; The Unified State Register of Court Decisions of Ukraine. 96.2 million full-text decisions (1,079 GB in PostgreSQL TOAST), 471 GB of vectors in Qdrant (voyage-3.5, 1024-dim), 28 GB of metadata (court, judge, date, case category, proceeding type, statute code). Breakdown by jurisdiction: civil 33.7M, administrative 14M+, criminal 12M+, commercial 6M+, misdemeanors 6M+. Largest annual cohort — 2024 (115 GB of TOAST text).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OpenReyestr — 43 GB.&lt;/strong&gt; Ukrainian public registries: 16.7M legal entities (EDR), ownership structures (beneficiaries, shareholders), debtors (State Enforcement Service), NAIS registries. This is the foundation for SneakyPiper — our due-diligence platform — but here it serves as raw corpus for the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Legislation — ~40 GB.&lt;/strong&gt; The Constitution, major codes (Civil, Criminal, Criminal Procedure, Civil Procedure, Commercial Procedure, Administrative Procedure, Labor, Tax, Customs), laws, and secondary legislation. All structurally annotated: articles, parts, clauses, revision dates with effective-date tracking. This isn't flat text: we know that Article 124 of the Constitution took effect on a specific date, carries particular references, and is cited in a precise number of decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supreme Court review practices + lu_court_decisions — ~25 GB.&lt;/strong&gt; SC plenary decisions, practice overviews, Grand Chamber rulings. This is the most valuable slice — the legal positions that lower courts follow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spanish open data — ~50 GB.&lt;/strong&gt; BOE (official gazette), AEAT (tax rulings), Tribunal Constitucional (Constitutional Court of Spain), BORME (companies register, section C), CENDOJ (criminal law), Fiscalia, Consejo de Estado, EU-Lex ES. A multilingual bonus: the model gets European legal context in its second working language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SecondLayer opendata shards — ~30 GB.&lt;/strong&gt; NIPO (patents/trademarks), DPA data, spending.gov.ua, parliamentary open data (Rada: deputies, bills, votes, legislation texts from zakon.rada.gov.ua), CourtSchedule, CourtExperts.&lt;/p&gt;

&lt;p&gt;Total — roughly &lt;strong&gt;2 TB of raw text&lt;/strong&gt;. After deduplication, boilerplate filtering (standard decision headers, "enters into force upon" clauses, signatures), OCR fixes, and normalization, we expect &lt;strong&gt;~800–1,000 GB of clean tokenized corpus&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In tokens (SentencePiece BPE trained on Ukrainian): approximately &lt;strong&gt;280–330 billion tokens&lt;/strong&gt;. For comparison, the original DeepSeek V3 was trained on 14.8T tokens, mostly English. Our corpus is 50x smaller, but it's focused, domain-specific, structured, and nearly unique: Common Crawl contains orders of magnitude less Ukrainian legal text.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why DeepSeek V3 and What 860B Means
&lt;/h2&gt;

&lt;p&gt;DeepSeek V3 is a Mixture-of-Experts (MoE) architecture from DeepSeek: 671B total parameters, 37B active per token. Hot inference is cheaper than dense models of the same scale because only a fraction of experts activates on each forward pass. For our use case — tens of millions of inference calls per month in production — that's critical.&lt;/p&gt;

&lt;p&gt;860B is a hypothetical scale: we take the V3 topology and expand it by roughly 1.28x. Specifically: keep 61 layers, increase routed experts from 256 to ~330, retain top-8 routing + 1 shared expert, sigmoid router-gate, balance-loss-free training (as in V3-R1). Total parameters ~860B, active per token ~47B. Still inference-friendly.&lt;/p&gt;

&lt;p&gt;Why this particular expansion? First, for a narrow-domain corpus more experts mean better specialized routing: one expert for "filing a claim under CPC," another for "tax rulings," a third for "Supreme Court reasoning in cassation orders." Second, 860B leaves headroom capacity for multilingual coverage (Ukrainian + Spanish + Russian + English) without domain degradation. Third, MoE on TPU v5p scales very cleanly — unlike dense models of the same parameter count.&lt;/p&gt;

&lt;p&gt;We'd use the architectural features from the original V3: Multi-Head Latent Attention (MLA) instead of GQA — this reduces KV-cache by roughly 9x, enabling long context (256K tokens) without petabytes of RAM. Multi-Token Prediction (MTP) head as an auxiliary loss during training — improves sampling and unlocks speculative decoding at inference.&lt;/p&gt;




&lt;h2&gt;
  
  
  Training on GCP: Config and Cost
&lt;/h2&gt;

&lt;p&gt;GCP has TPU v5p pods — the best platform for MoE training, better than H100 clusters in per-chip memory (95 GB HBM3 vs 80 GB) and inter-chip interconnect bandwidth (ICI). For an 860B MoE with 280B tokens, here's the estimate.&lt;/p&gt;

&lt;p&gt;Minimum production config: &lt;strong&gt;v5p-2048&lt;/strong&gt; (2,048 chips, 512 hosts). On this pod, one epoch over 280B tokens completes in roughly &lt;strong&gt;3–4 days&lt;/strong&gt;. Full pre-training at 3 epochs — 9–12 days of compute time. Hyperparameter search on smaller models (70B/200B variants) — another 5–7 days on v5p-512.&lt;/p&gt;

&lt;p&gt;v5p pricing is approximately \4.20 per chip-hour on-demand, \2.50 on a 3-year commitment. At 12 days on v5p-2048, the pre-training run alone comes to &lt;strong&gt;\2.5–4.2M&lt;/strong&gt;. Add another &lt;strong&gt;\200–500K&lt;/strong&gt; for experiments + supervised fine-tuning + DPO/RLHF on a separate judicial instruction dataset. Checkpoint storage in GCS runs ~100–200 GB per checkpoint; over a week you'll accumulate several TB.&lt;/p&gt;

&lt;p&gt;Alternative — A3 Ultra (H100 Mega) on GCP. 768 H100s (48 a3-megagpu-8g instances) are roughly equivalent to v5p-1024 in throughput, but worse for MoE efficiency due to NVLink vs ICI. Price is comparable but slightly worse. So — v5p.&lt;/p&gt;

&lt;p&gt;Data: the source corpus lives in GCS as multi-stream TFRecord chunks (256 MB each); tokenization happens on-the-fly in the data loader via the JAX/Flax/Paxml stack. This is standard for TPU training, unlike PyTorch/FSDP on H100. Pipeline: TPU chip -&amp;gt; HBM -&amp;gt; TensorCore, no round-trip to host DRAM on the hot path.&lt;/p&gt;




&lt;h2&gt;
  
  
  Expected Model Properties
&lt;/h2&gt;

&lt;p&gt;What do we get by running this corpus through this much compute?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First: native Ukrainian legal reasoning.&lt;/strong&gt; As of today, no frontier model truly knows Ukrainian law — not GPT-4o, not Claude Opus 4.7, not Gemini 2.5. They hallucinate Civil Code articles, confuse pre- and post-2022 code revisions, and can't distinguish administrative from civil proceedings. Our model would ingest 280B tokens of Ukrainian legal text — hundreds of times more than any frontier model's pre-training dataset contains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second: fine-grained citation.&lt;/strong&gt; Because the corpus is structured (each chunk carries its doc_id, category, date, article reference), the model learns not just "there's an article in the code somewhere..." but rather "pursuant to Article 611 of the Civil Code of Ukraine (revision of 17.06.2020), in cases concerning recovery of penalties..." This isn't retrieval-augmented; it's a property the model develops in its activations from the pre-training signal itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third: reasoning over precedents.&lt;/strong&gt; With 96M decisions carrying full metadata (cassation/appellate/first instance, judicial district, reporting judge, date), the model learns how lower courts apply Supreme Court legal positions, how practice evolves over time, and where splits exist between chambers. This is no longer just "information synthesis" — it's legal reasoning trained on real decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fourth: graph logic for beneficiaries and connections.&lt;/strong&gt; 16.7M entities in OpenReyestr + SneakyPiper relationship graphs provide raw material for the model to internally build a knowledge graph of the Ukrainian business world. With proper formatting of training samples (triples like "company–beneficiary–ownership %" as text), the model learns to generate hypotheses such as "if person X is the ultimate beneficiary of 3 companies sharing the same attorney, it's worth checking connections with the offshore registry."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fifth: multilingual bridge function.&lt;/strong&gt; The Spanish corpus (~50 GB) + EU-Lex ES + Ukrainian legislative texts creates a mapping between EU and Ukrainian criminal-law concepts — useful for extradition matters, MLAT requests, and cases with a foreign element. This isn't professional translation; it's a shared reasoning space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sixth: radically lower hallucination on domain queries.&lt;/strong&gt; We expect that on a test set measuring "correct answer with article/precedent citation" we'd achieve 85–92% accuracy — compared to 40–55% for general-purpose frontier models. This is an experimental estimate, but on small variants (7B/70B fine-tuned on a corpus subset) we already see these numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the model would NOT do better than frontier models:&lt;/strong&gt; general reasoning outside jurisprudence, math, code, creative writing in non-legal genres, niche English-language context. For those, production retains multi-model orchestration: lightweight queries go to a quick model, complex legal queries to our own, general queries to Claude/GPT.&lt;/p&gt;




&lt;h2&gt;
  
  
  What This Means for SecondLayer in Production
&lt;/h2&gt;

&lt;p&gt;Right now we run multi-agent orchestration: intent classifier, retrieval planner, embedding via Voyage, Qdrant search, context building, query to GPT-4o/Claude, post-processing. This is expensive (\$0.01–0.05 per query), slow (3–8 seconds per response), and dependent on OpenAI/Anthropic not cutting off Ukraine tomorrow.&lt;/p&gt;

&lt;p&gt;With our own model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inference at half the cost of OpenAI at comparable domain quality, because we don't pay for tokens that went into general pre-training&lt;/li&gt;
&lt;li&gt;1–2 second latency instead of 3–8, because the query no longer travels trans-Atlantic through a retrieval pipeline&lt;/li&gt;
&lt;li&gt;Self-hosted on EU servers, GDPR-compliant, with no dependency on an external provider&lt;/li&gt;
&lt;li&gt;Ability to fine-tune for new task types (tax, labor, attorney ethics) without paying for retraining frontier models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key insight: &lt;strong&gt;what we currently have on disk isn't just "data." It's the world's largest domain corpus for training a Ukrainian legal AI model.&lt;/strong&gt; No foreign player has this corpus and won't have it for years. No open dataset (Pile, RedPajama, Dolma, FineWeb) comes close to containing this much judicial practice from any jurisdiction.&lt;/p&gt;

&lt;p&gt;The question isn't whether it's worth doing. The question is when and with whom. \$3–5M for pre-training is seed-to-Series-A territory — this is done with a single strategic investor who sees the Ukr-legal-AI market as a distinct category. We already have the pipeline, the corpus, and the team that keeps prod running on 96M decisions without downtime.&lt;/p&gt;

&lt;p&gt;Next — compute.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Author: Volodymyr Ovcharov. legal.org.ua&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://legal.org.ua/blog/deepseek-v3-860b-ukrainian-law" rel="noopener noreferrer"&gt;legal.org.ua&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>deepseekv3</category>
      <category>moe</category>
      <category>tpuv5p</category>
      <category>gcp</category>
    </item>
  </channel>
</rss>
