pgjev

Filter Postgres rows in plain .

Write the condition the way you would say it. Postgres does the rest.

psql
SELECT * FROM reviews
WHERE jev(reviews, 'the customer is angry');

Four functions. Same row, different answer.

SQL
SELECT *
FROM people
WHERE jev(people, 'the name is European')
  AND age > 40;

A boolean predicate. It composes with every other condition, join and index in the query.

One scan, a handful of requests.

Every row goes to the API, by design. Filter with indexed predicates first when the table is large.

  1. Read ahead

    On the first call for a table and condition, the extension reads the table up front instead of judging row by row.

  2. Batch

    Rows are packed 40 per request into one shared state with a yes/no question per row.

  3. Judge in parallel

    Jev evaluates every question over that state at once. Six requests run concurrently by default.

  4. Cache

    Answers are cached per row content for the session. Changing the threshold or sorting by probability costs nothing.

First run, 2,000 rows
<2 s
Cost of that run
~$0.009
Second run, cached
6 ms

Plain SQL functions.

All functions and settings
jev(row, condition [, threshold])boolean

The WHERE predicate. True when the probability clears the threshold, 0.5 by default.

jev_prob(row, condition)float8

Probability from 0 to 1 that the row satisfies the condition.

jev_score(row, question, levels)float8

Probability-weighted position on an ordered list of levels.

jev_choice(row, question, options)text

The most likely option for the row.

jev_eval(row, question, kind, options)jsonb

The full raw answer: probabilities, legend and confidence.

jev_stats()jsonb

Requests, tokens, estimated cost and cache hits for this session.

Install in two commands.

Requires PostgreSQL 14 to 17 with plpython3u and a TypeSafe API key. A Docker image is included for trying it out.

Installation guide
shell
git clone https://github.com/realZachi/pg-jev.git && cd pg-jev
make install
psql
CREATE EXTENSION jev;
SET jev.api_key = 'your-typesafe-key';