<?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: Darkstalker</title>
    <description>The latest articles on DEV Community by Darkstalker (@darkstalker).</description>
    <link>https://dev.to/darkstalker</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%2F2688594%2Fc8f35020-7f39-4f59-8696-ada57b5fba6a.jpg</url>
      <title>DEV Community: Darkstalker</title>
      <link>https://dev.to/darkstalker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darkstalker"/>
    <language>en</language>
    <item>
      <title>Building Nexa Research Agent: An AI-Powered Deep Research Platform from Scratch</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 11 Aug 2025 20:12:08 +0000</pubDate>
      <link>https://dev.to/darkstalker/building-nexa-research-agent-an-ai-powered-deep-research-platform-from-scratch-3c3</link>
      <guid>https://dev.to/darkstalker/building-nexa-research-agent-an-ai-powered-deep-research-platform-from-scratch-3c3</guid>
      <description>&lt;p&gt;If you've been following the explosion of research agents sparked by open-source powerhouses like DeepSeek R1  you'll love this. Today, I'm sharing how I built &lt;strong&gt;Nexa Research Agent&lt;/strong&gt; from scratch: an open-source platform that transforms any topic into a comprehensive, sourced research report in minutes. It's powered by advanced LLMs, neural search, and a scalable backend.&lt;/p&gt;

&lt;p&gt;We'll cover why this matters in 2025's AI landscape, the step-by-step build process, key tech decisions, and code snippets straight from the repo. By the end, you'll have a blueprint to spin this up yourself. Let's jump in!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Build a Deep Research Agent? The Big Picture
&lt;/h2&gt;

&lt;p&gt;with LLMs like DeepSeek R1 and Claude-3, research isn't just about searching – it's about intelligent synthesis. Deep Research Agents plan, fetch data, reflect, and compile like a pro researcher, but at warp speed.&lt;/p&gt;

&lt;p&gt;Why does this matter?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency Boost&lt;/strong&gt;: Manual deep dives take hours; Nexa does it in &amp;lt;30 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality &amp;amp; Depth&lt;/strong&gt;: Iterative reflection fills gaps, ensuring balanced, cited reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monetization Ready&lt;/strong&gt;: Built-in Stripe tiers (Free: 10 queries/day, Pro: $29/mo for 200) – ideal for SaaS hustles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open-Source Power&lt;/strong&gt;: MIT-licensed, so fork it for custom tools in healthcare, finance, or education.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agentic AI Future&lt;/strong&gt;: As xAI pushes boundaries, this preps us for autonomous workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inspired by a SwirlAI newsletter on building agents with DeepSeek R1, I evolved a simple script into a production system. No frameworks like LangChain – pure Python for control. Handles 100+ concurrent requests with 99.9% uptime.&lt;/p&gt;

&lt;p&gt;If you're into FastAPI, Redis, or AI agents, this is your guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Architecture: High-Level Design
&lt;/h2&gt;

&lt;p&gt;Nexa uses a 5-stage pipeline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Planning&lt;/strong&gt;: LLM outlines sections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fan-out&lt;/strong&gt;: Parallel tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Research Loop&lt;/strong&gt;: Search + Reflect (≤3 iterations).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synthesis&lt;/strong&gt;: Paragraph compilation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collation&lt;/strong&gt;: Final Markdown report.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visualized in Mermaid:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7t164hpxemdxfh3ml3a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7t164hpxemdxfh3ml3a.png" alt="Architecture Diagram" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tech stack table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;th&gt;Why?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;API Framework&lt;/td&gt;
&lt;td&gt;FastAPI&lt;/td&gt;
&lt;td&gt;Async, high-perf API.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLMs&lt;/td&gt;
&lt;td&gt;OpenRouter&lt;/td&gt;
&lt;td&gt;Routes to DeepSeek R1, Claude-3, Qwen.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Search&lt;/td&gt;
&lt;td&gt;Exa.ai&lt;/td&gt;
&lt;td&gt;Neural search &amp;gt; traditional.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache&lt;/td&gt;
&lt;td&gt;Redis&lt;/td&gt;
&lt;td&gt;Sub-ms hits, rate-limiting.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DB&lt;/td&gt;
&lt;td&gt;PostgreSQL&lt;/td&gt;
&lt;td&gt;Users/subscriptions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vectors&lt;/td&gt;
&lt;td&gt;Qdrant&lt;/td&gt;
&lt;td&gt;Semantic reuse.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payments&lt;/td&gt;
&lt;td&gt;Stripe&lt;/td&gt;
&lt;td&gt;Easy tiers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deploy&lt;/td&gt;
&lt;td&gt;Docker&lt;/td&gt;
&lt;td&gt;Portable.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Cost: Pennies/query thanks to caching.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step-by-Step: How I Built It
&lt;/h2&gt;

&lt;p&gt;Cloned a base repo, added files like &lt;code&gt;main.py&lt;/code&gt;, &lt;code&gt;config.py&lt;/code&gt;. Used &lt;code&gt;pyproject.toml&lt;/code&gt; for deps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[project]&lt;/span&gt;
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"nexa-deep-research-agent"&lt;/span&gt;
&lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1.0"&lt;/span&gt;
&lt;span class="py"&gt;requires-python&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="py"&gt;"&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;3.10&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="py"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="py"&gt;"fastapi=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.104&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"uvicorn[standard]=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.24&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"pydantic=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"redis=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;5.0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"aioredis=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"httpx=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"openai=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.3&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"stripe=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;7.8&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"typer=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"python-dotenv=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"qdrant-client=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.7&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"sentence-transformers=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.2&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"psycopg2-binary=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.9&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"sqlalchemy=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="s"&gt;",&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="py"&gt;"alembic=&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1.13&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Env setup in &lt;code&gt;.env.example&lt;/code&gt; (copy to &lt;code&gt;.env&lt;/code&gt; with keys).&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Config &amp;amp; Startup
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;config.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;

&lt;span class="nf"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;REDIS_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REDIS_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;redis://localhost:6379&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Add HELIX_DB_URL, etc.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;main.py&lt;/code&gt; boots FastAPI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;api.routes&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;router&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;REDIS_URL&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;aioredis&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;services.helix_client&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HelixClient&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi.responses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;JSONResponse&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nd"&gt;@app.on_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;startup&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;startup_event&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;aioredis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;REDIS_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;helix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;HelixClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nd"&gt;@app.on_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shutdown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;shutdown_event&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;helix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;include_router&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/api/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/health&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;health_check&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;JSONResponse&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;healthy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timestamp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;version&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1.0.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Core Pipeline
&lt;/h3&gt;

&lt;p&gt;Planning in &lt;code&gt;core/planner.py&lt;/code&gt; (pseudo, expand as needed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;services.openrouter_client&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenRouterClient&lt;/span&gt;
&lt;span class="n"&gt;openrouter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenRouterClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;plan_research&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a Deep Research assistant. Plan a structure for a report...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;openrouter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;deepseek/deepseek-r1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Parse JSON outline
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Research loop in &lt;code&gt;core/research.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;services.exa_client&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exa_search&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iterative_research&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pass_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;full&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;para&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;paragraphs&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Initial query based on para&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# LLM-generated
&lt;/span&gt;        &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;exa_search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_results&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;para&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;research&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pass_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;full&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;reflection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LLM reflect on results&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# Use Qwen
&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;needs more&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;new_query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Refined query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;exa_search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Synthesis in &lt;code&gt;core/summarizer.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;compile_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;# Report Title&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;para&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;paragraphs&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LLM synthesize para&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# Claude-Haiku
&lt;/span&gt;        &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;## &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;para&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;  &lt;span class="c1"&gt;# Markdown string
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. API Routes
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;api/routes.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;APIRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;core.cache&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_cached_report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;set_cached_report&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;core.planner&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;plan_research&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;core.research&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;iterative_research&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;core.summarizer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;compile_report&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;schemas.query&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;QueryRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;QueryResponse&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sentence_transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SentenceTransformer&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sha256&lt;/span&gt;

&lt;span class="n"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;APIRouter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;embedding_model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SentenceTransformer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;all-MiniLM-L6-v2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@router.post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;QueryResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;query_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;QueryRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;redis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;
    &lt;span class="n"&gt;helix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;helix&lt;/span&gt;
    &lt;span class="n"&gt;key_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;cache_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;report:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key_hash&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;get_cached_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cache_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cached&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;QueryResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cached&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;research_plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;plan_research&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;updated_plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;iterative_research&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;research_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pass_type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;report_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;compile_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updated_plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;topic&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;report_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;created_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;set_cached_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cache_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ttl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;vector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;embedding_model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;helix&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reports&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cache_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;vector&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;payload&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;}])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;QueryResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cached&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Services: Exa.ai, OpenRouter, etc.
&lt;/h3&gt;

&lt;p&gt;Exa client in &lt;code&gt;services/exa_client.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;

&lt;span class="n"&gt;EXA_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;EXA_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;EXA_SEARCH_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.exa.ai/search&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;EXA_API_KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;num_results&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;num_results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exclude_domains&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reddit.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;twitter.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;use_autoprompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;neural&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;contents&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max_characters&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsyncClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXA_SEARCH_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;results&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similar for OpenRouter, Qdrant.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Caching &amp;amp; Quotas
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;core/cache.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_cached_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_cached_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ttl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ttl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quotas in &lt;code&gt;services/user_service.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tier_limits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;free&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pro&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;custom&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_rate_limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;today&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;today&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queries:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;today&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;incr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Set TTL to midnight
&lt;/span&gt;        &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;seconds_left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;86400&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds_left&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;tier_limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{}).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Deployment
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;docker-compose.yml&lt;/code&gt; (partial):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;api&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8000:8000"&lt;/span&gt;
  &lt;span class="na"&gt;redis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis:7.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run: &lt;code&gt;docker-compose up -d&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges &amp;amp; Learnings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prompts&lt;/strong&gt;: Use JSON schemas for structured outputs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Costs&lt;/strong&gt;: Cache aggressively; route models wisely (DeepSeek for planning, Claude for synthesis).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scaling&lt;/strong&gt;: AsyncIO shines; monitor LLM rates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edges&lt;/strong&gt;: Fallbacks for search failures; validate JSON.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Built in ~2 weeks part-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It Matters: Impact &amp;amp; Next Steps
&lt;/h2&gt;

&lt;p&gt;Nexa democratizes deep research – devs save time, businesses get insights. Open-source fosters innovation.&lt;/p&gt;

&lt;p&gt;Roadmap: Multi-lang, custom sources, collab.&lt;/p&gt;

&lt;p&gt;Star/fork:&lt;a href="https://github.com/DarkStarStrix/Nexa_Research_Agent/tree/main" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/Nexa_Research_Agent/tree/main&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Thoughts? Would you build on this? Comments below! Follow for more AI tutorials. &lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>nlp</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>NEXAPod: The Discovery Engine That Could Change the Future of Science Forever</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Thu, 07 Aug 2025 16:30:11 +0000</pubDate>
      <link>https://dev.to/darkstalker/nexapod-the-discovery-engine-that-could-change-the-future-of-science-forever-3mfj</link>
      <guid>https://dev.to/darkstalker/nexapod-the-discovery-engine-that-could-change-the-future-of-science-forever-3mfj</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“The story of humanity is not one of war or trade. It is the story of discovery.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;We discovered fire and we were never the same again.&lt;br&gt;&lt;br&gt;
We discovered atoms, electricity, DNA, semiconductors.&lt;br&gt;&lt;br&gt;
We crossed oceans, decoded the genome, and built machines that dream.&lt;/p&gt;

&lt;p&gt;And at every step every turning point—we proved the same thing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;When we understand more, we become more.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But today, discovery is broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Scientific Bottleneck
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Billions of compute hours sit idle globally.&lt;/li&gt;
&lt;li&gt;Researchers are bottlenecked by grant access, closed systems, and institutional politics.&lt;/li&gt;
&lt;li&gt;Promising models die in Jupyter Notebooks.&lt;/li&gt;
&lt;li&gt;Massive datasets sit untouched because &lt;strong&gt;no one can process them at scale.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We don't lack imagination.&lt;br&gt;&lt;br&gt;
We lack the &lt;strong&gt;infrastructure&lt;/strong&gt; to &lt;strong&gt;test our ideas at global scale&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s why I built &lt;strong&gt;NEXAPod&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  NEXAPod: The Discovery Engine
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NEXAPod is a decentralized, cryptographically-validated scientific compute mesh for AI-driven science.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’m not building another toy infra stack.&lt;br&gt;&lt;br&gt;
This is a &lt;strong&gt;generalist, global engine for solving civilization-scale scientific problems&lt;/strong&gt;—starting with proteins, ending with DreamMS, and expanding to whatever problem humanity dares to throw at it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mythos: Why I’m Doing This
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"&lt;em&gt;The story of humanity is the story of discovery.&lt;/em&gt;"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not commerce.&lt;br&gt;&lt;br&gt;
Not conquest.&lt;br&gt;&lt;br&gt;
But our ability to understand the world and shape it with that understanding.&lt;/p&gt;

&lt;p&gt;Science is how we make sense of the chaos.&lt;br&gt;&lt;br&gt;
Technology is how we turn that knowledge into progress.&lt;/p&gt;

&lt;p&gt;And yet, science itself has become gated, slow, elite.&lt;/p&gt;

&lt;p&gt;But what if we could flip that?&lt;/p&gt;

&lt;p&gt;What if every person with a CPU or GPU could &lt;strong&gt;run scientific inference&lt;/strong&gt;?&lt;br&gt;&lt;br&gt;
What if we scaled &lt;strong&gt;collective scientific compute&lt;/strong&gt; the way we scaled Bitcoin?&lt;br&gt;&lt;br&gt;
What if we aligned incentives, compute, and curiosity to &lt;strong&gt;accelerate science itself&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;That’s the core idea behind &lt;strong&gt;NEXAPod&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I am just one dude with a Docker container and a dream.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But if this works?&lt;/p&gt;

