pg_pink_slonik
pg_pink_slonik · Run small Llama models inside PostgreSQL using C or SQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102476 | pg_pink_slonik | pg_pink_slonik | 0.1.0 | RAG | PostgreSQL | C |
PostgreSQL · 17, 18, 19
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pg_pink_slonik 0.1.0 runs small Llama models inside PostgreSQL, with weights stored in tables and a C or SQL execution engine. The reviewed source supports PostgreSQL 17–19 in UTF-8 databases. It is experimental and model output can be incorrect.
Import and Ask
After installing the matching library and SQL files, a superuser can enable the extension. It requires plpgsql, creates the fixed pink_slonik schema and needs no shared preload.
The import path is read by the database server. The caller needs superuser privileges or membership in pg_read_server_files, and the server OS user needs access to the files. Prepare a Hugging Face model directory containing config.json, tokenizer.json and a single bfloat16 model.safetensors. The supported architecture is LlamaForCausalLM, without attention_bias, mlp_bias or rope_scaling. Sharded weights are not accepted. Models with a different byte-level BPE splitting rule can tokenize differently even if import succeeds; the tested family is SmolLM2.
Generation and Permissions
pink_slonik.ask accepts a prompt, model, engine, token limit and optional system prompt. The default engine is c; sql is slower and also needs database TEMPORARY privilege. With no model argument, pink_slonik.default_model selects the model, otherwise the most recently imported model is used. ask assumes ChatML; use the lower-level pink_slonik.generate with explicit token IDs for other templates.
Ordinary callers need schema USAGE and SELECT on model, tensor, tensor_row, vocab, merge and byte_map. SET client_min_messages = debug1 exposes generated tokens; SET pink_slonik.stats = off suppresses timing notices. Review who can see prompts and generated content through application logging.
Memory and Maintenance
The C engine caches weights separately in every backend at roughly four bytes per parameter. Connection pools can multiply this memory use. After editing tensor rows in place, reset the cache in affected sessions; dropping a model clears it in the calling backend, while other backends notice the removal on their next C-engine call.