Skip to main content
Most database AI work follows the same shape: read rows, send them to a model, wait, write the answers back. vsql_ai removes the middle by calling the model from SQL. Two functions cover it, one for a prompt and one for an embedding, and both work against Anthropic Claude, Google Gemini, OpenAI, or a model running locally through Ollama.

Install

vsql_ai.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

provider is anthropic, google, openai, or local. A local model runs through Ollama and takes an empty API key. ai_embedding supports Google, OpenAI, and local models.

Example

Ask a local model a question:
A model answers in its own words, so your reply will differ from that one. Turn text into a vector and check its width:
A hosted provider takes the same call with a key:
On VillageSQL 0.0.6 and earlier the result carries the binary character set, and two things follow. A JSON function or a JSON column rejects it, so the embedding example above fails there with ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'. Inside JSON_OBJECT() or JSON_ARRAY() it is accepted but base64-encoded, so SELECT JSON_OBJECT('v', ai_prompt(...)) gives {"v": "base64:type15:UGFyaXMu"}. Wrap the call in CONVERT(... USING utf8mb4) on those versions. It is unnecessary on 0.0.7 and later, where the examples above run as written.
Each call blocks its statement while the model answers, and each call costs whatever the provider charges. One call per row across a large table is slow and expensive. Keep an API key out of the statement text, where it would land in the query log, by setting it into a variable first.

See also