GitHub - stym06/kepler

4 min read Original article โ†—

๐Ÿ”ญ Kepler

Next.js React ClickHouse SQLite TypeScript Docker License

An AI-powered data agent that lets you query databases using natural language. Ask questions in plain English and get SQL queries, validated results, and auto-generated visualizations.

Kepler demo

โš™๏ธ How It Works

  1. ๐Ÿ’ฌ You ask a question in natural language
  2. ๐Ÿ” Kepler discovers relevant tables and recalls past learnings
  3. ๐Ÿง  The AI agent writes SQL, executes it read-only, and validates the results
  4. ๐Ÿ“Š Results are displayed with suggested charts when appropriate

โœจ Features

  • ๐Ÿ’ฌ Natural language querying โ€” Ask questions in plain English, get SQL + results
  • ๐Ÿ” Schema discovery โ€” Automatic introspection of tables, columns, types, and sample data
  • โœ… Smart validation โ€” Checks for zero rows, high NULL rates, suspicious aggregations
  • ๐Ÿง  Persistent memory โ€” Learns corrections, schema notes, and patterns across sessions
  • ๐Ÿ“‚ Query inference โ€” Upload historical SQL files for the agent to learn from
  • ๐Ÿ  ClickHouse support โ€” Connect to ClickHouse via CLICKHOUSE_URL; SQLite used when unset
  • ๐Ÿ“ค CSV upload โ€” Import CSV files with automatic type inference (into SQLite or ClickHouse)
  • ๐Ÿ“Š Auto-generated charts โ€” Bar, line, pie, and area charts via Recharts
  • ๐Ÿ”Ž Semantic search (RAG) โ€” Qdrant + Ollama embeddings for finding relevant context
  • ๐Ÿ“ Annotations โ€” Domain experts can annotate tables and columns with business meaning

๐Ÿ› ๏ธ Tech Stack

  • Frontend: Next.js 16, React 19, Tailwind CSS 4, Recharts
  • Backend: Next.js API routes, Better-sqlite3, ClickHouse, Vercel AI SDK
  • AI: OpenAI GPT-4o with tool-based agentic workflow
  • Vector search: Qdrant + Ollama (nomic-embed-text)
  • Infrastructure: Docker Compose

๐Ÿš€ Quick Start

Prerequisites

  • ๐Ÿ“ฆ Node.js 20+
  • ๐Ÿ“ฆ pnpm
  • ๐Ÿ”‘ An OpenAI API key

Local Development

# Install dependencies
pnpm install

# Configure environment
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY

# Start the dev server
pnpm dev

The app will be available at http://localhost:3000. By default it runs in demo mode with sample e-commerce data (customers, products, orders).

๐Ÿณ Docker Compose

# Set your API key
export OPENAI_API_KEY=sk-...

# Start all services (app + Qdrant + Ollama)
docker compose up -d

# Optional: run the enrichment sidecar for semantic search
docker compose --profile enrich up -d

This starts three services:

Service Port Purpose
๐Ÿ”ญ kepler 3000 Next.js application
๐Ÿ—„๏ธ qdrant 6333 Vector database
๐Ÿค– ollama 11434 Local embedding model

๐Ÿ”ง Configuration

Variable Required Default Description
OPENAI_API_KEY โœ… โ€” OpenAI API key
KEPLER_MODE โŒ demo demo seeds sample data, service uses existing DB
QDRANT_URL โŒ http://localhost:6333 Qdrant vector database URL
OLLAMA_URL โŒ http://localhost:11434 Ollama embedding service URL
EMBEDDING_MODEL โŒ nomic-embed-text Embedding model name
CLICKHOUSE_URL โŒ โ€” ClickHouse HTTP URL (enables ClickHouse mode)
CLICKHOUSE_DATABASE โŒ default ClickHouse database name
CLICKHOUSE_USER โŒ default ClickHouse username
CLICKHOUSE_PASSWORD โŒ โ€” ClickHouse password

When CLICKHOUSE_URL is set, data queries run against ClickHouse. Internal tables (memories, query history, annotations) always stay in SQLite. Semantic search is optional โ€” if Qdrant/Ollama are unavailable, Kepler falls back to keyword-based schema matching.

๐Ÿงฐ Makefile

Run make help to see all available commands.

make setup      # ๐Ÿ—๏ธ  Full first-time setup: install deps, start infra, pull embedding model
make up         # ๐Ÿš€ Start infra + dev server with ClickHouse
make dev        # ๐Ÿ’ป Dev server with SQLite only
make dev-ch     # ๐Ÿ  Dev server with ClickHouse
make infra      # ๐Ÿณ Start infra services (ClickHouse, Qdrant, Ollama)
make infra-stop # โน๏ธ  Stop infra services
make pull-model # ๐Ÿ“ฅ Pull the embedding model into Ollama
make enrich     # ๐Ÿ”Ž Run the RAG enrichment sidecar
make build      # ๐Ÿ“ฆ Production build
make start      # โ–ถ๏ธ  Production server (SQLite)
make start-ch   # โ–ถ๏ธ  Production server (ClickHouse)
make clean      # ๐Ÿงน Stop infra and remove volumes

๐Ÿ One-click from scratch

cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
make setup
make up

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ page.tsx              # ๐Ÿ  Landing page
โ”‚   โ”œโ”€โ”€ demo/page.tsx         # ๐Ÿ’ฌ Chat interface
โ”‚   โ”œโ”€โ”€ docs/                 # ๐Ÿ“– Documentation pages
โ”‚   โ””โ”€โ”€ api/
โ”‚       โ”œโ”€โ”€ chat/route.ts     # ๐Ÿง  AI agent (streaming, tools)
โ”‚       โ”œโ”€โ”€ schema/route.ts   # ๐Ÿ” Table schema endpoint
โ”‚       โ”œโ”€โ”€ upload/route.ts   # ๐Ÿ“ค CSV upload
โ”‚       โ”œโ”€โ”€ queries/route.ts  # ๐Ÿ“‚ Query history
โ”‚       โ”œโ”€โ”€ memories/route.ts # ๐Ÿง  Memory CRUD
โ”‚       โ””โ”€โ”€ annotations/      # ๐Ÿ“ Annotation CRUD
โ”œโ”€โ”€ components/               # ๐Ÿงฉ React components
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ db.ts                 # ๐Ÿ—„๏ธ Database operations (SQLite + ClickHouse delegation)
โ”‚   โ”œโ”€โ”€ clickhouse.ts         # ๐Ÿ  ClickHouse client + data functions
โ”‚   โ”œโ”€โ”€ rag.ts                # ๐Ÿ”Ž Qdrant vector search
โ”‚   โ”œโ”€โ”€ enrichment.ts         # โœจ Table context builder
โ”‚   โ”œโ”€โ”€ schema.ts             # ๐Ÿ“‹ Schema formatting & scoring
โ”‚   โ””โ”€โ”€ types.ts              # ๐Ÿ“ TypeScript interfaces
scripts/
โ””โ”€โ”€ enrich.ts                 # ๐Ÿ”„ Enrichment pipeline
data/
โ””โ”€โ”€ kepler.db                 # ๐Ÿ’พ SQLite database

๐Ÿ“œ Scripts

pnpm dev       # ๐Ÿ’ป Start development server
pnpm build     # ๐Ÿ“ฆ Production build
pnpm start     # โ–ถ๏ธ  Start production server
pnpm lint      # ๐Ÿ” Run ESLint
pnpm enrich    # ๐Ÿ”„ Run the enrichment pipeline

๐Ÿ“„ License

Private