---
title: "NL2SQL (Natural Language to SQL)"
---

# NL2SQL (Natural Language to SQL)

Convert natural language queries to SQL with AI-powered understanding.

## Overview

HeliosDB NL2SQL enables users to query databases using natural language, automatically translating questions into optimized SQL queries.

## Quick Start

```sql
-- Enable NL2SQL
SET nl2sql_enabled = true;
SET nl2sql_model = 'gpt-4';

-- Query with natural language
NL2SQL "Show me all customers who made purchases over $1000 last month";

-- Result: Automatically generated and executed SQL
-- SELECT c.* FROM customers c
-- JOIN orders o ON c.id = o.customer_id
-- WHERE o.total > 1000
-- AND o.date >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
```

## Key Features

| Feature | Description |
|---------|-------------|
| **Schema Awareness** | Understands table relationships and data types |
| **Query Optimization** | Generates efficient SQL with proper indexes |
| **Multi-Model Support** | OpenAI, Anthropic, local models |
| **Agentic Enhancements** | Iterative refinement for complex queries |
| **WASM Procedures** | Custom stored procedures in WASM |

## Documentation

| Document | Description |
|----------|-------------|
| [NL2SQL_USER_GUIDE.md](https://www.heliosdb.com/docs/full/features/nl2sql/nl2sql_user_guide/) | Complete user guide |
| [PRODUCTION_DEPLOYMENT_GUIDE.md](https://www.heliosdb.com/docs/full/features/nl2sql/production_deployment_guide/) | Production setup |

## Related

- **Conversational BI**: `/docs/guides/user/CONVERSATIONAL_BI_USER_GUIDE.md`
- **SQL Native RAG**: `/docs/guides/user/SQL_NATIVE_RAG_USER_GUIDE.md`

---
