A Go-powered CLI tool for retrieving electric vehicle battery specifications (capacity, power, chemistry) by make/model/year. Features intelligent similarity search using Neon PostgreSQL with pgvector and OpenAI embeddings, with Claude API fallback for low-confidence results.
- π Vector Similarity Search: Uses pgvector for semantic search of EV specifications
- π€ OpenAI Embeddings: Converts queries to embeddings for accurate similarity matching
- π§ Claude Fallback: Automatically falls back to Claude API when confidence < 0.8
- π Multiple Output Formats: Supports human-readable and JSON output
- β‘ Fast & Efficient: Built with Go for performance and reliability
The project follows a clean architecture pattern:
ev-oracle/
βββ cmd/ # CLI commands
β βββ root.go # Main query command
β βββ init.go # Database initialization
β βββ migrate.go # Migration commands
βββ migrations/ # Database migration files
β βββ 000001_init_schema.up.sql
β βββ 000001_init_schema.down.sql
βββ internal/
β βββ db/ # Database layer (pgx/v5, pgvector)
β βββ embedding/ # OpenAI embeddings service
β βββ llm/ # Claude API integration
β βββ models/ # Data models and configuration
βββ main.go # Entry point
- Go 1.21 or later
- PostgreSQL database with pgvector extension (Neon recommended)
- OpenAI API key
- Anthropic API key (for Claude)
git clone https://github.com/scaryPonens/ev-oracle.git
cd ev-oracle
go build -o ev-oracle .go install github.com/scaryPonens/ev-oracle@latestThe application uses environment variables for configuration:
| Variable | Description | Required |
|---|---|---|
NEON_DATABASE_URL |
PostgreSQL connection string (with pgvector) | Yes |
EMBEDDING_PROVIDER |
Embedding provider: openai or ollama (default: openai) |
No |
LLM_PROVIDER |
LLM provider: claude or ollama (default: ollama) |
No |
OPENAI_API_KEY |
OpenAI API key for embeddings (required if using OpenAI) | Conditional |
ANTHROPIC_API_KEY |
Anthropic API key for Claude (required if using Claude) | Conditional |
OLLAMA_URL |
Ollama API URL (default: http://localhost:11434) |
No |
OLLAMA_MODEL |
Ollama embedding model (default: nomic-embed-text) |
No |
OLLAMA_LLM_MODEL |
Ollama LLM model (default: llama3.2) |
No |
Using OpenAI (default):
NEON_DATABASE_URL=postgresql://user:password@host/database?sslmode=require
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...Using Ollama (default for LLM):
NEON_DATABASE_URL=postgresql://user:password@host/database?sslmode=require
EMBEDDING_PROVIDER=ollama
LLM_PROVIDER=ollama
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=nomic-embed-text
OLLAMA_LLM_MODEL=llama3.2
# ANTHROPIC_API_KEY not needed when using OllamaUsing Claude for LLM:
NEON_DATABASE_URL=postgresql://user:password@host/database?sslmode=require
EMBEDDING_PROVIDER=ollama
LLM_PROVIDER=claude
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=nomic-embed-text
ANTHROPIC_API_KEY=sk-ant-...The application automatically loads the .env file if it exists. You don't need to manually export the variables.
Note: The .env file is gitignored by default to keep your secrets safe.
Ollama is now the default LLM provider and can also be used for embeddings. To use Ollama:
-
Install Ollama: Download from ollama.com
-
Pull required models:
ollama pull nomic-embed-text # For embeddings ollama pull llama3.2 # For LLM (or any other model you prefer)
-
Start Ollama (if not running as a service):
ollama serve
-
Configure your
.envfile` (Ollama is the default for LLM):EMBEDDING_PROVIDER=ollama LLM_PROVIDER=ollama # This is the default, can be omitted OLLAMA_URL=http://localhost:11434 OLLAMA_MODEL=nomic-embed-text OLLAMA_LLM_MODEL=llama3.2
Important Note: The default database schema expects 1536-dimensional vectors (OpenAI's text-embedding-3-small). Ollama's nomic-embed-text produces 768-dimensional vectors. If you want to use Ollama, you'll need to:
- Create a migration to change the embedding dimension in the database schema, OR
- Use an Ollama model that produces 1536 dimensions (if available)
To create a migration for Ollama's 768 dimensions:
# Create a new migration file
# migrations/000002_update_embedding_dimension.up.sql
ALTER TABLE ev_specs ALTER COLUMN embedding TYPE vector(768);
DROP INDEX IF EXISTS ev_specs_embedding_idx;
CREATE INDEX ev_specs_embedding_idx ON ev_specs
USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);Initialize the database schema by running:
ev-oracle initThis will run all pending migrations to set up the necessary tables and indexes. The pgvector extension will be automatically enabled.
For Neon databases, pgvector is typically pre-installed.
The project uses golang-migrate for database schema management. Migration files are stored in the migrations/ directory.
Run all pending migrations:
ev-oracle migrate upRoll back the last migration:
ev-oracle migrate downRun a specific number of migrations:
ev-oracle migrate --steps 2 # Run 2 migrations forward
ev-oracle migrate --steps -1 # Roll back 1 migrationTo create a new migration, add files to the migrations/ directory following the naming pattern:
00000N_description.up.sql- Migration to apply00000N_description.down.sql- Migration to rollback
The migration number should be sequential and unique.
ev-oracle Tesla "Model 3" 2023Output:
Make: Tesla
Model: Model 3
Year: 2023
Capacity: 75.0 kWh
Power: 283.0 kW
Chemistry: NMC (Nickel Manganese Cobalt)
Confidence: 1.00
Source: database
ev-oracle --json Nissan Leaf 2022Output:
{
"make": "Nissan",
"model": "Leaf",
"year": 2022,
"capacity_kwh": 40.0,
"power_kw": 110.0,
"chemistry": "Li-ion",
"confidence": 0.95,
"source": "database"
}ev-oracle --help- Exact Match: First tries to find an exact match in the database by make/model/year
- Similarity Search: If no exact match, converts the query to an embedding and performs vector similarity search
- Confidence Check: If the best match has confidence β₯ 0.8, returns it
- LLM Fallback: If confidence < 0.8, queries Claude API for the information
- Output: Returns the result in the requested format (text or JSON)
- cmd/root.go: Main CLI command implementation
- cmd/init.go: Database initialization command
- cmd/migrate.go: Database migration commands
- migrations/: SQL migration files (up/down)
- internal/db/: Database operations using pgx/v5 and pgvector with migration support
- internal/embedding/: OpenAI embeddings integration
- internal/llm/: Claude API integration for fallback queries
- internal/models/: Data models and configuration using functional options pattern
go build -o ev-oracle .go test ./...Contributions are welcome! Please feel free to submit a Pull Request.
See LICENSE file for details.
- Built with Cobra for CLI
- Uses pgx for PostgreSQL connectivity
- Database migrations powered by golang-migrate
- Powered by OpenAI embeddings
- Falls back to Anthropic Claude for intelligent responses