&lt;p&gt;We’re talking about the scientific equivalent of LLaMA.cpp or Folding@Home, but applied to &lt;strong&gt;frontier inference&lt;/strong&gt;: proteins, quantum, climate, materials, disease.&lt;/p&gt;




&lt;h2&gt;
  
  
  What We’ve Built (and Where We’re Going)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Alpha – &lt;em&gt;Now Live&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Inference: Secondary structure protein prediction via &lt;strong&gt;NexaBio-1&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Containerized client with cryptographic hash logging&lt;/li&gt;
&lt;li&gt;Coordinator server that mirrors the DB and assigns tasks&lt;/li&gt;
&lt;li&gt;Integration-tested across multiple simulated nodes&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the &lt;strong&gt;bootstrapping phase&lt;/strong&gt;—testing the Core Scheduling Engine (CSE), gathering contributors, laying groundwork.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Beta – &lt;em&gt;Tertiary Structure &amp;amp; Scaling&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Inference: Tertiary 3D structure prediction (NexaBio-2)&lt;/li&gt;
&lt;li&gt;Adds: Redundant job validation, reputation system, Nexa Credits, dashboards&lt;/li&gt;
&lt;li&gt;Hardened scheduler, fuzzed job queue&lt;/li&gt;
&lt;li&gt;Wider contributor pool, robust volunteer mesh&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Omega – &lt;em&gt;DreamMS: The 201M Molecule Challenge&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Goal: Process &lt;strong&gt;201 million MS-MS spectra&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Adds: ZK-proofs, P2P coordination, tokenized incentives&lt;/li&gt;
&lt;li&gt;Scientific intelligence models trained on verified compute runs&lt;/li&gt;
&lt;li&gt;The first public mesh LLMs for molecular science&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What Is DreamMS?
&lt;/h2&gt;

&lt;p&gt;It’s a real dataset.&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;massive, underutilized reservoir&lt;/strong&gt; of over 201 million unannotated MS-MS (mass spectrometry) spectra.&lt;/p&gt;

&lt;p&gt;It represents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New drugs&lt;/li&gt;
&lt;li&gt;New materials&lt;/li&gt;
&lt;li&gt;New chemistry&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New unknowns&lt;/strong&gt; waiting to be discovered&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No one has run it at scale because no one has built the mesh to do it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NEXAPod will.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Link to more reading on the omega: &lt;a href="https://github.com/pluskal-lab/DreaMS" rel="noopener noreferrer"&gt;https://github.com/pluskal-lab/DreaMS&lt;/a&gt;&lt;/p&gt;




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

&lt;h2&gt;
  
  
  System Roles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client Node&lt;/strong&gt;: Runs the job, logs results, signs output hash&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coordinator (VPS)&lt;/strong&gt;: Assigns jobs, validates hashes, updates credits&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result Hashing&lt;/strong&gt;: Cryptographically signed, ready for future ZK-rollup integration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incentive Engine&lt;/strong&gt;: In design phase—Nexa Credits now, tokens later&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Security Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Redundant job execution (N &amp;gt; M match model)&lt;/li&gt;
&lt;li&gt;Light reputation tracking for nodes&lt;/li&gt;
&lt;li&gt;Early fuzz testing for input validation&lt;/li&gt;
&lt;li&gt;ZK-proof system coming in Omega&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The system isn't perfectly decentralized yet. But it's &lt;strong&gt;moving toward&lt;/strong&gt; a verifiable, incentivized, and trustless compute mesh.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How You Can Help
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Run the Node
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open source client ready now&lt;/li&gt;
&lt;li&gt;Join the Alpha by running jobs from your machine&lt;/li&gt;
&lt;li&gt;Instructions on GitHub:
&amp;gt; &lt;a href="https://github.com/DarkStarStrix/NexaPod" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/NexaPod&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Contribute Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fork the repo&lt;/li&gt;
&lt;li&gt;Submit PRs&lt;/li&gt;
&lt;li&gt;First Issues and CONTRIBUTING.md coming soon&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support the Project
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Sponsors: &lt;a href="https://github.com/sponsors/DarkStarStrix" rel="noopener noreferrer"&gt;https://github.com/sponsors/DarkStarStrix&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon: &lt;a href="https://patreon.com/user?u=12454131&amp;amp;utm_medium=unknown&amp;amp;utm_source=join_link&amp;amp;utm_campaign=creatorshare_creator&amp;amp;utm_content=copyLink" rel="noopener noreferrer"&gt;https://patreon.com/user?u=12454131&amp;amp;utm_medium=unknown&amp;amp;utm_source=join_link&amp;amp;utm_campaign=creatorshare_creator&amp;amp;utm_content=copyLink&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Every dollar goes into scaling the infrastructure, paying for compute, and helping build the future of decentralized science.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  For Investors &amp;amp; Companies
&lt;/h2&gt;

&lt;p&gt;If you’re an angel, a philanthropic funder, or a visionary organization:&lt;/p&gt;

&lt;p&gt;You're not investing in a product.&lt;br&gt;&lt;br&gt;
You're investing in &lt;strong&gt;scientific freedom at scale&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s talk.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Because we are squandering potential.&lt;/p&gt;

&lt;p&gt;Because too many ideas die in notebooks.&lt;br&gt;&lt;br&gt;
Because the tools of science belong to all of us.&lt;br&gt;&lt;br&gt;
Because problems like protein folding, quantum simulation, and molecular modeling shouldn’t be &lt;strong&gt;gatekept by capital.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We already proved collective compute works:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Folding@Home
&lt;/li&gt;
&lt;li&gt;BOINC
&lt;/li&gt;
&lt;li&gt;LLaMA.cpp
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;NEXAPod is next.&lt;br&gt;&lt;br&gt;
This is &lt;strong&gt;AI for science&lt;/strong&gt;, &lt;strong&gt;run by the people&lt;/strong&gt;, &lt;strong&gt;for the future.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Final Rallying Cry
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Do not go gentle into that good night…”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We won't.&lt;/p&gt;

&lt;p&gt;We will build.&lt;br&gt;&lt;br&gt;
We will train.&lt;br&gt;&lt;br&gt;
We will simulate proteins, solve spectra, model atoms, and engineer new futures—because we &lt;strong&gt;believe&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you've ever wanted to push back against stagnation—this is it.&lt;br&gt;&lt;br&gt;
If you've ever wanted to help humanity solve real problems—start here.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NEXAPod is not just a mesh.&lt;br&gt;&lt;br&gt;
It’s a movement.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Join the Revolution
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/DarkStarStrix/NexaPod" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/NexaPod&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contribute&lt;/li&gt;
&lt;li&gt;Run the software&lt;/li&gt;
&lt;li&gt;Sponsor the vision&lt;/li&gt;
&lt;li&gt;Amplify the Mythos&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Those who take action shape the future.  Be one of them.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;NEXAPod: The Discovery Engine.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Link to full paper: &lt;a href="https://github.com/DarkStarStrix/CSE-Repo-of-Advanced-Computation-ML-and-Systems-Engineering/blob/main/Papers/Engineering/NexaPod_full.pdf" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/CSE-Repo-of-Advanced-Computation-ML-and-Systems-Engineering/blob/main/Papers/Engineering/NexaPod_full.pdf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>science</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>github</category>
    </item>
    <item>
      <title>Scientific AI with NEXA's Stacked Adapter Fine-Tuning Strategy</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 28 Jul 2025 18:15:53 +0000</pubDate>
      <link>https://dev.to/darkstalker/scientific-ai-with-nexas-stacked-adapter-fine-tuning-strategy-3n53</link>
      <guid>https://dev.to/darkstalker/scientific-ai-with-nexas-stacked-adapter-fine-tuning-strategy-3n53</guid>
      <description>&lt;h1&gt;
  
  
  Revolutionizing Scientific AI with NEXA's Stacked Adapter Fine-Tuning Strategy
&lt;/h1&gt;

&lt;p&gt;In the rapidly evolving world of AI-driven scientific discovery, efficiently adapting large language models (LLMs) to specialized domains without sacrificing general reasoning capabilities is a critical challenge. The &lt;strong&gt;NEXA fine-tuning pipeline&lt;/strong&gt; introduces an innovative solution through its &lt;strong&gt;stacked adapter architecture&lt;/strong&gt;, leveraging Parameter-Efficient Fine-Tuning (PEFT) with LoRA adapters. This modular, scalable approach combines &lt;strong&gt;GLoRA&lt;/strong&gt; (General Scientific Reasoning Adapter) and &lt;strong&gt;SQLoRA&lt;/strong&gt; (Specialized Scientific Adapter) to empower LLMs with both broad scientific reasoning and domain-specific expertise. Here’s a deep dive into how NEXA is transforming AI for science, as outlined in the &lt;em&gt;NEXA Fine-Tuning Strategy v2&lt;/em&gt; specification.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Stacked Adapter Architecture: A Modular Approach
&lt;/h2&gt;

&lt;p&gt;The NEXA pipeline is built around a &lt;strong&gt;stacked adapter strategy&lt;/strong&gt; that separates general scientific reasoning from domain-specific knowledge, ensuring flexibility and efficiency. This approach avoids the pitfalls of catastrophic forgetting—where fine-tuning erases previously learned capabilities—while enabling rapid adaptation to new scientific subfields. The architecture consists of two key components:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. GLoRA: The Reasoning Foundation
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;General Scientific Reasoning Adapter (GLoRA)&lt;/strong&gt; serves as the backbone of the NEXA pipeline. Its role is to inject broad, cross-disciplinary scientific reasoning into the base LLM.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Objective&lt;/strong&gt;: Equip the model with foundational skills like hypothesis generation, consistency checks, methodological reasoning, and formal logic flow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Training Corpus&lt;/strong&gt;: A massive dataset of 100M–325M tokens, drawn from a diverse range of scientific documents spanning physics, biology, chemistry, and AI research.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Position in Stack&lt;/strong&gt;: GLoRA is the first adapter applied, forming the "reasoning base" that all subsequent specialized adapters build upon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of GLoRA as the general-purpose scientific brain, enabling the model to structure papers, reason logically, and align with scientific methodologies across domains.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. SQLoRA: Domain-Specific Expertise
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Specialized Scientific Adapter (SQLoRA)&lt;/strong&gt; overlays targeted expertise for specific scientific subfields, such as molecular biology or astrophysics.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Objective&lt;/strong&gt;: Add high-resolution alignment with domain-specific terminology, methodologies, and edge cases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Training Corpus&lt;/strong&gt;: Smaller, focused datasets of 500k–1M tokens per domain, ensuring precision without overwhelming the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Position in Stack&lt;/strong&gt;: Applied after GLoRA via adapter fusion or staged injection, allowing seamless integration of specialized knowledge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, an SQLoRA for molecular biology (SQLoRA-Bio) might enhance the model’s ability to generate protein folding hypotheses, while an SQLoRA for theoretical physics (SQLoRA-Physics) could focus on equation grounding and citation consistency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Stacked Adapters? The Power of Modularity
&lt;/h2&gt;

&lt;p&gt;The stacked adapter approach offers several compelling advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency&lt;/strong&gt;: By training lightweight adapters instead of retraining entire models, NEXA drastically reduces GPU hours and computational costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composability&lt;/strong&gt;: SQLoRA adapters can be swapped or fused with the stable GLoRA backbone, enabling flexible adaptation to new tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modularity&lt;/strong&gt;: Each subfield evolves independently, so new SQLoRA adapters can be developed without disrupting the general reasoning layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Adding a new domain is as simple as training a new SQLoRA, while the shared GLoRA foundation remains unchanged.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This modular design makes the pipeline ideal for ongoing research, where scientific fields evolve rapidly and require frequent updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  The NEXA Auto Framework: Automation at Its Core
&lt;/h2&gt;

&lt;p&gt;The fine-tuning process is fully automated through the &lt;strong&gt;Nexa Auto framework&lt;/strong&gt;, a CLI/TUI tool that streamlines training, manages secure tokenized workflows, and abstracts complex logic. Key features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retry Logic&lt;/strong&gt;: Gradient checkpointing and modular restarts ensure that failed jobs can resume seamlessly, minimizing downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation Integration&lt;/strong&gt;: Post-training, adapters are injected into inference pipelines to generate scientific artifacts (e.g., hypotheses or research papers), which are evaluated using the &lt;strong&gt;SciEval framework&lt;/strong&gt; for accuracy and relevance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This automation empowers researchers to focus on science rather than the intricacies of model training.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling Strategy: One GLoRA, Many SQLoRAs
&lt;/h2&gt;

&lt;p&gt;The NEXA pipeline is designed for scalability across model families and scientific disciplines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shared GLoRA&lt;/strong&gt;: A single GLoRA adapter is trained per model family (e.g., Nexa-Mistral-7B), serving as the common foundation for all tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight SQLoRAs&lt;/strong&gt;: Multiple SQLoRA adapters are trained for specific subfields, avoiding the need to retrain the full model for each domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distillation for Production&lt;/strong&gt;: GLoRA and SQLoRA adapters can be distilled into denser formats for efficient inference or deployed via the &lt;strong&gt;Nexa inference stack&lt;/strong&gt; for production-scale applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach ensures that NEXA can handle a growing number of domains without exponential increases in computational overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example Use Case: From General to Specialized
&lt;/h2&gt;

