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:
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: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.See also
- Setting up an AI API key — where to put the key and how to keep it out of logs
- AI prompts in MySQL — prompting patterns that survive contact with a table
- Generating vector embeddings — storing vectors and searching them
- Install extensions — how
INSTALL EXTENSIONworks and where the server looks for a bundle - Available extensions — the full catalog
- villagesql/vsql-ai — source, build instructions, and the known limitations

