GitHub - realZachi/pg-jev: Ask your Postgres tables questions in plain language. A PostgreSQL extension powered by TypeSafe's Jev.

Open original

Jev is a Postgres extension that lets you filter and rank database rows using plain-language conditions instead of SQL logic, powered by TypeSafe's AI model that returns probabilities rather than generated text. It works without indexes, embeddings, or vector columns—just write what you want and Postgres handles the rest.

  • Accuracy drops noticeably above batch sizes of 20-25 rows (92-98% at 40 rows, 77-94% at 80 rows), so the default batch size of 20 balances speed and correctness.
  • A typical 2,000-row query costs about $0.012 on first run (~3.5 seconds), drops to 50ms on repeat thanks to session caching, and subsequent queries with LIMIT clauses can run in 0.6 seconds by stopping early.
  • Requires PostgreSQL 14-17 with plpython3u and superuser access—doesn't work on managed hosts like Supabase, Neon, or RDS that restrict these, and row data gets sent to TypeSafe's API so it's unsuitable for sensitive information.

Jev is a PostgreSQL extension that uses TypeSafe's System One language model to filter and classify database rows based on plain-English conditions instead of traditional SQL predicates. You write conditions like "the name is European" or "the customer is angry," and the model returns calibrated probabilities. It works as ordinary SQL functions that compose with standard operations—WHERE clauses, joins, GROUP BY, ORDER BY—so you can combine it with cheaper filters to skip unnecessary API calls. The extension handles rows in batches (default 20 per request) streamed in physical order, keeps connections pooled, and caches answers per row for the session, so reruns and threshold changes are free. Performance depends heavily on batch size. On a 2,000-row test table, the first run took 3.5 seconds and cost about $0.012; the second run dropped to 50 milliseconds thanks to caching. A LIMIT 3 on a new condition took 0.6 seconds. Accuracy is solid at batch sizes of 20 (100% correct on test data), but drops noticeably at 40 rows (92–98%) and more at 80 rows (77–94%). Wider rows don't hurt accuracy, and batches of 20 cost only 4% more tokens than batches of 40 while staying equally fast because latency barely depends on request size. Installation requires PostgreSQL 14–17 with plpython3u enabled, superuser access, and a TypeSafe API key. Managed hosts like Supabase and Neon that restrict superuser privileges or disable plpython3u won't work. You can install via pgxn, compile from source, or use a Docker image. The extension exposes functions like jev_prob() for probabilities, jev_choice() to pick from options, and jev_score() to rank rows on ordered scales. Configuration is straightforward—set the API key via environment variable or per-session, adjust batch size and concurrency as needed, and monitor costs with jev_stats().

Ask about this article