&lt;p&gt;To illustrate, consider how the pipeline works for two domains:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Component&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Adapter Type&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Domain&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Functionality&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GLoRA&lt;/td&gt;
&lt;td&gt;General&lt;/td&gt;
&lt;td&gt;Multi-Science&lt;/td&gt;
&lt;td&gt;Reasoning, paper structuring, logic alignment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SQLoRA-Bio&lt;/td&gt;
&lt;td&gt;Specialized&lt;/td&gt;
&lt;td&gt;Molecular Biology&lt;/td&gt;
&lt;td&gt;Protein folding hypotheses, structure mapping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SQLoRA-Physics&lt;/td&gt;
&lt;td&gt;Specialized&lt;/td&gt;
&lt;td&gt;Theoretical Physics&lt;/td&gt;
&lt;td&gt;Equation grounding, method consistency, citation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For instance, a researcher using the NEXA pipeline could generate a hypothesis about protein structures in molecular biology by leveraging the GLoRA’s general reasoning capabilities and the SQLoRA-Bio’s specialized knowledge, all while maintaining consistency with scientific standards.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It Matters for Scientific AI
&lt;/h2&gt;

&lt;p&gt;The NEXA fine-tuning strategy is a game-changer for AI in scientific research. By combining general reasoning with domain-specific expertise in a modular, efficient framework, NEXA enables LLMs to tackle complex scientific tasks with unprecedented flexibility. Whether it’s generating hypotheses, structuring papers, or grounding equations, this pipeline ensures that AI can keep pace with the ever-evolving landscape of scientific discovery.&lt;/p&gt;

&lt;p&gt;Want to dive deeper? Check out My GLORA Fine tunes SQLORA coming soon on HF happy adpating: &lt;a href="https://huggingface.co/Allanatrix" rel="noopener noreferrer"&gt;https://huggingface.co/Allanatrix&lt;/a&gt;&lt;/p&gt;

</description>
      <category>science</category>
      <category>programming</category>
      <category>ai</category>
      <category>finetune</category>
    </item>
    <item>
      <title>Why Science Must Be Decentralized, Permissionless, and Widely Available</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Tue, 22 Jul 2025 16:56:31 +0000</pubDate>
      <link>https://dev.to/darkstalker/why-science-must-be-decentralized-permissionless-and-widely-available-5481</link>
      <guid>https://dev.to/darkstalker/why-science-must-be-decentralized-permissionless-and-widely-available-5481</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Progress is born not in ivory towers, but in garages, basements, and open forums."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a world facing existential threats from pandemics to climate collapse to quantum uncertainty we can no longer afford to gatekeep discovery. Science, at its best, is a collaborative process that thrives on diversity of thought, access to compute, and the freedom to experiment.&lt;/p&gt;

&lt;p&gt;Yet today, science remains chained by centralized inertia.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Bottleneck of Bureaucracy
&lt;/h1&gt;

&lt;p&gt;Traditional scientific institutions be they universities, national labs, or legacy peer-reviewed journals were designed for an era where access was limited and slow. In that world, hierarchy brought order. But in today’s networked, compute-heavy, post-AI world, that same hierarchy is a bottleneck.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Inertia over innovation: Grant cycles move slower than technological progress. Groundbreaking ideas get buried under committee reviews, political risk assessments, or outdated paradigms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Credential gatekeeping: Many of the world’s brightest minds are outside academia. Yet if you lack institutional affiliation, your ability to publish, collaborate, or even apply for funding is diminished.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resource hoarding: HPC clusters, lab equipment, and datasets are locked behind institutional walls. Only select researchers with the "right access" can run meaningful experiments.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This system doesn't just slow us down it filters out voices and ideas that could transform the world.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Case for Decentralized Science
&lt;/h1&gt;

&lt;p&gt;NEXAPod is a distributed computing fabric for scientific problems. It lets you run complex simulations protein folding, weather forecasting, quantum simulation on a global mesh of compute nodes, from GPUs in someone's garage to cloud instances in research clusters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Heterogeneous compute unification: You can join with whatever hardware you have laptop, gaming rig, or HPC and contribute to scientific workloads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Job redundancy and trustless execution: Results are verified cryptographically. You don't have to trust the node—you can trust the math.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open economy of research: Credits and tokenized rewards are issued for valuable compute cycles. No more free labor for closed journals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Protocol, not platform: NEXAPod isn’t a product it’s an ecosystem.&lt;br&gt;
Anyone can build on top of it, submit jobs, or spin up nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publication as prestige, not progress: Papers get written to earn citations and tenure points, not to solve problems. The incentive structure rewards safe, incremental work—not radical breakthroughs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Science as Infrastructure
&lt;/h1&gt;

&lt;p&gt;What Git did for code, what the internet did for information, NEXAPod aims to do for scientific compute: remove the middlemen. If knowledge creation is a human right, then access to the tools that power discovery must be &lt;br&gt;
public infrastructure. Decentralized science isn’t just about efficiency it’s about equity.&lt;/p&gt;

&lt;p&gt;Anyone who is curious and ready to help contribute, whether it's their area of expertise, computation, or even verification of results, should be given a node to help advance the state of humanity. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Simulate protein structures in response to a viral outbreak.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test novel battery chemistries in a virtual lab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run quantum experiments with crowd-compute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publish results instantly—on-chain, on-archive, on-impact.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  A Call to Build
&lt;/h1&gt;

&lt;p&gt;We must build systems where bureaucracy can't slow us, where knowledge is not hoarded, and where the right to contribute is universal. Decentralized, permissionless, and open science is not an ideology—it’s an engineering necessity.&lt;/p&gt;

&lt;p&gt;Let’s build a world where your compute matters more than your credentials.&lt;br&gt;
Github Repo: &lt;a href="https://github.com/DarkStarStrix/NexaPod" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/NexaPod&lt;/a&gt;&lt;br&gt;
Streamlit demo: &lt;a href="https://nexapod.streamlit.app/" rel="noopener noreferrer"&gt;https://nexapod.streamlit.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>science</category>
      <category>infrastructureascode</category>
      <category>thesis</category>
      <category>programming</category>
    </item>
    <item>
      <title>Nexa Auto: Your Go-To for Easy, Secure LLM Fine-Tuning</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Tue, 08 Jul 2025 01:56:14 +0000</pubDate>
      <link>https://dev.to/darkstalker/nexa-auto-your-go-to-for-easy-secure-llm-fine-tuning-2hif</link>
      <guid>https://dev.to/darkstalker/nexa-auto-your-go-to-for-easy-secure-llm-fine-tuning-2hif</guid>
      <description>&lt;p&gt;Imagine you’re a developer itching to fine-tune a language model but dreading the setup hassle—managing tokens, wrangling hardware, configuring datasets, and keeping everything secure. Enter Nexa Auto, a slick tool that takes the pain out of fine-tuning Hugging Face-compatible large language models (LLMs). It’s like having a personal assistant who handles the boring stuff, letting you focus on picking the right model and data to make your project shine.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Nexa Auto All About?
&lt;/h2&gt;

&lt;p&gt;Nexa Auto is a command-line (CLI) and terminal user interface (TUI) tool built for developers, whether you’re just starting out or a seasoned pro. It streamlines the entire fine-tuning process for LLMs using Hugging Face’s powerful libraries. Think of it as an orchestrator that guides you step-by-step, works on your local machine (with cloud support planned), and keeps everything secure by never saving sensitive stuff like your Hugging Face token to disk. It’s part of the broader Nexa ecosystem, which you might recognize as a hub for scientific AI projects, but it’s designed to stand alone for anyone diving into model fine-tuning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why You’ll Love It
&lt;/h2&gt;

&lt;p&gt;Here’s what makes Nexa Auto stand out:&lt;br&gt;
Super Secure Token Handling: Your Hugging Face token stays in memory, encrypted with AES-GCM, and never touches your disk. It’s like locking your secrets in a vault that disappears when you’re done.&lt;br&gt;
Choose Your Style: Prefer a modern, interactive terminal UI? The Go-based TUI (powered by BubbleTea) has you covered. Want a classic command-line feel? The Python CLI (using Rich) is smooth and intuitive.&lt;br&gt;
Guided and Easy: Nexa Auto walks you through picking a model (from Hugging Face Hub or a local file), selecting a dataset, naming your output, and checking your hardware. No guesswork needed.&lt;/p&gt;

&lt;p&gt;Hardware Smarts: It automatically detects your CPU or GPU setup, so you know exactly what you’re working with before you start training.&lt;br&gt;
Efficient Fine-Tuning: Supports LoRA and PEFT, which are like lightweight add-ons for models, saving you time and compute power.&lt;/p&gt;

&lt;p&gt;Hackable Design: Want to add new features or tweak it? Its modular setup makes it easy to extend with new training modes or custom logging.&lt;br&gt;
How It Actually Works&lt;/p&gt;

&lt;p&gt;Nexa Auto is split into three main pieces that work together like a well-oiled machine:&lt;/p&gt;

&lt;p&gt;Session Server (session_server.py): This is the secure brain of the operation. It runs locally using FastAPI and keeps your Hugging Face token safe in memory. The CLI or TUI talks to this server to handle authentication without ever risking your credentials.&lt;/p&gt;

&lt;p&gt;User Interface (CLI or TUI): You get two flavors here:&lt;br&gt;
The Python CLI is clean and text-based, perfect for quick commands.&lt;br&gt;
The Go TUI is a fancier, interactive interface for a more visual experience. Both guide you through picking a model, dataset, and output name, then confirm your hardware before kicking off training. You can switch between them depending on your mood.&lt;/p&gt;

&lt;p&gt;Training Backend (trainer_server.py): This is where the magic happens. It uses a REST API to manage training jobs, load your model and dataset, apply tokenization, and run the Hugging Face Trainer. It supports efficient fine-tuning with LoRA/PEFT and saves your fine-tuned model ready for Hugging Face Hub upload.&lt;br&gt;
Get Started in a Snap&lt;/p&gt;

&lt;p&gt;Here’s how to dive in:&lt;br&gt;
What You Need:&lt;br&gt;
Python 3.8+ (for the backend and CLI)&lt;br&gt;
Go 1.18+ (if you want the TUI)&lt;br&gt;
A CUDA-capable GPU (nice to have for local training)&lt;br&gt;
A Hugging Face access token&lt;br&gt;
A dataset (from Hugging Face Hub or a local file)&lt;/p&gt;

&lt;p&gt;Set It Up: Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh git clone https://github.com/your-org/nexa-auto.git
cd nexa-auto
Install Python dependencies:
sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
For the TUI, set up Go:
sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd go_cli
go mod tidy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fire Up the Session Server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh python session_server.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starts the secure server for token management.&lt;br&gt;
Launch Your Interface: For the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh python cli.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or for the TUI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sh cd go_cli
go run main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the Flow:&lt;br&gt;
Enter your Hugging Face token (just once per session).&lt;br&gt;
Pick your model and dataset.&lt;br&gt;
Name your output model.&lt;br&gt;
Confirm your hardware setup.&lt;br&gt;
Hit go and watch it train!&lt;/p&gt;

&lt;p&gt;Track and Collect: Monitor progress through logs in the interface. When it’s done, grab your fine-tuned model for Hugging Face Hub upload.&lt;br&gt;
A Sample Run&lt;/p&gt;

&lt;p&gt;Picture this: You start the session server, fire up the CLI, and enter your token. Nexa Auto asks you to pick a model (say, a lightweight one like DistilBERT), a dataset (maybe a local CSV or something from Hugging Face), and a name for your fine-tuned model. It checks your GPU, confirms everything looks good, and starts training. You sip coffee while watching real-time logs, and soon enough, you’ve got a shiny new model ready to share or use.&lt;/p&gt;

&lt;p&gt;Security You Can Trust&lt;br&gt;
Nexa Auto takes security seriously:&lt;/p&gt;

&lt;p&gt;No Disk, No Risk: Your token stays in memory and gets wiped when you’re done.&lt;/p&gt;

&lt;p&gt;Local-Only Server: The session server only listens to localhost, keeping things private.&lt;/p&gt;

&lt;p&gt;Clean Exit: Tokens are cleared automatically at the end of a session or if you say so.&lt;/p&gt;

&lt;p&gt;Make It Your Own&lt;br&gt;
Nexa Auto’s modular design means you can tweak it to fit your needs. Want to add a new training mode? Update remote.py. Need custom hardware checks? Extend hardware.py. Want better logs? Hook into logging.py. It’s built to grow with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next for Nexa Auto?
&lt;/h2&gt;

&lt;p&gt;The tool already supports local training, LoRA/PEFT, and remote options like SSH or Kaggle. The team’s working on auto-generating model cards to make sharing even easier. Given your interest in the Nexa ecosystem (like organizing links for material science projects), Nexa Auto could integrate nicely with tools like Nexa Data Studio for managing datasets or NexaHub for sharing results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Got Issues?
&lt;/h2&gt;

&lt;p&gt;If something goes wonky, check the logs in the interface. For bugs or ideas, hit up the GitHub repo with an issue or pull request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick FAQs
&lt;/h2&gt;

&lt;p&gt;Is my token safe? Yep, it’s encrypted in memory and never saved to disk.&lt;br&gt;
Can I use my own dataset? Totally—local files or Hugging Face Hub datasets both work.&lt;/p&gt;

&lt;p&gt;What about remote servers? Remote and cloud support (like SSH or Kaggle) are already in, with more to come.&lt;/p&gt;

&lt;p&gt;To the Github repo: &lt;a href="https://github.com/DarkStarStrix/Nexa_Auto" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/Nexa_Auto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nexa Auto is your ticket to fast, secure, and developer-friendly LLM fine-tuning. Whether you’re tweaking models for a side project or integrating it into a bigger Nexa-powered workflow, it’s got your back. Give it a spin and let me know how it goes!&lt;/p&gt;

