1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! # opendbpylot
//!
//! Turn a natural-language question into SQL using **Retrieval-Augmented Generation (RAG)**.
//!
//! ## The pipeline
//! ```text
//! question
//! -> retrieve relevant context (similar Q/SQL, related DDL, related docs) [vectorstore]
//! -> build a prompt out of that context [prompt]
//! -> ask the LLM to write SQL [llm]
//! -> clean the SQL out of the reply [sql]
//! -> run it on the database [sqlrunner]
//! -> return rows
//! ```
//!
//! Every layer is a **trait** so the concrete provider (OpenAI vs mock, SQLite vs
//! Postgres, in-memory vs hosted vector store) can be swapped without touching the
//! orchestration logic — an "interface + plug-in" design throughout.