Jev-Style Decision Models in MySQL with vsql-ai VillageSQL's vsql-ai 0.0.9 extension lets MySQL databases call decision models such as Google's Gemini Decision 1, TypeSafe's Jev and OpenAI's Decisions API directly from SQL through an ai_decision() function, returning a probability per row that is stored in a JSON column. The extension, which runs on VillageSQL's drop-in MySQL replacement, reads API keys from the MySQL keyring by name, and the post recommends labeling at least 100 to 150 rows per answer in the same table so a classification threshold can be chosen with a query rather than guessed. MySQL https://villagesql.com/blog/tag/mysql/ Jev-Style Decision Models in MySQL with vsql-ai Use probabilities from Gemini Decision, TypeSafe Jev, and OpenAI's Decisions API in MySQL with vsql-ai, and pick a classification threshold in SQL. Decision models such as TypeSafe's Jev, Google's Gemini Decision 1, and OpenAI's Decisions API answer a question about an input with a probability, which makes them useful for classifying rows in a database. Getting a probability score from these models takes one API call per input. The harder part is choosing the cutoff that counts as yes, and knowing that it's right for your data. OpenAI's guide https://developers.openai.com/api/docs/guides/decisions on this topic gives an answer: "Use labeled examples from your application to set thresholds for routing, filtering, or review." That means that to derive a threshold, you need some rows where you already know the right answer. Your application may already store these answers. For example, a support application may record which team resolved each ticket. Before you use a stored answer as a label, check two things: that it answers the same question that you ask the model, and that it is correct. If you don't have such a column, you can label a sample of rows by hand and store each label in a column next to the input. Label at least 100 to 150 rows of each answer more when an answer is rare . Either way, the labels should be in the same table as the data. The vsql-ai https://github.com/villagesql/vsql-ai extension can then write a decision model's probabilities there too, so checking a threshold becomes a query. vsql-ai is an extension that runs on VillageSQL https://villagesql.com/ , a drop-in replacement for MySQL that adds PostgreSQL-style extensions to MySQL. Its ai decision function lets a database call decision APIs directly from SQL. The rest of this post walks through an example of using this function. Asking a decision model from SQL The example in this post is a support team that wants to send billing tickets to a billing queue and other tickets to a general queue. We wrote 20 short support tickets for it and labeled each one by hand, 10 as billing and 10 as other. That is enough to show the method, but too few to choose a real threshold. The tickets are in a tickets table, with the ticket text in a body column, our label in an is billing column, and an empty JSON column, answers , for the model's response. Setup takes two statements. First, you store the API key in the MySQL keyring, where vsql-ai 0.0.9 reads it. After that, everything refers to the key by name, so a query does not carry the key itself: SELECT keyring key store 'gemini key', 'SECRET', '