</description>
      <category>llm</category>
      <category>tooling</category>
      <category>go</category>
      <category>python</category>
    </item>
    <item>
      <title>Fine-Tuning Mistral-7B for Scientific Research: A Step-by-Step Guide</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 30 Jun 2025 04:00:00 +0000</pubDate>
      <link>https://dev.to/darkstalker/fine-tuning-mistral-7b-for-scientific-research-a-step-by-step-guide-ob</link>
      <guid>https://dev.to/darkstalker/fine-tuning-mistral-7b-for-scientific-research-a-step-by-step-guide-ob</guid>
      <description>&lt;h2&gt;
  
  
  A Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;Fine-tuning large language models (LLMs) like Mistral-7B for domain-specific tasks is a powerful way to adapt their capabilities to specialized fields such as scientific research. In this comprehensive guide, we'll walk through a well-structured Jupyter notebook designed for fine-tuning Mistral-7B using LoRA (Low-Rank Adaptation) and 4-bit quantization on a GPU-enabled environment. This notebook, optimized for platforms like Kaggle or Colab, ensures reproducibility and efficiency. Whether you're a machine learning practitioner or a researcher, this tutorial will help you understand the process and adapt it for your own projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Fine-Tune Mistral-7B?&lt;/strong&gt;&lt;br&gt;
Mistral-7B, developed by Mistral AI, is a 7-billion-parameter model known for its efficiency and performance in natural language processing tasks. Fine-tuning it for scientific research allows you to tailor its responses to domain-specific jargon, hypotheses, and datasets, improving accuracy and relevance. By using techniques like LoRA and quantization, we can make this process computationally feasible on consumer-grade GPUs like the NVIDIA Tesla T4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overview of the Notebook&lt;/strong&gt;&lt;br&gt;
The notebook is structured for clarity and efficiency, following a clear workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imports: All dependencies are listed upfront.&lt;/li&gt;
&lt;li&gt;Functions: Modular functions handle specific tasks like model loading, dataset preparation, and training.&lt;/li&gt;
&lt;li&gt;Main Execution: The main() function orchestrates the workflow.&lt;/li&gt;
&lt;li&gt;CPU/GPU Division: Data preparation runs on the CPU, while model training leverages the GPU.&lt;/li&gt;
&lt;li&gt;Token Batching: The notebook uses a batch size and sequence length to manage memory, with notes on implementing a custom 100M/30M token strategy for large datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s dive into the key components and how they work together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting Up the Environment&lt;/strong&gt;&lt;br&gt;
The notebook begins by installing and importing essential libraries, ensuring compatibility with GPU acceleration. Key dependencies include:&lt;/p&gt;

&lt;p&gt;Transformers: For model and tokenizer handling.&lt;br&gt;
BitsAndBytes: For 4-bit quantization to reduce memory usage.&lt;br&gt;
PEFT: For LoRA implementation.&lt;br&gt;
TRL: For supervised fine-tuning (SFT) with the SFTTrainer.&lt;br&gt;
Datasets: For loading and processing datasets.&lt;br&gt;
PyTorch: For GPU computations.&lt;/p&gt;

&lt;p&gt;Here’s a snippet of the import section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import torch
import json
import gc
from huggingface_hub import login
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    TrainingArguments,
    DataCollatorForLanguageModeling
)
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training
from datasets import load_dataset
from trl import SFTTrainer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The notebook also checks library versions and GPU availability, ensuring the environment is correctly configured:&lt;br&gt;
print(f"CUDA available: {torch.cuda.is_available()}")&lt;br&gt;
print(f"CUDA version: {torch.version.cuda}")&lt;br&gt;
!nvidia-smi&lt;/p&gt;

&lt;p&gt;To authenticate with Hugging Face for model and dataset access, the notebook uses a token stored in Kaggle Secrets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def hf_login():
    try:
        client = UserSecretsClient()
        token = client.get_secret("HF_TOKEN")
        login(token=token)
        print("Hugging Face login complete.")
    except Exception as e:
        print(f"Failed to access HF_TOKEN: {e}")
        raise
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Configuration&lt;/strong&gt;&lt;br&gt;
A Config class centralizes all hyperparameters and paths, making it easy to modify settings without digging through the code. Key parameters include:&lt;/p&gt;

&lt;p&gt;Model Name: mistralai/Mistral-7B-v0.1&lt;br&gt;
Dataset Name: Allanatrix/Scientific_Research_Tokenized&lt;br&gt;
Sequence Length: 1024 tokens&lt;br&gt;
Batch Size: 1 (with gradient accumulation to simulate larger batches)&lt;br&gt;
Learning Rate: 2e-5&lt;br&gt;
Epochs: 2&lt;br&gt;
Output Directories: For saving results and artifacts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Config:
    MODEL_NAME = "mistralai/Mistral-7B-v0.1"
    DATASET_NAME = "Allanatrix/Scientific_Research_Tokenized"
    NEW_MODEL_NAME = "nexa-mistral-sci7b"
    MAX_SEQ_LENGTH = 1024
    BATCH_SIZE = 1
    GRADIENT_ACCUMULATION_STEPS = 64
    LEARNING_RATE = 2e-5
    NUM_TRAIN_EPOCHS = 2
    OUTPUT_DIR = "/kaggle/working/results"
    ARTIFACTS_DIR = "/kaggle/working/artifacts"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration is also exportable as JSON for reproducibility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def to_dict(self):
    return {k: v for k, v in vars(self).items() if not k.startswith('__') and not callable(getattr(self, k))}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Loading the Model and Tokenizer&lt;/strong&gt;&lt;br&gt;
The get_model_and_tokenizer function loads Mistral-7B with 4-bit quantization to reduce memory usage, enabling it to run on a single Tesla T4 GPU. The BitsAndBytesConfig specifies:&lt;/p&gt;

&lt;p&gt;4-bit Quantization: Using the nf4 type.&lt;br&gt;
Compute Data Type: bfloat16 for faster GPU computations.&lt;br&gt;
Device Map: Loads the model onto GPU 0.&lt;/p&gt;

&lt;p&gt;The tokenizer is configured with the end-of-sequence token as the padding token and right-side padding for causal language modeling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def get_model_and_tokenizer(model_name: str):
    bnb_config = BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_quant_type="nf4",
        bnb_4bit_compute_dtype=torch.bfloat16,
        bnb_4bit_use_double_quant=False,
    )
    model = AutoModelForCausalLM.from_pretrained(
        model_name,
        quantization_config=bnb_config,
        trust_remote_code=True,
        device_map={"": 0}
    )
    model.config.use_cache = False
    tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
    tokenizer.pad_token = tokenizer.eos_token
    tokenizer.padding_side = "right"
    return model, tokenizer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Memory management is critical, so the function includes calls to torch.cuda.empty_cache() and gc.collect() to free up GPU and CPU memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Preparing the Dataset&lt;/strong&gt;&lt;br&gt;
The load_and_prepare_dataset function handles dataset loading and tokenization on the CPU to avoid GPU memory bottlenecks. It loads the Allanatrix/Scientific_Research_Tokenized dataset from Hugging Face and tokenizes the input_text column with a maximum sequence length of 1024 tokens. Empty sequences are filtered out to ensure data quality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def load_and_prepare_dataset(dataset_name: str, tokenizer: AutoTokenizer, max_seq_length: int):
    dataset = load_dataset(dataset_name)
    def tokenize_function(examples):
        return tokenizer(
            examples["input_text"],
            truncation=True,
            max_length=max_seq_length
        )
    tokenized_dataset = dataset.map(
        tokenize_function,
        batched=True,
        remove_columns=[col for col in dataset["train"].column_names if col != "input_ids"],
        desc="Tokenizing dataset"
    )
    tokenized_dataset = tokenized_dataset.filter(lambda x: len(x["input_ids"]) &amp;gt; 0, desc="Filtering empty sequences")
    return tokenized_dataset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The notebook mentions a "100M token pool, feed 30M until 100M" strategy, which would require a custom IterableDataset for streaming large datasets. While not fully implemented here, the MAX_SEQ_LENGTH and BATCH_SIZE settings control token batching, and group_by_length in the training arguments optimizes padding efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Configuring LoRA&lt;/strong&gt;&lt;br&gt;
LoRA is used to fine-tune only a small subset of parameters, reducing memory and compute requirements. The get_lora_config function sets up LoRA with:&lt;/p&gt;

&lt;p&gt;Rank (r): 64&lt;br&gt;
Alpha: 16&lt;br&gt;
Dropout: 0.1&lt;br&gt;
Task Type: Causal language modeling&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def get_lora_config():
    lora_config = LoraConfig(
        lora_alpha=16,
        lora_dropout=0.1,
        r=64,
        bias="none",
        task_type="CAUSAL_LM",
    )
    return lora_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model is prepared for LoRA fine-tuning with gradient checkpointing and quantization-aware training:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model.gradient_checkpointing_enable()
model = prepare_model_for_kbit_training(model)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces trainable parameters to approximately 0.375% of the total (27M out of 7.2B), significantly lowering memory usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Training Arguments&lt;/strong&gt;&lt;br&gt;
The get_training_arguments function configures the TrainingArguments for the SFTTrainer. Key settings include:&lt;/p&gt;

&lt;p&gt;Batch Size: 1 per device, with 64 gradient accumulation steps to simulate a larger batch size.&lt;br&gt;
Learning Rate: 2e-5 with a cosine scheduler.&lt;br&gt;
Optimizer: Paged AdamW in 8-bit precision.&lt;br&gt;
Precision: bf16 for faster training.&lt;br&gt;
Logging and Saving: Every 25 steps, with TensorBoard reporting.&lt;br&gt;
Group by Length: To minimize padding and optimize GPU utilization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def get_training_arguments(config: Config):
    training_args = TrainingArguments(
        output_dir=config.OUTPUT_DIR,
        num_train_epochs=config.NUM_TRAIN_EPOCHS,
        per_device_train_batch_size=config.BATCH_SIZE,
        gradient_accumulation_steps=config.GRADIENT_ACCUMULATION_STEPS,
        optim="paged_adamw_8bit",
        save_steps=25,
        logging_steps=25,
        learning_rate=config.LEARNING_RATE,
        weight_decay=0.001,
        bf16=True,
        max_grad_norm=0.3,
        warmup_ratio=0.03,
        group_by_length=True,
        lr_scheduler_type="cosine",
        report_to="tensorboard"
    )
    return training_args
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Fine-Tuning the Model&lt;/strong&gt;&lt;br&gt;
The fine_tune_model function uses the SFTTrainer from the TRL library to perform supervised fine-tuning. It combines the model, dataset, tokenizer, LoRA configuration, and training arguments. The DataCollatorForLanguageModeling handles batch preparation, moving data to the GPU asynchronously during training.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fine_tune_model(model, dataset, tokenizer, lora_config, training_args, max_seq_length):
    data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)
    trainer = SFTTrainer(
        model=model,
        train_dataset=dataset["train"],
        peft_config=lora_config,
        dataset_text_field="input_ids",
        max_seq_length=max_seq_length,
        tokenizer=tokenizer,
        args=training_args
    )
    trainer.train()
    return trainer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The training process runs for 2 epochs, with progress logged to TensorBoard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Saving Artifacts&lt;/strong&gt;&lt;br&gt;
After training, the save_model_artifacts function saves the fine-tuned model, tokenizer, training configuration, and arguments to the artifacts directory. These files ensure the model can be reloaded or shared later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def save_model_artifacts(trainer: SFTTrainer, config: Config, training_args: TrainingArguments):
    final_model_path = os.path.join(config.ARTIFACTS_DIR, config.NEW_MODEL_NAME)
    trainer.save_model(final_model_path)
    trainer.tokenizer.save_pretrained(final_model_path)
    config_filename = os.path.join(config.ARTIFACTS_DIR, "training_config.json")
    with open(config_filename, 'w') as f:
        json.dump(config.to_dict(), f, indent=4)
    training_args_filename = os.path.join(config.ARTIFACTS_DIR, "training_arguments.json")
    with open(training_args_filename, 'w') as f:
        json.dump(training_args.to_dict(), f, indent=4)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 9: Running the Workflow&lt;/strong&gt;&lt;br&gt;
The main()function ties everything together, executing the workflow in a try-except block for robust error handling. It initializes the configuration, sets up directories, logs into Hugging Face, loads the model and dataset, configures LoRA and training arguments, fine-tunes the model, and saves the artifacts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def main():
    config = Config()
    os.makedirs(config.ARTIFACTS_DIR, exist_ok=True)
    hf_login()
    model, tokenizer = get_model_and_tokenizer(config.MODEL_NAME)
    dataset = load_and_prepare_dataset(config.DATASET_NAME, tokenizer, config.MAX_SEQ_LENGTH)
    lora_config = get_lora_config()
    model.gradient_checkpointing_enable()
    model = prepare_model_for_kbit_training(model)
    model = get_peft_model(model, lora_config)
    training_args = get_training_arguments(config)
    trainer = fine_tune_model(model, dataset, tokenizer, lora_config, training_args, config.MAX_SEQ_LENGTH)
    save_model_artifacts(trainer, config, training_args)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Features and Optimizations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Memory Efficiency:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4-bit quantization reduces the model’s memory footprint.&lt;/li&gt;
