SLM-Agents / website /sql.html
spcv's picture
Design polish: welcome card layout & icons, assistant tables/links/typography, mobile responsiveness
61846f9 verified
Raw History Blame Contribute Delete
23.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Converts natural language questions into executable PostgreSQL, SQLite, and MySQL queries with schema auto-linking and syntax validation.">
<link rel="canonical" href="https://www.slmagents.ai/sql.html">
<title>SLM Text-to-SQL: Natural Language to Optimized SQL Queries | SLMAgents</title>
<link rel="stylesheet" href="style.css?v=64.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- OpenGraph / Social Meta Tags -->
<meta property="og:type" content="article">
<meta property="og:url" content="https://www.slmagents.ai/sql.html">
<meta property="og:title" content="SLM Text-to-SQL: Natural Language to Optimized SQL Queries | SLMAgents">
<meta property="og:description" content="Converts natural language questions into executable PostgreSQL, SQLite, and MySQL queries with schema auto-linking and syntax validation.">
<meta property="og:site_name" content="SLMAgents">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="SLM Text-to-SQL: Natural Language to Optimized SQL Queries | SLMAgents">
<meta name="twitter:description" content="Converts natural language questions into executable PostgreSQL, SQLite, and MySQL queries with schema auto-linking and syntax validation.">
<!-- Structured Data / Schema Markup -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "SLM Text-to-SQL: Natural Language to Optimized SQL Queries | SLMAgents",
"description": "Converts natural language questions into executable PostgreSQL, SQLite, and MySQL queries with schema auto-linking and syntax validation.",
"url": "https://www.slmagents.ai/sql.html",
"mainEntityOfPage": "https://www.slmagents.ai/sql.html",
"articleSection": "Developer Tools",
"author": {
"@type": "Organization",
"name": "SLMAgents Community",
"url": "https://github.com/t00114218-stack/SLMAgents"
},
"publisher": {
"@type": "Organization",
"name": "SLMAgents",
"logo": {
"@type": "ImageObject",
"url": "https://www.slmagents.ai/flowchart.png"
}
}
}
</script>
</head>
<body>
<!-- Top Engineering Header -->
<header class="site-top-header web-only-nav">
<div class="container nav-container">
<div style="display: flex; align-items: center; gap: 10px;">
<button class="sidebar-toggle" onclick="toggleSidebar()" aria-label="Toggle Sidebar">
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16"/>
</svg>
</button>
<a href="index.html" class="logo">
<div class="logo-icon">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
</svg>
</div>
<span>SLMAgents</span>
</a>
</div>
<nav>
<ul class="nav-links">
<li><a href="index.html" id="topnav-home">Home</a></li>
<li><a href="chat.html" id="topnav-chat">Chat Studio</a></li>
<li><a href="playground.html" id="topnav-playground">Playground</a></li>
<li><a href="blogs.html" id="topnav-blogs">Blogs</a></li>
<li>
<button type="button" onclick="openDownloadModal()" class="btn-nav-download">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
Download App
</button>
</li>
<li>
<a href="https://github.com/t00114218-stack/SLMAgents" target="_blank" class="btn-github-nav">
<svg width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8"/>
</svg>
GitHub
</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="layout-container">
<aside class="sidebar" id="sidebar">
<div class="sidebar-group">
<div class="sidebar-group-title">Active Libraries</div>
<ul class="sidebar-list" id="sidebar-active-list"></ul>
</div>
</aside>
<main class="main-content">
<div class="doc-content-wrapper">
<section class="doc-section" style="margin-top: 0;">
<div class="breadcrumb" style="font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.75rem;"><a href="index.html" style="color: var(--text-secondary); text-decoration: none;">Overview</a> <span style="margin: 0 6px;">/</span> <span>slm_text_to_sql</span> <span style="margin: 0 6px;">/</span> <span style="color: var(--text-primary); font-weight: 600;">SLM Text-to-SQL</span></div>
<div class="badge-pill">slm_text_to_sql · Developer Tools · 10-Plane Pure-CPU Agent</div>
<h1 style="font-size: 2.25rem; color: #0f172a; font-weight: 800; margin-bottom: 0.75rem;">SLM Text-to-SQL</h1>
<p style="font-size: 1.05rem; color: #334155; line-height: 1.65; font-weight: 500; margin: 0;">Translates natural language questions into valid SQL queries against custom database schemas offline.</p>
</section>
<nav class="doc-nav">
<a href="#overview">01 / Overview</a>
<a href="#install">02 / OS Installers &amp; CLI</a>
<a href="#harness">03 / 10-Plane Harness</a>
<a href="#git">04 / Git Checkout</a>
<a href="#config">05 / API Reference</a>
</nav>
<!-- OVERVIEW -->
<section class="doc-section" id="overview">
<h2>01 / Overview &amp; Capabilities</h2>
<p>Translates natural language questions into valid SQL queries against custom database schemas offline.</p>
<h3 style="margin-top: 1.5rem; font-size: 1.15rem; color: #0f172a; font-weight: 700;">Key Features</h3>
<ul style="padding-left: 1.5rem; color: #334155; font-weight: 500; line-height: 1.7;">
<li><strong>Offline schema parsing and SQL translation</strong></li>
<li><strong>Dialect support: PostgreSQL, SQLite, MySQL</strong></li>
<li><strong>Guarantees valid syntax without leaking data to external servers</strong></li>
</ul>
</section>
<!-- INSTALLATION & STANDALONE OS HARNESS INSTALLERS -->
<section class="doc-section" id="install">
<h2>02 / Standalone OS Harness Installers, CLI &amp; Python SDK</h2>
<p>In <strong>SLMAgents 2.0</strong>, <strong>SLM Text-to-SQL</strong> executes inside the <strong>10-Plane Pure-CPU Agent Harness (<code>slm_harness</code>)</strong>. Download a self-extracting <strong>Individual Agent + Harness OS Installer</strong> for macOS, Windows, or Linux (bundling <code>slm_text_to_sql</code> + <code>slm_harness</code> + the <code>./slm</code> CLI), install the full 26-agent desktop suite, or install via Python <code>pip</code>:</p>
<h3>1. Individual SLM Text-to-SQL + 10-Plane Harness Installers (All OSes)</h3>
<div class="subpage-installer-grid">
<a href="/api/installers/download/agent-macos?agent=sql" class="subpage-installer-card">
<div class="subpage-installer-title">
<span>macOS Installer</span>
<span class="subpage-installer-ext">.command</span>
</div>
<div class="subpage-installer-desc">Self-extracting macOS bundle with <code>slm_text_to_sql</code> + <code>slm_harness</code> + <code>./slm</code> CLI</div>
</a>
<a href="/api/installers/download/agent-windows?agent=sql" class="subpage-installer-card">
<div class="subpage-installer-title">
<span>Windows Installer</span>
<span class="subpage-installer-ext">.exe</span>
</div>
<div class="subpage-installer-desc">Native 64-bit Windows Setup with portable Python 3.11 + <code>slm_text_to_sql</code> + <code>slm_harness</code></div>
</a>
<a href="/api/installers/download/agent-linux?agent=sql" class="subpage-installer-card">
<div class="subpage-installer-title">
<span>Linux Installer</span>
<span class="subpage-installer-ext">.AppImage</span>
</div>
<div class="subpage-installer-desc">Standalone Linux AppImage with <code>slm_text_to_sql</code> + <code>slm_harness</code> + <code>./slm</code> CLI</div>
</a>
</div>
<h3>2. Full 26-Agent Studio &amp; Desktop OS Installers</h3>
<div class="subpage-suite-links">
<a href="/api/installers/download/macos-dmg" class="subpage-suite-link">macOS .dmg (280 MB)</a>
<a href="/api/installers/download/windows" class="subpage-suite-link">Windows .exe (2.8 MB)</a>
<a href="/api/installers/download/linux" class="subpage-suite-link">Linux .AppImage (3.4 MB)</a>
<button onclick="openDownloadModal()" class="btn btn-primary" style="padding: 0.38rem 0.8rem; font-size: 0.76rem;">All OS Installers Modal</button>
</div>
<h3>3. 10-Plane Harness CLI (<code>./slm</code>) &amp; Python <code>pip</code> Installation</h3>
<div class="code-panel" style="margin: 0.85rem 0;">
<div class="code-header">
<div class="code-dots"><div class="code-dot"></div><div class="code-dot"></div><div class="code-dot"></div></div>
<div class="code-title">Terminal — 10-Plane Harness CLI &amp; Pip</div>
</div>
<div class="code-content" style="display:block;">
<pre><span style="color:#64748b;"># Option A: Install via PyPI or editable source with the 10-Plane Harness</span>
<span style="color:#34d399;">$</span> pip install slm-text-to-sql
<span style="color:#34d399;">$</span> pip install -e ./slm_harness -e ./slm_text_to_sql
<span style="color:#64748b;"># Option B: Run directly through the Unified 10-Plane Pure-CPU Harness CLI (./slm)</span>
<span style="color:#34d399;">$</span> ./slm ask "Write a SQL query for total sales in West region against @schema.sql"
<span style="color:#34d399;">$</span> ./slm chat <span style="color:#64748b;"># Interactive Rich TUI with 18 slash commands (/trace, /models, /arena, /undo)</span>
<span style="color:#34d399;">$</span> ./slm serve <span style="color:#64748b;"># 100% Offline Web AI Studio + OpenAI /v1 API at http://127.0.0.1:7860</span></pre>
</div>
</div>
</section>
<!-- 10-PLANE PURE-CPU HARNESS ARCHITECTURE -->
<section class="doc-section" id="harness">
<h2>03 / 10-Plane Pure-CPU Harness Integration (<code>slm_harness</code>)</h2>
<p>Rather than executing as an isolated prompt wrapper, <strong>SLM Text-to-SQL</strong> is natively orchestrated by the <strong>SLMAgents 2.0 10-Plane Pure-CPU Harness</strong> (via <code>slm_harness.runtime.legacy_bridge</code> and <code>CascadeRouter</code>). Every call benefits from hybrid <code>llama.cpp</code> GGUF (<code>Q4_K_M</code>) + Quantized INT4/INT8 CPU execution, watermarked LRU memory governance, grammar-constrained decoding, and deterministic verification at <strong>$0 API cost</strong>:</p>
<table class="param-table">
<thead>
<tr><th>Harness Plane</th><th>Subsystem</th><th>How It Powers SLM Text-to-SQL on Pure CPU</th></tr>
</thead>
<tbody>
<tr>
<td><strong>Plane 6</strong></td>
<td><code>CascadeRouter</code> (&lt;35ms)</td>
<td>Stage 2 (DDL / SELECT / Schema AST Regex) & Stage 4 (ONNXPrefixEnumMasker Token-Trie)</td>
</tr>
<tr>
<td><strong>Plane 2 &amp; 5</strong></td>
<td><code>MemoryArena</code> &amp; Hybrid CPU Runtime</td>
<td>Specialist Role: <code>sql (Prem-1B-SQL GGUF Q4_K_M / Qwen2.5-Coder-1.5B INT4)</code>. Managed inside Watermark LRU <code>MemoryArena</code> (<code>lite</code> 2.6 GB / <code>balanced</code> 4.7 GB / <code>power</code> 8.2 GB) with zero-copy session sharing and automatic OOM tier step-down (<code>8B -&gt; 4B -&gt; 3B -&gt; 0.8B</code>).</td>
</tr>
<tr>
<td><strong>Plane 7 &amp; 8</strong></td>
<td>Deterministic Verifier &amp; Governance</td>
<td>Plane 7 Read-Only SQLite Execution Verifier (?mode=ro URI) + Levenshtein PRAGMA table_info Column Auto-Healing</td>
</tr>
<tr>
<td><strong>Plane 1, 3 &amp; 4</strong></td>
<td>Kernel, Artifact Scratchpad &amp; 4-Tier Memory</td>
<td>SQLite WAL <code>CheckpointStore</code> (<code>/fork</code>, <code>/rewind</code>, <code>/undo</code>), content-addressed <code>artifact://&lt;sha12&gt;</code> handles to prevent prompt bloat, and hybrid SQLite FTS5 BM25 + HNSW vector memory.</td>
</tr>
</tbody>
</table>
</section>
<!-- GIT CHECKOUT -->
<section class="doc-section" id="git">
<h2>04 / Source Checkout (Git Sparse-Checkout)</h2>
<p>Clone this agent alongside the <strong>10-Plane Pure-CPU Harness (<code>slm_harness</code>)</strong> from the monorepo using Git sparse-checkout — no need to download all 26 agents:</p>
<h3>Option 1 — Sparse Checkout with 10-Plane Harness (Recommended)</h3>
<div class="code-panel" style="margin: 0.85rem 0;">
<div class="code-header">
<div class="code-dots"><div class="code-dot"></div><div class="code-dot"></div><div class="code-dot"></div></div>
<div class="code-title">Terminal — Git Sparse Checkout</div>
</div>
<div class="code-content" style="display:block;">
<pre><span style="color:#64748b;"># 1. Create and enter a new directory</span>
<span style="color:#34d399;">$</span> mkdir slm_text_to_sql_workspace &amp;&amp; cd slm_text_to_sql_workspace
<span style="color:#64748b;"># 2. Initialise empty git repo and add remote</span>
<span style="color:#34d399;">$</span> git init
<span style="color:#34d399;">$</span> git remote add origin https://github.com/t00114218-stack/SLMAgents.git
<span style="color:#64748b;"># 3. Enable sparse-checkout for both slm_harness and slm_text_to_sql</span>
<span style="color:#34d399;">$</span> git sparse-checkout init --cone
<span style="color:#34d399;">$</span> git sparse-checkout set slm_harness slm_text_to_sql
<span style="color:#64748b;"># 4. Pull the 10-Plane Harness and agent source</span>
<span style="color:#34d399;">$</span> git pull origin main</pre>
</div>
</div>
<h3>Option 2 — Full Repository Clone</h3>
<div class="code-panel" style="margin: 0.85rem 0;">
<div class="code-header">
<div class="code-dots"><div class="code-dot"></div><div class="code-dot"></div><div class="code-dot"></div></div>
<div class="code-title">Terminal — Full Clone</div>
</div>
<div class="code-content" style="display:block;">
<pre><span style="color:#34d399;">$</span> git clone https://github.com/t00114218-stack/SLMAgents.git
<span style="color:#34d399;">$</span> cd SLMAgents
<span style="color:#34d399;">$</span> ./slm doctor</pre>
</div>
</div>
<p style="margin-top: 1.25rem; font-size: 0.86rem; color: var(--text-secondary); border-left: 2px solid #09090b; padding-left: 1rem;">
<strong>Note:</strong> After checkout, install the harness and agent in editable mode with <code>pip install -e ./slm_harness -e ./slm_text_to_sql</code> or download the pre-packaged OS Harness Installer above.
</p>
</section>
<!-- CONFIGURATION -->
<section class="doc-section" id="config">
<h2>05 / Configuration &amp; API Reference</h2>
<h3 style="font-size: 1.15rem; color: #0f172a; font-weight: 700; margin-top: 1.5rem;">Constructor Parameters</h3>
<p>Instantiate <code>SLMTextToSQL</code> with performance and runtime options:</p>
<table class="param-table">
<thead>
<tr><th>Parameter</th><th>Type / Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>model_path</code></td><td><span class='param-type'>str | None</span></td><td>Local GGUF (.gguf) or quantized ONNX model path managed by MemoryArena. Default: None (auto-resolved via slm_harness).</td></tr>
<tr><td><code>temperature</code></td><td><span class='param-type'>float | 0.0</span></td><td>Sampling temperature. Default: 0.0.</td></tr>
<tr><td><code>top_p</code></td><td><span class='param-type'>float | 0.9</span></td><td>Nucleus sampling threshold. Default: 0.9.</td></tr>
<tr><td><code>max_tokens</code></td><td><span class='param-type'>int | 256</span></td><td>Max token output limit. Default: 256.</td></tr>
<tr><td><code>n_threads</code></td><td><span class='param-type'>int | 4</span></td><td>CPU thread count. Default: 4.</td></tr>
</tbody>
</table>
<h3 style="font-size: 1.15rem; color: #0f172a; font-weight: 700; margin-top: 2rem;">Methods</h3>
<table class="param-table">
<thead>
<tr><th>Method Signature</th><th>Return Type</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>generate_sql(schema, query, ...)</code></td><td><span class='param-type'>str</span></td><td>Generates valid SQL query string from natural language prompt.</td></tr>
</tbody>
</table>
<h3 style="font-size: 1.15rem; color: #0f172a; font-weight: 700; margin-top: 2rem;">Execution Parameters</h3>
<p>Complete list of execution parameters accepted by the primary agent method:</p>
<table class="param-table">
<thead>
<tr><th>Parameter</th><th>Type / Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>schema</code></td><td><span class='param-type'>str</span></td><td>Database DDL creation schema string.</td></tr>
<tr><td><code>query</code></td><td><span class='param-type'>str</span></td><td>Natural language user question.</td></tr>
<tr><td><code>system_prompt</code></td><td><span class='param-type'>str | None</span></td><td>SQL dialect prompt override. Default: None.</td></tr>
<tr><td><code>user_input</code></td><td><span class='param-type'>str | None</span></td><td>Additional SQL constraints. Default: None.</td></tr>
<tr><td><code>temperature</code></td><td><span class='param-type'>float | 0.0</span></td><td>Sampling temperature. Default: 0.0.</td></tr>
<tr><td><code>top_p</code></td><td><span class='param-type'>float | 0.9</span></td><td>Nucleus sampling probability. Default: 0.9.</td></tr>
<tr><td><code>max_tokens</code></td><td><span class='param-type'>int | 256</span></td><td>Maximum token limit. Default: 256.</td></tr>
</tbody>
</table>
<h3 style="font-size: 1.15rem; color: #0f172a; font-weight: 700; margin-top: 2rem;">Quick Start</h3>
<div class="code-panel" style="margin: 0.85rem 0;">
<div class="code-header">
<div class="code-dots"><div class="code-dot"></div><div class="code-dot"></div><div class="code-dot"></div></div>
<div class="code-title">Python Example</div>
</div>
<div class="code-content" style="display:block;">
<pre style="margin:0; background:#0f172a; color:#f8fafc; font-family:'JetBrains Mono',monospace; font-size:0.9rem; border:none; box-shadow:none; padding:0;"><code class="language-python">from slm_text_to_sql import SLMTextToSQL
sql_agent = SLMTextToSQL(temperature=0.0, top_p=0.9, max_tokens=256)
query = sql_agent.generate_sql(
schema="CREATE TABLE sales (id INT, amount DECIMAL, region TEXT);",
query="What is total sales in West?",
system_prompt="Dialect: PostgreSQL",
user_input="Add WHERE amount > 0 condition",
temperature=0.0,
top_p=0.9,
max_tokens=256
)
print(query)</code></pre>
</div>
</div>
</section>
<!-- VERIFIED LOGS -->
<section class="doc-section">
<h2>06 / Verified Execution Logs</h2>
<p>Diagnostic execution console output running locally on CPU:</p>
<div class="code-panel" style="margin: 0.85rem 0;">
<div class="code-header">
<div class="code-dots"><div class="code-dot"></div><div class="code-dot"></div><div class="code-dot"></div></div>
<div class="code-title">Output Console</div>
</div>
<div class="code-content" style="display:block;">
<pre style="margin:0; background:#0f172a; color:#38bdf8; font-family:'JetBrains Mono',monospace; font-size:0.85rem; border:none; box-shadow:none; padding:0; white-space: pre-wrap; word-break: break-word;">→ INPUT:
Query: What is total sales in West?
← OUTPUT:
"SELECT SUM(amount) FROM sales WHERE region = 'West' AND amount > 0;"</pre>
</div>
</div>
</section>
<!-- FOOTER -->
<footer>
<div class="footer-row">
<div><strong style="color: var(--text-primary);">SLMAgents 2.0</strong> · Powered by the 10-Plane Pure-CPU Agent Harness (<code>slm_harness</code>) · MIT License</div>
<div class="footer-links">
<a href="index.html">Home</a>
<a href="index.html#os-installers">OS Installers</a>
<a href="chat.html">Chat Studio</a>
<a href="playground.html">Playground</a>
<a href="blogs.html">Blogs</a>
<a href="https://github.com/t00114218-stack/SLMAgents" target="_blank">GitHub</a>
</div>
</div>
</footer>
</div>
</main>
</div>
<script src="app.js?v=100.0"></script>
</body>
</html>