Documentation
¶
Overview ¶
Package text2sql provides natural language to ClickHouse SQL translation using a local Ollama LLM with structural validation feedback.
The LLM generates SQL freely. The nanopass pipeline validates and canonicalizes the output. On failure, the error is fed back for retry.
Usage:
gen := text2sql.New("http://localhost:11434", "qwen2.5-coder:7b", schema)
result, err := gen.Generate(ctx, "count orders by country for 2024")
if err != nil { ... }
fmt.Println(result.SQL) // canonical SQL
fmt.Println(result.AST) // ast.Query
fmt.Println(result.Attempts) // number of LLM calls
Index ¶
Constants ¶
This section is empty.
Variables ¶
var PackageProps = packageprops.Props{ WASMWASI: packageprops.WASMCompiles, WASMJS: packageprops.WASMBlocked, WASMFreestanding: packageprops.WASMCompiles, }
PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.
Functions ¶
func NewCliCommand ¶
NewCliCommand returns the `text2sql` subcommand. Mounted directly under the boxer top-level CLI by public/app/main.go.
In non-interactive mode the question is supplied as positional arguments (joined with a single space). Interactive mode reads from stdin, prompts for a question per line, and prints the result.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator translates natural language to ClickHouse SQL.
type Option ¶
type Option func(*Generator)
Option configures a Generator.
func WithMaxAttempts ¶
WithMaxAttempts sets the maximum number of LLM calls (default: 3).
func WithSystemPromptOverride ¶
WithSystemPromptOverride replaces the default system prompt entirely.
type Result ¶
type Result struct {
SQL string // canonical (Grammar2-compliant) SQL
AST ast.Query // parsed and converted AST
RawSQL string // SQL as generated by the LLM (before normalization)
Attempts int // number of LLM calls (1 = first try)
Model string // model used
TotalTokens int // approximate total tokens across all attempts
}
Result is the output of a successful text-to-SQL generation.
type SchemaColumn ¶
type SchemaColumn struct {
Name string
Type string
Comment string // optional human-readable description
}
SchemaColumn describes a column.
type SchemaTable ¶
type SchemaTable struct {
Database string
Table string
Columns []SchemaColumn
Comment string // optional human-readable description
}
SchemaTable describes a table for the LLM prompt.