&lt;li&gt;Gradient checkpointing trades compute for memory.&lt;/li&gt;
&lt;li&gt;Frequent calls to torch.cuda.empty_cache() and gc.collect() prevent memory leaks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Scalability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The notebook is designed for a single GPU but can be adapted for multi-GPU setups using accelerate.&lt;/li&gt;
&lt;li&gt;The group_by_length option minimizes padding, improving training speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reproducibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All configurations are saved as JSON files.&lt;/li&gt;
&lt;li&gt;Library versions and GPU details are logged for debugging.&lt;/li&gt;
&lt;li&gt;Custom Token Batching:&lt;/li&gt;
&lt;li&gt;While not fully implemented, the notebook outlines a strategy for handling large datasets with a 100M/30M token approach, which could be extended with a custom IterableDataset.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges and Future Improvements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dataset Size: The Allanatrix/Scientific_Research_Tokenized dataset may be small, as evidenced by the quick training (2 steps in the output). For real-world applications, you’d need a larger dataset or a custom streaming loader.&lt;/li&gt;
&lt;li&gt;Custom Batching: Implementing the 100M/30M token strategy requires a custom data loader, which could be added using PyTorch’s IterableDataset.&lt;/li&gt;
&lt;li&gt;Warnings: The notebook includes deprecated arguments (dataset_text_field, max_seq_length) in SFTTrainer. Future versions should use SFTConfig to avoid warnings.&lt;/li&gt;
&lt;li&gt;Evaluation: The notebook focuses on training but lacks an evaluation step. Adding a validation dataset and metrics like perplexity would improve model assessment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to Run the Notebook&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Environment Setup:&lt;/li&gt;
&lt;li&gt;Use a Kaggle notebook with a Tesla T4 GPU or a Colab instance with a similar GPU.&lt;/li&gt;
&lt;li&gt;Add your Hugging Face token to Kaggle Secrets as HF_TOKEN.&lt;/li&gt;
&lt;li&gt;Dependencies:&lt;/li&gt;
&lt;li&gt;The notebook installs all required libraries. Ensure you restart the kernel if prompted.&lt;/li&gt;
&lt;li&gt;Execution:&lt;/li&gt;
&lt;li&gt;Run the cells sequentially. The main() function handles the entire workflow.&lt;/li&gt;
&lt;li&gt;Output:&lt;/li&gt;
&lt;li&gt;Artifacts (model weights, tokenizer, configs) are saved to /kaggle/working/artifacts.&lt;/li&gt;
&lt;li&gt;Training logs are available in TensorBoard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This notebook provides a robust and reproducible framework for fine-tuning Mistral-7B on a scientific research dataset. By leveraging LoRA, 4-bit quantization, and a modular design, it makes fine-tuning accessible on modest hardware. Whether you’re adapting LLMs for scientific research or another domain, this guide offers a solid foundation to build upon. Future enhancements could include larger datasets, custom batching, and evaluation metrics to further refine the model.&lt;br&gt;
Feel free to fork the notebook, experiment with your own datasets, and share your results! If you have questions or improvements, drop them in the comments below. &lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
Mistral-7B on Hugging Face: &lt;a href="https://huggingface.co/Allanatrix/Nexa-Mistral-Sci7b" rel="noopener noreferrer"&gt;https://huggingface.co/Allanatrix/Nexa-Mistral-Sci7b&lt;/a&gt;&lt;br&gt;
Scientific Research Dataset:&lt;a href="https://huggingface.co/datasets/Allanatrix/Scientific_Research_Tokenized" rel="noopener noreferrer"&gt;https://huggingface.co/datasets/Allanatrix/Scientific_Research_Tokenized&lt;/a&gt;&lt;br&gt;
Github repo with notebook: &lt;a href="https://github.com/DarkStarStrix/Nexa_Auto" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/Nexa_Auto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy fine-tuning! 🚀&lt;/p&gt;

</description>
      <category>programming</category>
      <category>machinelearning</category>
      <category>llm</category>
      <category>lora</category>
    </item>
    <item>
      <title>How I Shipped 95,000 Proteins in Under 5 Minutes: Building a Scalable Inference Engine for Scientific ML</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 23 Jun 2025 20:53:37 +0000</pubDate>
      <link>https://dev.to/darkstalker/how-i-shipped-95000-proteins-in-under-5-minutes-building-a-scalable-inference-engine-for-3kll</link>
      <guid>https://dev.to/darkstalker/how-i-shipped-95000-proteins-in-under-5-minutes-building-a-scalable-inference-engine-for-3kll</guid>
      <description>&lt;p&gt;Scientific machine learning is one of the most important fields of the next decade — but its tooling is still clunky, inconsistent, and painfully slow. Researchers in biology, materials science, and physics often don’t have the infrastructure or time to build robust, scalable inference systems that can generate real results fast.&lt;/p&gt;

&lt;p&gt;So I built one.&lt;/p&gt;

&lt;p&gt;It’s called Lambda Inference, and it’s a multi-domain inference engine optimized for high-throughput, low-latency prediction. In one session, I used it to generate and infer 95,000 protein sequences in under five minutes. This blog post explains how I did it — from the architecture and tech stack down to the specific function that made it all possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built It
&lt;/h2&gt;

&lt;p&gt;This started from a core frustration: scientific ML tasks — like predicting protein structures or material properties — are powerful in theory but painfully fragmented in practice. There’s no centralized way to plug in domain-specific inputs and receive confidence-ranked predictions from a preloaded, trained model. Tools exist, but they’re scattered across legacy codebases or buried in papers and internal scripts.&lt;/p&gt;

&lt;p&gt;I wanted something simple: an engine I could call with scientific input and get a fast, structured, inference-ready output. I wanted it for proteins, for materials, and for astrophysics. So I built it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Inference Works
&lt;/h2&gt;

&lt;p&gt;At the heart of the protein pipeline is a simple function that combines generation and prediction. Here’s a minimal example (stripped down for clarity):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random

AMINO_ACIDS = "ACDEFGHIKLMNPQRSTVWY"

def generate_protein_sequence(length=12):
    return ''.join(random.choices(AMINO_ACIDS, k=length))

def predict_structure(model, sequence, threshold=0.8):
    pred = model.predict({"sequence": sequence})
    confidence = pred.get("confidence", 0)
    if confidence &amp;gt;= threshold:
        return {"sequence": sequence, "structure": pred["structure"], "confidence": confidence}
    return None

def generate_and_infer(model, num_sequences=100000):
    outputs = []
    for _ in range(num_sequences):
        seq = generate_protein_sequence()
        result = predict_structure(model, seq)
        if result:
            outputs.append(result)
    return outputs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This basic loop, with some threading and GPU optimization, was enough to produce and filter 95,000 sequences in under five minutes. Results were written in Arrow format, compressed, and uploaded to Hugging Face under the Nexa ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Components I Used
&lt;/h2&gt;

&lt;p&gt;Here’s a breakdown of the actual tech stack I used in production:&lt;/p&gt;

&lt;p&gt;FastAPI for REST endpoints across /bio, /astro, and /materials&lt;/p&gt;

&lt;p&gt;PyTorch for running all model inference (models loaded into memory once)&lt;/p&gt;

&lt;p&gt;Docker for containerization and portability&lt;/p&gt;

&lt;p&gt;Arrow + Pandas for fast serialization of large outputs&lt;/p&gt;

&lt;p&gt;Redis + Postgres for caching and request logging&lt;/p&gt;

&lt;p&gt;Plotly + Streamlit (via LambdaViz) for rendering 3D structures&lt;/p&gt;

&lt;p&gt;Hugging Face Spaces to make everything accessible from a browser&lt;/p&gt;

&lt;p&gt;Everything was orchestrated locally on a T4 GPU instance, with CPU threading for sequence generation and filtering.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the Minimal Tech You Actually Need?
&lt;/h2&gt;

&lt;p&gt;If you want to build a barebones scientific inference engine like this, here’s the absolute minimum:&lt;/p&gt;

&lt;p&gt;A trained model checkpoint (PyTorch or ONNX)&lt;/p&gt;

&lt;p&gt;A Python prediction function (like above) that can handle inputs and return outputs + confidence&lt;/p&gt;

&lt;p&gt;A simple script to loop through inputs, run inference, and filter by confidence&lt;/p&gt;

&lt;p&gt;FastAPI (or Flask) to expose a REST API if needed&lt;/p&gt;

&lt;p&gt;Arrow (or CSV/JSON) for storing the results&lt;/p&gt;

&lt;p&gt;You can run this entire system on:&lt;/p&gt;

&lt;p&gt;1 GPU-enabled machine (T4, A10, or even CPU if small)&lt;/p&gt;

&lt;p&gt;A single Docker container&lt;/p&gt;

&lt;p&gt;Less than 2GB RAM usage during inference&lt;/p&gt;

&lt;p&gt;No frontend — just curl or Python scripts calling the API&lt;/p&gt;

&lt;p&gt;And you can build and deploy that in a weekend.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the Results Show
&lt;/h2&gt;

&lt;p&gt;This was more than a benchmark — it was a signal. When you combine model inference with fast data generation and thoughtful engineering, you don’t need a 10-person team to ship valuable scientific assets.&lt;/p&gt;

&lt;p&gt;I shipped:&lt;/p&gt;

&lt;p&gt;95,000 protein structures&lt;/p&gt;

&lt;p&gt;In under 300 seconds&lt;/p&gt;

&lt;p&gt;With confidence filtering&lt;/p&gt;

&lt;p&gt;Structured in training-ready format&lt;/p&gt;

&lt;p&gt;And I did it with a single model, a single machine, and ~150 lines of core logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Inference isn’t just a backend process — it’s the beginning of what enables researchers to test ideas, run simulations, and fine-tune models on real-world scientific problems. Without fast inference infra, everything breaks: training becomes slower, data pipelines get blocked, and your modeling loop stalls out.&lt;/p&gt;

&lt;p&gt;What I’ve built with Lambda Inference is one layer of a much larger mission: to build the infrastructure for high-quality, domain-specific scientific ML at scale.&lt;/p&gt;

&lt;p&gt;This engine now supports biological predictions, materials property estimation, and stellar astrophysics regressors. More models are being added. And with each domain, the same philosophy applies: serve structured, validated predictions fast and let researchers focus on science — not sysadmin work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;You can try the engine or use the protein dataset:&lt;/p&gt;

&lt;p&gt;Lambda Inference (HF Demo)&lt;/p&gt;

&lt;p&gt;95K Protein Dataset on Hugging Face&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Note
&lt;/h2&gt;

&lt;p&gt;If you're a researcher, startup, or lab working in a domain that could benefit from plug-and-play ML inference — reach out. I build custom datasets, fine-tuned models, and deployable inference pipelines.&lt;/p&gt;

&lt;p&gt;This was just one experiment. But the goal is bigger: to make scientific machine learning feel like productized software — fast, elegant, useful.&lt;/p&gt;

&lt;p&gt;Let’s build it.&lt;br&gt;
link to the repo for more deatils:&lt;br&gt;
&lt;a href="https://github.com/DarkStarStrix/Lambda_Inference" rel="noopener noreferrer"&gt;https://github.com/DarkStarStrix/Lambda_Inference&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>machinelearning</category>
      <category>science</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>From Pixels to Predictions: Building Your First ML Classifier A dev-friendly intro to image classification using deep learning.</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Tue, 10 Jun 2025 01:00:02 +0000</pubDate>
      <link>https://dev.to/darkstalker/from-pixels-to-predictions-building-your-first-ml-classifier-a-dev-friendly-intro-to-image-2gga</link>
      <guid>https://dev.to/darkstalker/from-pixels-to-predictions-building-your-first-ml-classifier-a-dev-friendly-intro-to-image-2gga</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Machine learning isn’t magic. It’s just math applied with care."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you've ever wondered how an app can look at a picture and decide whether it's a dog or not welcome. This post is a gentle but thorough walkthrough of how you'd actually build a simple image classifier.&lt;/p&gt;

&lt;p&gt;We’ll also sprinkle in a few mental models, best practices, and resources so you build good priors for your ML journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Frame the Problem
&lt;/h2&gt;

&lt;p&gt;We want to answer: "Given an image, is this a dog?"&lt;/p&gt;

&lt;p&gt;That’s a binary classification problem. We're not trying to recognize the breed, or count how many dogs just yes or no.&lt;/p&gt;

&lt;p&gt;This is a supervised learning task: the model learns from labeled examples ("dog" / "not dog").&lt;/p&gt;

&lt;p&gt;ML Tip: Ask yourself is this binary, multiclass, or multilabel? Are labels ambiguous? What kind of mistakes do you care about more?&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Get and Understand the Data
&lt;/h2&gt;

&lt;p&gt;You can’t train a model without good data.&lt;/p&gt;

&lt;p&gt;Use a dataset like:&lt;br&gt;
Stanford Dogs Dataset&lt;br&gt;
Kaggle Dogs vs. Cats&lt;/p&gt;

&lt;p&gt;Clean it up:&lt;br&gt;
Resize images&lt;br&gt;
Normalize pixel values&lt;br&gt;
Make sure you have balanced examples (dogs and non-dogs)&lt;/p&gt;

&lt;p&gt;Split into:&lt;br&gt;
Train (e.g. 70%)&lt;br&gt;
Validation (15%)&lt;br&gt;
Test (15%)&lt;/p&gt;

&lt;p&gt;Data is the real currency of ML. Always treat it with respect.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Choose a Model
&lt;/h2&gt;

&lt;p&gt;We need a model that works well on images. Enter: Convolutional Neural Networks (CNNs).&lt;/p&gt;

&lt;p&gt;To keep it simple, use transfer learning:&lt;br&gt;
Load a pretrained CNN (e.g., ResNet-18)&lt;br&gt;
Replace the final layer&lt;br&gt;
Fine-tune it on your dataset&lt;/p&gt;

&lt;p&gt;PyTorch makes this easy:&lt;br&gt;
import torchvision.models as models&lt;br&gt;
model = models.resnet18(pretrained=True)&lt;br&gt;
model.fc = nn.Linear(model.fc.in_features, 1)  # Binary classifier&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Train the Model
&lt;/h2&gt;

