realZachi/pg-jev on GitHub
- Stars
- 329
- Forks
- 18
- Language
- Shell
- Last push
- 18 Sep 2026
Post on X
- Views
- 478,636
- Likes
- 2,835
- Reposts
- 186
Read from GitHub and X on . Counts change daily.
Reported by the author
- 2k rows, cold
- ~3.5s, $0.012
first run ≈ 3.5 s in 100 requests, ≈ 296k input tokens, ≈ $0.012
github.com - 2k rows, cached
- ~50ms
second run ≈ 50 ms
github.com - Batch overhead
- 175 vs 435 tok
about 435 tokens for one row alone vs 175 per row in batches of 20
github.com
pg-jev is a PostgreSQL extension that lets you write plain-language conditions straight into SQL, such as WHERE jev(tickets, 'the customer is angry'). Every row is judged by Jev, which returns a calibrated probability rather than generated text, so there’s no index, embeddings, or vector column to maintain. The extension also adds jev_prob, jev_choice, and jev_score functions, which behave as ordinary SQL functions and compose with joins, GROUP BY, LIMIT, and ORDER BY.
Rows that a cheaper predicate in the same WHERE already excludes, such as age > 60, are skipped rather than sent to Jev. When a condition does need to run, realZachi’s build batches 20 rows into one request with one yes/no question per row, using Jev’s noul primitive, which amortizes the roughly 270-token request overhead: about 435 tokens to judge one row alone against 175 tokens per row in a batch of 20. Answers are cached per row for the session, so sorting by probability or changing a threshold after the first pass costs nothing.
Measured on a 2,000-row table from Europe, with about 190ms to the API, realZachi reports a cold first run of about 3.5 seconds across 100 requests, using roughly 296,000 input tokens for about $0.012. A second run against the same condition, served from cache, drops to about 50ms, and adding LIMIT 3 on a fresh condition takes about 0.6 seconds since the read-ahead can stop early. The extension is published on PGXN. It needs PostgreSQL 14 to 17 with plpython3u and a superuser, so managed hosts such as Supabase, Neon and RDS cannot run it.
How it uses Jev
#!/usr/bin/env python3
"""Deterministic stand-in for https://api.typesafe.ai/v1/systemone, used by the regression tests.
Rules (so expected output is stable):
noul -> 0.9 if the LAST word of `state.condition` appears (case-insensitively) in the row JSON, else 0.1
score -> level index = length of the row JSON modulo number of levels (one-hot probabilities)
choice -> option index = length of the row JSON modulo number of options
A condition containing "trigger422" returns HTTP 422 (non-retryable error path).
usage.input_tokens = len(request body) // 4
Run: python3 test/mock_api.py [port] (default 8765)
"""
import json, sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
class Handler(BaseHTTPRequestHandler):
