Study how a transformer language model's forward pass works by reading it expressed as SQL.
Experiment with pgvector for storing and multiplying model weight vectors inside a database.
Run small text completions directly from a SQL query for teaching or demo purposes.
| omarish/llm-sql | saiprajoth/timescaledb-lab | akshayramabhat/claude-security-kit | |
|---|---|---|---|
| Stars | 1 | 1 | 0 |
| Language | PLpgSQL | PLpgSQL | PLpgSQL |
| Setup difficulty | moderate | moderate | — |
| Complexity | 4/5 | 3/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Requires Docker, the uv Python tool, and a psql client, plus downloading and exporting GPT-2 weights before first run.
llm-sql is a project that runs GPT-2, a small text generating AI model, entirely inside a Postgres database using plain SQL. Every part of how the model produces text, including looking up word pieces, tracking position in a sentence, its internal math layers, and even the process that breaks input text into tokens, is written as SQL functions instead of the usual Python or specialized AI code. The model's weights, which are the numbers the AI learned during training, are stored as regular database rows using a Postgres extension called pgvector that is built for storing and comparing lists of numbers efficiently. When you type a SQL command like asking it to complete the phrase "Hello, I", the database itself performs all the calculations needed to guess what text comes next, one word piece at a time. This is explicitly a toy and learning project rather than a fast or production ready tool. Generating each word piece takes about one second, since the database is doing work that would normally run on specialized AI hardware. The project does include a caching trick so that generating a new word only requires looking at the newest input rather than reprocessing the whole conversation each time, which keeps it from getting slower as the text grows. To try it, you need Docker to run the Postgres database, a Python tool called uv to manage dependencies, and the psql command line client. The setup process downloads the GPT-2 model, exports its weights into files, loads them into the database, and installs the SQL functions. A demo script then lets you type a prompt and see the generated text. The author is upfront that this should never be used anywhere exposed to the internet, since the included database setup disables normal safety checks and uses simple default passwords, only meant for a private test on your own machine. It only supports the smallest version of GPT-2, and its word splitting logic is a close but not perfect match for the original.
A learning project that runs GPT-2 text generation entirely inside a Postgres database, implementing the whole model as SQL functions using the pgvector extension.
Mainly PLpgSQL. The stack also includes PLpgSQL, Postgres, pgvector.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.