&lt;p&gt;Use Binary Cross-Entropy Loss&lt;br&gt;
Optimizer: Adam (lr=1e-4)&lt;br&gt;
Batch size: 32 or 64&lt;br&gt;
Train for 10–20 epochs&lt;/p&gt;

&lt;p&gt;Log:&lt;br&gt;
Loss&lt;br&gt;
Accuracy&lt;br&gt;
Precision/Recall/F1&lt;br&gt;
Use early stopping and save the best model.&lt;/p&gt;

&lt;p&gt;Training is where your model learns, but evaluation is where you learn.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Evaluate and Improve
&lt;/h2&gt;

&lt;p&gt;Don't just look at accuracy. Dive deeper:&lt;br&gt;
Confusion matrix&lt;br&gt;
Precision/Recall&lt;br&gt;
Examples it got wrong (and why!)&lt;/p&gt;

&lt;p&gt;Create a test set with edge cases:&lt;br&gt;
Dogs in costumes&lt;br&gt;
Blurry images&lt;br&gt;
Not-quite-a-dog images (foxes, wolves, etc.)&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 6: Deploy the Model
&lt;/h2&gt;

&lt;p&gt;Use something like FastAPI:&lt;br&gt;
Load the trained model&lt;/p&gt;

&lt;p&gt;Create an endpoint: /predict&lt;br&gt;
Accept image uploads&lt;br&gt;
Return prediction: yes/no + confidence&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "input": "dog.jpg",
  "output": {
    "class": "dog",
    "confidence": 0.94
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bonus: Dockerize it, add logging, and boom — you've got an ML microservice.&lt;/p&gt;

&lt;p&gt;Mental Models for ML&lt;/p&gt;

&lt;p&gt;"Bad data beats good models." Clean your data.&lt;br&gt;
"All models are wrong, some are useful." Focus on real-world value.&lt;br&gt;
"Every ML model is a hypothesis." Validate it against reality.&lt;/p&gt;

&lt;p&gt;Continue Learning&lt;br&gt;
If you're excited to go deeper, here are some curated resources:&lt;/p&gt;

&lt;p&gt;Foundational&lt;br&gt;
Deep Learning with PyTorch (free book):&lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=b95a304773387304460e4addd2d0d3061188c99a88cf69fc3c4060a16a5a1d4eJmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Deep+Learning+with+PyTorch&amp;amp;u=a1aHR0cHM6Ly93d3cubGVhcm5weXRvcmNoLmlvLw&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=b95a304773387304460e4addd2d0d3061188c99a88cf69fc3c4060a16a5a1d4eJmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Deep+Learning+with+PyTorch&amp;amp;u=a1aHR0cHM6Ly93d3cubGVhcm5weXRvcmNoLmlvLw&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C0S231n: Convolutional Neural Networks for Visual Recognition&lt;br&gt;
Practical: &lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=abb2ed38507c82f845bab881da4858194c16f0c26d1ca28ed4ca061d16f4f246JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=C0S231n%3a+Convolutional+Neural+Networks+for+Visual+Recognition+Practical&amp;amp;u=a1aHR0cHM6Ly9jczIzMW4uc3RhbmZvcmQuZWR1Lw&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=abb2ed38507c82f845bab881da4858194c16f0c26d1ca28ed4ca061d16f4f246JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=C0S231n%3a+Convolutional+Neural+Networks+for+Visual+Recognition+Practical&amp;amp;u=a1aHR0cHM6Ly9jczIzMW4uc3RhbmZvcmQuZWR1Lw&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;fast.ai's Practical Deep Learning: &lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=555d78b7e1231143e269ce360005c8f207d3c261ef88ee5043e2daa2136b378aJmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=fast.ai%27s+Practical+Deep+Learning&amp;amp;u=a1aHR0cHM6Ly9jb3Vyc2UuZmFzdC5haS8&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=555d78b7e1231143e269ce360005c8f207d3c261ef88ee5043e2daa2136b378aJmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=fast.ai%27s+Practical+Deep+Learning&amp;amp;u=a1aHR0cHM6Ly9jb3Vyc2UuZmFzdC5haS8&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kaggle Learn: Computer Vision:&lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=dfe4d5b9f4f515e41c5ef93e0e8617bc67e89e4985b1b1210282cff8d7489f64JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Kaggle+Learn%3a+Computer+Vision+&amp;amp;u=a1aHR0cHM6Ly93d3cua2FnZ2xlLmNvbS9sZWFybi9jb21wdXRlci12aXNpb24&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=dfe4d5b9f4f515e41c5ef93e0e8617bc67e89e4985b1b1210282cff8d7489f64JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Kaggle+Learn%3a+Computer+Vision+&amp;amp;u=a1aHR0cHM6Ly93d3cua2FnZ2xlLmNvbS9sZWFybi9jb21wdXRlci12aXNpb24&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Papers with Code – Image Classification: &lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=23f1094ad7f47bdc825716ee4fa1585f249318f01941d9f4e474e02967984c48JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Papers+with+Code+%e2%80%93+Image+Classification&amp;amp;u=a1aHR0cHM6Ly9wYXBlcnN3aXRoY29kZS5jb20vdGFzay9pbWFnZS1jbGFzc2lmaWNhdGlvbg&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=23f1094ad7f47bdc825716ee4fa1585f249318f01941d9f4e474e02967984c48JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Papers+with+Code+%e2%80%93+Image+Classification&amp;amp;u=a1aHR0cHM6Ly9wYXBlcnN3aXRoY29kZS5jb20vdGFzay9pbWFnZS1jbGFzc2lmaWNhdGlvbg&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Distill.pub – Understanding Neural Networkshttps://&lt;a href="http://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=6fe476bbb2ab923280fe0db4ee1734aaa5d5bf6ce662b6348b1c59e3ca5a4234JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Distill.pub+%e2%80%93+Understanding+Neural+Networks&amp;amp;u=a1aHR0cHM6Ly9kaXN0aWxsLnB1Yi8yMDIxL2dubi1pbnRyby8&amp;amp;ntb=1" rel="noopener noreferrer"&gt;www.bing.com/ck/a?!&amp;amp;&amp;amp;p=6fe476bbb2ab923280fe0db4ee1734aaa5d5bf6ce662b6348b1c59e3ca5a4234JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=Distill.pub+%e2%80%93+Understanding+Neural+Networks&amp;amp;u=a1aHR0cHM6Ly9kaXN0aWxsLnB1Yi8yMDIxL2dubi1pbnRyby8&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Visual Intro to ML: &lt;a href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=98c6efc8a7ef7a95069de441e56c9f510fceec87fe54dbe923d95f31d808ed26JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=A+Visual+Intro+to+ML&amp;amp;u=a1aHR0cDovL3d3dy5yMmQzLnVzL3Zpc3VhbC1pbnRyby10by1tYWNoaW5lLWxlYXJuaW5nLXBhcnQtMS8&amp;amp;ntb=1" rel="noopener noreferrer"&gt;https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=98c6efc8a7ef7a95069de441e56c9f510fceec87fe54dbe923d95f31d808ed26JmltdHM9MTc0OTQyNzIwMA&amp;amp;ptn=3&amp;amp;ver=2&amp;amp;hsh=4&amp;amp;fclid=11f78f6f-4226-66ca-395a-9afb432267e8&amp;amp;psq=A+Visual+Intro+to+ML&amp;amp;u=a1aHR0cDovL3d3dy5yMmQzLnVzL3Zpc3VhbC1pbnRyby10by1tYWNoaW5lLWxlYXJuaW5nLXBhcnQtMS8&amp;amp;ntb=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TL;DR&lt;br&gt;
Step:&lt;br&gt;
What You Do&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Define the problem (classification? regression?)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get clean, labeled data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose a model (CNNs + transfer learning)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Train and evaluate rigorously&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;5.Deploy with a web API&lt;/p&gt;

&lt;p&gt;Final Thought&lt;br&gt;
Learning ML is a journey — one where the map is fuzzy, but the destination is worth it. Start simple, stay curious, and keep shipping things that work.&lt;/p&gt;

&lt;p&gt;If this helped you, consider following me for more ML breakdowns and engineering insights. Questions or feedback? Drop them in the comments!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Building a Scalable Scientific LLM Pipeline: From Raw Data to Hugging Face</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Fri, 06 Jun 2025 19:59:13 +0000</pubDate>
      <link>https://dev.to/darkstalker/building-a-scalable-scientific-llm-pipeline-from-raw-data-to-hugging-face-183d</link>
      <guid>https://dev.to/darkstalker/building-a-scalable-scientific-llm-pipeline-from-raw-data-to-hugging-face-183d</guid>
      <description>&lt;p&gt;In the fast-evolving world of AI, domain-specific language models are unlocking new possibilities for scientific discovery. I’ve built an 882-line Python pipeline, Main_2.py, that transforms raw academic data into a clean, tokenized corpus for training models like NEXA-MOE-MINI, a 110 million parameter Mixture-of-Experts (MoE) model tailored for physics, biology, and materials science. This post dives into the stack’s architecture, its key features, and how it empowers scientific AI—from data generation to public sharing on Hugging Face. Whether you’re building LLMs or just curious about scientific AI, let’s explore how this pipeline works and how you can adapt it for your own projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Pipeline Matters
&lt;/h2&gt;

&lt;p&gt;General-purpose LLMs like GPT-4 excel at broad tasks but often falter in specialized domains where precision and context are critical. For scientific tasks like generating hypotheses or designing methodologies, you need high-quality, domain-specific datasets and models optimized for those niches. My pipeline addresses this by:&lt;/p&gt;

&lt;p&gt;Curating a ~325M token scientific corpus from arXiv, PubMed, and FineWeb-Edu.&lt;br&gt;
Distilling raw data into instruction-ready formats for tasks like hypothesis generation.&lt;br&gt;
Training a sparse MoE model with domain-specialized experts.&lt;br&gt;
Sharing the dataset publicly on Hugging Face for reproducibility and collaboration.&lt;/p&gt;

&lt;p&gt;This isn’t a one-off script—it’s a reusable “research OS” for scientific AI, built with minimal resources and designed to scale.&lt;/p&gt;

&lt;p&gt;The Stack: A Technical Deep Dive&lt;br&gt;
The pipeline integrates data generation, model training, and dataset sharing into a modular, end-to-end system. Here’s how it breaks down:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data Generation Engine (main2.py)
The core is an 882-line Python script that builds a scientific corpus from academic sources. Its key components are:&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Data Sources:
&lt;/h2&gt;

&lt;p&gt;arXiv: Fetches up to 9,000 papers using the arxiv library, querying subcategories like physics* (astrophysics, quantum physics), q-bio* (biology), and cond-mat.mtrl-sci (materials science). Collects metadata: titles, abstracts, authors, publication dates, and arXiv IDs.&lt;br&gt;
PubMed: Retrieves 3,000 biology abstracts via Biopython’s Entrez API, using MeSH-based queries (e.g., (methods[Title/Abstract]) AND (biology[MeSH Terms])). Returns titles, abstracts, and PMIDs.&lt;br&gt;
FineWeb-Edu: Streams 30,000 samples from Hugging Face’s FineWeb-Edu dataset (sample-10BT, train split), selecting explanatory educational content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preprocessing Pipeline:
&lt;/h2&gt;

&lt;p&gt;Cleaning: Normalizes text with clean_text, removing special characters, redundant whitespace, and boilerplate (e.g., acknowledgments).&lt;br&gt;
Segmentation: Splits full-text into paragraphs using segment_paragraphs, preserving semantic coherence.&lt;br&gt;
Tokenization: Converts text into tokens with QLoRAPreprocessor, optimized for scientific vocabulary and MoE training.&lt;br&gt;
Semantic Tagging: Assigns metadata labels:&lt;/p&gt;

&lt;p&gt;Domain Tags: [PHYS], [BIO], [MAT] for physics, biology, materials science.&lt;br&gt;
Task Tags: [HYP], [MTH], [EXP] for hypothesis, methodology, experiment tasks.&lt;br&gt;
Routing Tags: [GEN] for general routing, &lt;a href="//e.g.,%20[SPEC:Astrophysics]"&gt;SPEC:&lt;/a&gt; for specialized routing.&lt;/p&gt;

&lt;p&gt;Entropy-Based Filtering: Uses EntropyRanker to compute Shannon entropy &lt;br&gt;
for each sample, discarding low-information content. Distills ~500M raw tokens into ~325M clean tokens, plus ~300k instruction-format samples for hypothesis/methodology tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output Formats:
&lt;/h2&gt;

&lt;p&gt;JSONL (~15GB): Line-delimited JSON objects, each with fields like title, abstract, full_text, domain_tag, and provenance. Ideal for debugging and analysis.&lt;br&gt;
Arrow (~3.13GB): Compressed columnar format, sharded (500MB max per shard) for ML frameworks like Hugging Face Datasets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Efficiency:
&lt;/h2&gt;

&lt;p&gt;Processes data in chunks (default: 1,000 samples) to manage memory.&lt;br&gt;
Parallelizes filtering with concurrent.futures.ThreadPoolExecutor (8 workers default).&lt;br&gt;
Saves checkpoints (e.g., arxiv_papers.jsonl) for fault tolerance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scalability:
&lt;/h2&gt;

&lt;p&gt;Modular design supports new sources (e.g., Semantic Scholar) and larger corpora (up to 650M tokens for future models like ULTRAMAX). Configurable via CorpusConfig (e.g., max_arxiv_papers=9000, max_workers=8).&lt;/p&gt;

&lt;p&gt;Example Output (JSONL Line):&lt;br&gt;
&lt;code&gt;jsonCollapseWrapCopy{&lt;br&gt;
  "title": "Quantum Entanglement in Black Holes",&lt;br&gt;
  "abstract": "We explore quantum entanglement properties...",&lt;br&gt;
  "domain_tag": "[PHYS]",&lt;br&gt;
  "section_tag": "[ABSTRACT]",&lt;br&gt;
  "task_tag": "[HYP]",&lt;br&gt;
  "routing_tag": "[SPEC:QuantumPhysics]",&lt;br&gt;
  "provenance": {"arxiv_id": "2305.12345"}&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Automated Upload Tooling (hf_upload.py)
The uploader script shares the corpus on Hugging Face, ensuring accessibility and reproducibility:&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Compression:
&lt;/h2&gt;

&lt;p&gt;Converts JSONL to Arrow using datasets.Dataset.from_json and save_to_disk, reducing size from ~15GB to ~3.13GB.&lt;br&gt;
Large File Handling:&lt;/p&gt;

&lt;p&gt;Splits files &amp;gt;10MB into ~10MB chunks for Git LFS compatibility.&lt;br&gt;
Tracks files with git lfs track "*.jsonl", *.arrow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic README:
&lt;/h2&gt;

&lt;p&gt;Generates a README.md with metadata (sources, token count, formats), ensuring Hugging Face compliance.&lt;br&gt;
Hugging Face Integration:&lt;/p&gt;

&lt;p&gt;Uses huggingface_hub.HfApi and Repository to manage Allanatrix/Scientific_Research_Tokenized.&lt;br&gt;
Implements retries (max: 3, 30s backoff) for network failures, addressing issues on a 1 Gbit/s Ethernet.&lt;br&gt;
Supports resumable uploads via Git LFS.&lt;br&gt;
Commits with versioned messages (e.g., Upload dataset 2025-06-06T15:41:00).&lt;/p&gt;

&lt;h2&gt;
  
  
  Error Handling:
&lt;/h2&gt;

&lt;p&gt;Validates tokens with HfApi.whoami.&lt;br&gt;
Catches HTTPError, URLError, OSError, and cleans up temporary chunks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future Plans:
&lt;/h2&gt;

&lt;p&gt;Offload uploads to a cloud-based backend to bypass local network constraints.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example README Snippet:
&lt;/h2&gt;

&lt;p&gt;markdownCollapseWrapCopy&lt;/p&gt;

&lt;h2&gt;
  
  
  Scientific Research Tokenized
&lt;/h2&gt;

&lt;p&gt;This dataset contains ~325M tokens (~300k samples) for scientific ML tasks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sources: arXiv, PubMed, FineWeb-Edu&lt;/li&gt;
&lt;li&gt;Formats: JSONL, Arrow&lt;/li&gt;
&lt;li&gt;NEXA-MOE-MINI Training
The pipeline trains NEXA-MOE-MINI, a 110M parameter MoE model, as the first in a family of scientific LLMs:&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture:
&lt;/h2&gt;

&lt;p&gt;Four experts: BERT-based router (~110M parameters, shared layers) and three T5-based specialists (~60M each) for biology, physics, materials science.&lt;br&gt;
Soft routing with top-k selection (k=1), driven by semantic tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Training:
&lt;/h2&gt;

&lt;p&gt;Fine-tunes with QLoRA (4-bit/8-bit quantization, adapter layers) on ~325M tokens (~300k instructions).&lt;br&gt;
Hardware: Intel i5 vPro (1.9–6.0 GHz, 16GB RAM), dual NVIDIA T4 GPUs (16GB VRAM).&lt;br&gt;
Optimizations: Mixed precision (FP16/BF16), gradient checkpointing, torch.distributed for tensor parallelism.&lt;br&gt;
Optimizers: Adam (Optuna-tuned), transitioning to AzureSky Optimizer (Stochastic Approximation + Adam hybrid) with RL fine-tuning.&lt;br&gt;
Stages:&lt;/p&gt;

&lt;p&gt;Easy: Basic STEM problems (e.g., physics equations).&lt;br&gt;
Moderate: Complex tasks (e.g., astrophysics simulations).&lt;br&gt;
Hard: Multi-step reasoning (e.g., CFD + alloy modeling).&lt;br&gt;
Metrics: ~21 GFLOPS 60% utilization on 2 T4 GPU's&lt;/p&gt;

&lt;p&gt;Output: Weights in .pt or .onnx, versioned for traceability.&lt;br&gt;
Tasks: Hypothesis generation, methodology design, literature summarization.&lt;br&gt;
Role: Distiller for reasoning/retrieval, bootstrap for larger models.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Full Pipeline: A Research OS
The stack integrates:
Data Generation: Modular, extensible to new sources.
Training Infra: Plug-and-play expert swapping, dynamic routing.
Sharing: Public datasets/models on Hugging Face.
Compute:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;CPU: Intel i5 vPro for preprocessing.&lt;br&gt;
GPU: Dual T4s for training/inference.&lt;br&gt;
Software: PyTorch, Hugging Face Transformers, Biopython, arxiv.&lt;/p&gt;

&lt;p&gt;Metrics:&lt;br&gt;
Processes ~500M tokens in ~10–12 hours.&lt;br&gt;
Trains 110M parameters in ~40 hours (Kaggle GPU).&lt;br&gt;
Uploads ~3.13GB in ~1–2 hours.&lt;/p&gt;

&lt;p&gt;Roadmap:&lt;br&gt;
NEXA-COD: Chain-of-thought model, ~425–500M tokens.&lt;br&gt;
SCOUT: Exploratory reasoning for novel hypotheses.&lt;br&gt;
ULTRAMAX: 2.2B parameters, 20,000-token context, ~600–650M tokens.&lt;/p&gt;

&lt;p&gt;Key Features in Action&lt;br&gt;
Modularity: Add new sources (e.g., OpenAlex) by updating CorpusConfig and queries.&lt;/p&gt;

&lt;p&gt;Resilience:&lt;br&gt;
Retries API failures with exponential backoff.&lt;br&gt;
Saves checkpoints to recover from crashes.&lt;br&gt;
Handles interrupts (SIGINT/SIGTERM) gracefully.&lt;/p&gt;

&lt;p&gt;Efficiency:&lt;br&gt;
Chunks data (1,000 samples) to manage memory.&lt;br&gt;
Parallelizes filtering with 8 workers.&lt;/p&gt;

&lt;p&gt;Quality:&lt;br&gt;
Filters low-value content with EntropyRanker.&lt;br&gt;
Tags samples for precise MoE routing.&lt;br&gt;
Example Workflow&lt;/p&gt;

&lt;p&gt;Generate the Corpus:&lt;br&gt;
bashCollapseWrapRunCopyexport ENTREZ_EMAIL="&lt;a href="mailto:your.email@example.com"&gt;your.email@example.com&lt;/a&gt;"&lt;br&gt;
python main2.py&lt;br&gt;
Output: scientific_corpus_325M.jsonl (~15GB).&lt;br&gt;
Upload to Hugging Face:&lt;br&gt;
bashCollapseWrapRunCopypython hf_upload.py&lt;br&gt;
Enter your Hugging Face token, and the script compresses to Arrow (~3.13GB), splits large files, and uploads to Allanatrix/Scientific_Research_Tokenized.&lt;br&gt;
Train NEXA-MOE-MINI:&lt;br&gt;
Use the dataset to fine-tune the MoE model with QLoRA:&lt;br&gt;
pythonCollapseWrapRunCopyfrom transformers import Trainer, TrainingArguments&lt;br&gt;
trainer = Trainer(model=moe_model, train_dataset=dataset)&lt;br&gt;
trainer.train()&lt;/p&gt;

&lt;p&gt;Share Results:&lt;br&gt;
Publish model weights and dataset on Hugging Face.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Report:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;============================================================
           SCIENTIFIC CORPUS BUILD REPORT
============================================================
SOURCE METRICS:
----------------------------------------
ARXIV          :  9000 papers |   2 errors |    120.50s
PUBMED         :  3000 papers |   1 errors |     80.30s
FINEWEB_EDU    : 15000 papers |   3 errors |    200.75s
OVERALL METRICS:
----------------------------------------
Total Papers:     27,000
Total Tokens:     324,500,000
Total Time:       401.55s
Success Rate:     99.98%
============================================================
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Challenges and Solutions
&lt;/h2&gt;

&lt;p&gt;Git LFS Bottlenecks: Uploading ~3.13GB on a 1 Gbit/s Ethernet faced errors. Solution: Split files into ~10MB chunks and retry with backoff. Future: Cloud-based backend.&lt;br&gt;
Data Quality: Tuning EntropyRanker thresholds balanced precision/recall for high-signal data.&lt;br&gt;
Compute Limits: Training on modest hardware (Intel i5, T4 GPUs) required 4-bit quantization, mixed precision, and gradient checkpointing.&lt;/p&gt;

&lt;p&gt;Why It’s Exciting&lt;br&gt;
This pipeline unlocks:&lt;br&gt;
Rapid Prototyping: Build datasets for any scientific domain in hours.&lt;br&gt;
Specialized Models: Train MoEs for niche tasks like hypothesis generation.&lt;br&gt;
Community Impact: Share high-quality datasets/models publicly.&lt;br&gt;
Scalability: Ready for billion-parameter models and massive corpora.&lt;/p&gt;

&lt;p&gt;It’s a foundation for accelerating scientific discovery with AI, built with no institutional support.&lt;/p&gt;

&lt;p&gt;Get Involved: &lt;a href="https://dev.tourl"&gt;https://github.com/DarkStarStrix/DataVolt/blob/master/Tokenization/Main_2.py&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dataengineering</category>
      <category>opensource</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>How I Build: Stateless Engineering for Deep Work and Rapid Progress</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Tue, 27 May 2025 01:48:51 +0000</pubDate>
      <link>https://dev.to/darkstalker/how-i-build-stateless-engineering-for-deep-work-and-rapid-progress-4eco</link>
      <guid>https://dev.to/darkstalker/how-i-build-stateless-engineering-for-deep-work-and-rapid-progress-4eco</guid>
      <description>&lt;p&gt;This post isn’t about an app or a product. It’s about how I work — the structure, mindset, and engineering process I use to consistently build and ship complex systems across domains like machine learning, HPC, and scientific computing.&lt;/p&gt;

&lt;p&gt;⸻&lt;/p&gt;

&lt;p&gt;The Core Idea: Build for Your Future Self&lt;/p&gt;

&lt;p&gt;Everything I build is designed so that I can drop it today and return to it days (or weeks) later without friction.&lt;br&gt;
• Notebook layout is standardized&lt;br&gt;
• Inputs at the top&lt;br&gt;
• Functions in the middle&lt;br&gt;
• Main loop at the bottom&lt;br&gt;
• Dev journal captures intent&lt;br&gt;
Every notebook is paired with a journal entry outlining the purpose, constraints, and next steps. This ensures that even if I step away, I can re-enter the flow quickly.&lt;br&gt;
• Zero boot-up time&lt;br&gt;
My system is designed to be picked up mid-stream. I can be in deep work for 4–5 hours, walk away, and return days later without losing momentum.&lt;/p&gt;

&lt;p&gt;⸻&lt;/p&gt;

&lt;p&gt;My Feedback Loop&lt;/p&gt;

&lt;p&gt;My workflow is built around tight engineering loops optimized for speed, clarity, and intent.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set a crystal-clear goal
For example: “Tune optimizer X to match performance of optimizer Y on a custom task under specific constraints.”&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ingest and contextualize information&lt;br&gt;
Read papers, telemetry, logs — only what’s relevant to the current goal. Discard noise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Frame constraints and bottlenecks&lt;br&gt;
Whether it’s compute ceilings, memory pressure, or time budget — all decisions are grounded in resource realities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy tools with intent&lt;br&gt;
Tools like Optuna, LoRA, and Perf aren’t magic bullets. They’re applied precisely, based on bottlenecks surfaced in telemetry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate in-place&lt;br&gt;
No rewrites. No restarts. I evolve the existing pipeline. Each iteration builds directly on the last.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate and reflect&lt;br&gt;
Every result flows through one question: Did this get me closer to the goal? If yes, refine. If no, rethink.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;⸻&lt;/p&gt;

&lt;p&gt;Why It Works&lt;/p&gt;

&lt;p&gt;This system is:&lt;br&gt;
• Stateless — I can resume work anywhere, anytime&lt;br&gt;
• Portable — Cloud-synced and modular, built to run across devices&lt;br&gt;
• Efficient — Built once, reused across multiple domains&lt;br&gt;
• Maintainable — Future-proofed with clean code and clear intentions&lt;/p&gt;

&lt;p&gt;Most importantly, it’s goal-first. I don’t experiment blindly — I aim, execute, and adjust.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Reconsidering DSA in Tech Hiring: A Builder’s Perspective</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 19 May 2025 16:47:29 +0000</pubDate>
      <link>https://dev.to/darkstalker/reconsidering-dsa-in-tech-hiring-a-builders-perspective-1km1</link>
      <guid>https://dev.to/darkstalker/reconsidering-dsa-in-tech-hiring-a-builders-perspective-1km1</guid>
      <description>&lt;p&gt;Have you ever spent hours grinding LeetCode, only to wonder: Is this what software engineering is really about? Data structures and algorithms (DSA) dominate tech hiring, especially at big tech companies. They’re a measurable way to test coding skills, logic, and problem-solving under pressure. But as someone who’s been through the DSA gauntlet and come out the other side, I’m starting to question: Are we filtering for the right kind of talent?&lt;/p&gt;

&lt;p&gt;DSA isn’t the enemy—it’s a useful tool. But when it becomes the only lens for evaluating engineers, we risk missing out on builders, pragmatists, and innovators who don’t shine in 90-minute coding puzzles. Let’s rethink how we hire and what we’re optimizing for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;My Journey: From LeetCode to Real Systems&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’ll be honest: I’ve played the DSA game. I’ve solved hundreds of LeetCode problems, climbed the rankings, and honed my ability to reverse a linked list faster than you can say “time complexity.” That grind taught me discipline, code precision, and a deeper understanding of algorithms. It wasn’t a waste.&lt;/p&gt;

&lt;p&gt;But there was a moment when I hit a wall. I wasn’t building anything. I was solving abstract puzzles that felt disconnected from the real world. So I pivoted. I started writing compilers, tinkering with machine learning models, contributing to open-source projects, and designing tools to solve problems I cared about. That’s when my growth as an engineer truly took off.&lt;/p&gt;

&lt;p&gt;I learned how to structure a codebase, manage dependencies, deploy systems, and iterate on feedback. These skills—not my ability to invert a binary tree blindfolded—made me a better engineer. And yet, most tech interviews barely test for them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why DSA Matters (and Where It Falls Short)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s give DSA its due. It’s a scalable way to screen candidates. It tests foundational computer science knowledge and ensures a baseline of coding fluency. For roles in infrastructure, backend systems, or search algorithms, DSA skills often correlate with success. It’s also democratic—anyone with an internet connection and determination can study and compete.&lt;/p&gt;

&lt;p&gt;But here’s the catch: DSA is a narrow lens. Not every great engineer excels at solving decontextualized puzzles under a ticking clock. Some shine when building maintainable systems, designing APIs, tuning ML models, or collaborating on open-source projects. These aren’t “soft” skills—they’re the backbone of modern software engineering.&lt;/p&gt;

&lt;p&gt;By making DSA the primary gatekeeper, we might be filtering out engineers who are already productive in real-world contexts. Think about it: the person who can debug a production outage or architect a scalable API might not ace a graph traversal problem. Are we okay with losing that talent?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Redefining “Quality” in Hiring&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We all agree: quality matters. Tech companies manage massive infrastructure, serve billions of users, and ship mission-critical products. There’s no room for mediocrity. But “quality” isn’t just about acing a coding challenge. It’s about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing maintainable code: Can they structure a codebase that’s easy to extend and debug?&lt;/li&gt;
&lt;li&gt;Understanding trade-offs: Do they know when to optimize for speed vs. scalability?&lt;/li&gt;
&lt;li&gt;Debugging in production: Can they stay calm and methodical when things break?&lt;/li&gt;
&lt;li&gt;Building iteratively: Can they ship something useful and improve it over time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DSA tests some of these skills, but not all. It also favors candidates who’ve had the time and resources to practice a specific type of problem-solving, often outside real-world constraints. This can exclude builders who excel at shipping software but aren’t optimized for puzzle-solving.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A Broader Lens for Hiring&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, what’s the alternative? Replacing DSA entirely isn’t practical—it scales well, and portfolios or project reviews are harder to standardize. But we can complement DSA with approaches that capture a wider range of skills. Here are a few ideas:&lt;/p&gt;

&lt;p&gt;Value GitHub activity: A candidate’s open-source contributions or personal projects can reveal their ability to write real code and collaborate.&lt;/p&gt;

&lt;p&gt;Give take-homes real weight: Well-designed take-home projects mimic real engineering tasks and let candidates show their process.&lt;/p&gt;

&lt;p&gt;Review documentation and wikis: Writing clear docs or contributing to wikis shows communication and systems thinking.&lt;/p&gt;

&lt;p&gt;Incorporate system design: Practical discussions about architecture or trade-offs can test real-world problem-solving.&lt;/p&gt;

&lt;p&gt;These aren’t perfect solutions. They’re harder to scale and evaluate. But if we care about innovation, we need to experiment with hiring processes that let diverse talent shine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Final Thoughts: Let’s Hire Builders&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the most transformative technologies of the next decade might never be built—not because the talent isn’t there, but because we filtered it out with a 90-minute coding challenge. That’s not a quality filter; it’s a missed opportunity.&lt;/p&gt;

&lt;p&gt;DSA has its place, but it’s not the whole story. Let’s start optimizing for engineers who can build, contribute, collaborate, and grow—not just those who can solve puzzles the fastest. The sooner we broaden our lens, the stronger our industry will be.&lt;/p&gt;

&lt;p&gt;What do you think? Have you faced the DSA grind in interviews? How would you change tech hiring to value builders? Share your thoughts in the comments—I’d love to hear your perspective!&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>hiring</category>
      <category>interview</category>
    </item>
    <item>
      <title>NEXA-MOE: A Lean, Powerful AI for Scientific Discovery Under Tight Constraints</title>
      <dc:creator>Darkstalker</dc:creator>
      <pubDate>Mon, 12 May 2025 04:00:00 +0000</pubDate>
      <link>https://dev.to/darkstalker/nexa-moe-a-lean-powerful-ai-for-scientific-discovery-under-tight-constraints-4fgb</link>
      <guid>https://dev.to/darkstalker/nexa-moe-a-lean-powerful-ai-for-scientific-discovery-under-tight-constraints-4fgb</guid>
      <description>&lt;p&gt;Models with billions of parameters, trained on sprawling GPU clusters, dominate headlines. But what if you could achieve cutting-edge scientific results with a fraction of the resources? Enter NEXA-MOE, a Mixture of Experts (MoE) model with just 110 million parameters that’s making waves in physics, biology, and material science. Built to run on surprisingly modest hardware, NEXA-MOE is proof that you don’t need a supercomputer to push the boundaries of scientific discovery. In this post, we’ll explore how NEXA-MOE works, why it’s a game-changer, and what developers can learn from its clever design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is NEXA-MOE?&lt;/strong&gt;&lt;br&gt;
NEXA-MOE is an AI model designed to tackle complex scientific problems, from predicting battery ion behavior to modeling protein structures and simulating fluid dynamics. Unlike traditional behemoths that guzzle compute power, NEXA-MOE is lean, efficient, and specialized. With only 110 million parameters, it delivers high-fidelity results across multiple scientific domains, all while running on hardware that fits in a small lab or cloud setup.&lt;/p&gt;

&lt;p&gt;Its secret sauce? A Mixture of Experts architecture that acts like a team of specialists. Instead of throwing an entire model at every problem, NEXA-MOE routes queries to the right “expert” modules, saving time and energy. Think of it as a smart librarian who knows exactly which book to pull from the shelf, rather than scanning the entire library.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Architecture: A Team of Brainy Specialists&lt;/strong&gt;&lt;br&gt;
At the core of NEXA-MOE is a Semantic Router, a system that reads your query (say, “How do I model alloy properties?”) and sends it to the most relevant expert module. The notebook behind NEXA-MOE uses a SentenceTransformer (all-MiniLM-L6-v2) to embed queries and KMeans clustering to group them by domain, ensuring precise routing. Here’s who’s on the team:&lt;/p&gt;

&lt;p&gt;Physics Experts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generalist: Handles broad physics questions.&lt;/li&gt;
&lt;li&gt;Astrophysics: Models stars, galaxies, and cosmic events.&lt;/li&gt;
&lt;li&gt;High-Energy Particle Physics: Analyzes particle collider data.&lt;/li&gt;
&lt;li&gt;Computational Fluid Dynamics: Simulates how fluids move.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Biology Experts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generalist: Covers core biology queries.&lt;/li&gt;
&lt;li&gt;Protein Folding: Predicts how proteins twist and fold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Material Science Experts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generalist: Tackles material properties.&lt;/li&gt;
&lt;li&gt;Battery Ion Prediction: Optimizes battery tech.&lt;/li&gt;
&lt;li&gt;Alloy Property Modeling: Designs stronger, lighter alloys.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each expert is a fine-tuned neural network—either a BERT model for classification or a T5 model for generating text—trained to excel in its niche. After the experts do their thing, an Inference &amp;amp; Validation Pipeline checks the results, combines predictions for accuracy, and formats the output. A Knowledge Feedback Loop keeps the router learning, so it gets smarter with every query.&lt;br&gt;
This setup is brilliant because it’s sparse. Only the necessary experts light up for a given task, cutting down on compute costs. It’s like hiring a crack team of specialists instead of paying for a massive, general-purpose workforce.&lt;br&gt;
Training: Doing More with Less&lt;br&gt;
Training a model to handle diverse scientific tasks is no joke, especially when you’re working with limited resources. NEXA-MOE’s training pipeline, detailed in the notebook, is a masterclass in efficiency [1]:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dataset: The team used a curated set of arXiv papers, stored as JSON. Exploratory data analysis (EDA) showed it’s mostly English, with clean, domain-specific content—perfect for science without the clutter of web data.&lt;/li&gt;
&lt;li&gt;Sparse Gating: Only the relevant experts are trained for each sample, slashing memory and compute needs.&lt;/li&gt;
&lt;li&gt;Optimization: The model uses the Adam optimizer but is eyeing a switch to AzureSky, a hybrid optimizer blending Simulated Annealing and Adam for faster convergence on tricky scientific problems.&lt;/li&gt;
&lt;li&gt;Hyperparameter Tuning: The notebook leverages Optuna to automatically find the best settings, saving hours of manual tweaking.&lt;/li&gt;
&lt;li&gt;Reinforcement Learning: Fine-tuning based on prompt accuracy (measured with metrics like BLEU scores) ensures real-world usefulness.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pipeline is a lesson in working smart. By focusing on a high-quality dataset, using sparse training, and automating optimization, NEXA-MOE punches way above its weight without needing a data center.&lt;br&gt;
Hardware: Squeezing Every Drop of Power&lt;br&gt;
One of NEXA-MOE’s most impressive feats is its hardware setup. The notebook reveals a setup that stretches modest resources to their limits :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU: An Intel i5 vPro 8th Gen, overclocked from 1.9 GHz to ~6.0 GHz, handling preprocessing and overflow tasks.&lt;/li&gt;
&lt;li&gt;GPU: Two NVIDIA T4 GPUs in the cloud, running at 90%+ utilization with memory maxed out, managed by torch.distributed for efficient tensor handling.&lt;/li&gt;
&lt;li&gt;Performance: The system hit 47–50 petaflops—mind-blowing for such a small setup—thanks to a tightly optimized CPU-GPU pipeline on the first run but this was not sustainable my working directory crashed and the outputs were not usable even the clock speeds were insane the outputs were a non-stater&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I monitored everything with tools like psutil and nvidia-smi, ensuring no crashes and predictable runtimes. For developers, this is a reminder that clever resource management—overclocking, memory optimization, and workload balancing—can rival brute-force compute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why NEXA-MOE Shines&lt;/strong&gt;&lt;br&gt;
Here’s what makes NEXA-MOE stand out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specialization: Each expert delivers precise, interpretable results, perfect for scientists who need actionable insights.&lt;/li&gt;
&lt;li&gt;Versatility: It handles physics, biology, and material science with ease, as shown by the notebook’s domain clustering [1].&lt;/li&gt;
&lt;li&gt;Stability: Smart CPU-GPU balancing kept training smooth, with no unexpected crashes.&lt;/li&gt;
&lt;li&gt;Future Potential: The planned AzureSky optimizer could make training even faster and more accurate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a model with just 110 million parameters, these results are remarkable. The notebook’s FLOPs calculations show each expert uses ~10–20 GFLOPs, a fraction of what dense models like GPT-3 demand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Catch: It’s Not Perfect&lt;/strong&gt;&lt;br&gt;
No model is flawless, and NEXA-MOE has its quirks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Science-Only Focus: It’s built for scientific queries, so don’t ask it about pop culture or general knowledge—it’ll flounder.&lt;/li&gt;
&lt;li&gt;Occasional Nonsense: Sometimes, it generates low-quality responses, a hiccup which I'm activity tackling with more reinforcement learning.&lt;/li&gt;
&lt;li&gt;Scaling Limits: Plans to scale to 2.2 billion parameters are hitting hardware and algorithmic walls, as bigger models don’t always mean better results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These limitations are honest trade-offs for a model designed to excel in a niche while staying lean.&lt;br&gt;
Takeaways for Developers&lt;br&gt;
NEXA-MOE is a goldmine of lessons for anyone building AI systems, especially in resource-constrained settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go Modular: MoE architectures save resources by activating only what’s needed.&lt;/li&gt;
&lt;li&gt;Max Out Hardware: Overclock CPUs, optimize GPU memory, and use tools like torch.distributed to squeeze every bit of performance.&lt;/li&gt;
&lt;li&gt;Curate Your Data: A clean, focused dataset (like arXiv papers) beats massive, noisy ones for specialized tasks.&lt;/li&gt;
&lt;li&gt;Automate the Boring Stuff: Tools like Optuna take the pain out of hyperparameter tuning.&lt;/li&gt;
&lt;li&gt;Build for Growth: Feedback loops and optimizer upgrades keep your model improving over time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wrapping Up&lt;br&gt;
NEXA-MOE is a testament to what’s possible when you combine clever design with relentless optimization. With just 110 million parameters, it’s tackling some of science’s toughest problems on hardware that won’t break the bank. Whether you’re a researcher in a small lab or a developer looking to build efficient AI, NEXA-MOE shows that you don’t need billions of parameters to make a big impact. Stay tuned for updates as the team pushes toward the AzureSky optimizer and grapples with scaling challenges—it’s an exciting time for lean, mean AI machines!&lt;br&gt;
Want to dive deeper? Check out the training notebook for the full scoop on NEXA-MOE’s setup and results.&lt;/p&gt;

&lt;p&gt;Kaggle notebook:&lt;a href="https://www.kaggle.com/code/allanwandia/train-model" rel="noopener noreferrer"&gt;https://www.kaggle.com/code/allanwandia/train-model&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>highperfomancecomputing</category>
      <category>science</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
