A small, DB-aware chatbot backend with an Ollama LLM, schema-aware SQL generation, and an optional RAG layer.
- Create a virtual environment and install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt-
Copy
.env.exampleto.envand update values. -
Start the API:
uvicorn app.main:app --host 0.0.0.0 --port 8000GET /health– basic health checkGET /schema– current schema catalog (tables, columns, foreign keys)POST /chat– ask a question and get an answerPOST /rag/ingest– add a document to the local vector store (whenRAG_ENABLED=true)
curl -X POST http://localhost:8000/chat \
-H 'Content-Type: application/json' \
-d '{"question":"Top 5 customers by revenue last month?","include_debug":true}'- SQL is constrained to read-only
SELECTand limited to allowed tables. - For complex databases, tune
SCHEMA_MAX_CANDIDATESand allow/deny lists. - The local vector store is for small datasets. For production, replace it with pgvector, Qdrant, or another vector DB.
- To switch databases, set
DB_DIALECTand driver, or provideDB_URLdirectly.