pgai documentation
Supercharge your PostgreSQL database with AI capabilities. Supports:
pgai documentation
Section titled “pgai documentation”Supercharge your PostgreSQL database with AI capabilities. Supports:
- Ability to call out to leading LLMs like OpenAI, Ollama, Cohere, and more via SQL.
- Built-in utilities for dataset loading and processing
All with the reliability, scalability, and ACID compliance of PostgreSQL.
pgai install
Section titled “pgai install”- Install pgai with Docker: run pgai in a container environment.
- Install pgai from source: install pgai from source.
pgai model calling
Section titled “pgai model calling”Model calling allows you to call out to LLM models from SQL. This lets you leverage the power of LLMs for a variety of tasks, including classification, summarization, moderation, and other forms of data enrichment.
The following models are supported (click on the model to learn more):
| Model | Tokenize | Embed | Chat Complete | Generate | Moderate | Classify | Rerank |
|---|---|---|---|---|---|---|---|
| Ollama | ✔️ | ✔️ | ✔️ | ||||
| OpenAI | ✔️️ | ✔️ | ✔️ | ✔️ | |||
| Anthropic | ✔️ | ||||||
| Cohere | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ||
| Voyage AI | ✔️ | ||||||
| Huggingface (with LiteLLM) | ✔️ | ||||||
| Mistral (with LiteLLM) | ✔️ | ||||||
| Azure OpenAI (with LiteLLM) | ✔️ | ||||||
| AWS Bedrock (with LiteLLM) | ✔️ | ||||||
| Vertex AI (with LiteLLM) | ✔️ |
- Usage examples:
- Delayed embed: run pgai using pgai or TimescaleDB background actions.
- Moderate comments using OpenAI: use triggers or actions to moderate comments using OpenAI.
pgai utils
Section titled “pgai utils”- Load dataset from Hugging Face: load datasets from Hugging Face’s datasets library directly into your PostgreSQL database.
pgai operations and security
Section titled “pgai operations and security”- Secure pgai with user privilages: grant the necessary permissions for a specific user or role to use pgai functionality.
- A guide to securely handling API keys: learn how to securely handle API keys in your database.