Skip to main content

PostgreSQL

Nibchat uses SQLite by default — no setup required. For teams that need a managed database or want to run multiple Nibchat instances against a shared store, PostgreSQL is supported as a drop-in replacement.

Enabling PostgreSQL

Set POSTGRESQL_DSN to your connection string:

environment:
- POSTGRESQL_DSN=postgres://user:password@db:5432/nibchat

Nibchat detects the variable at startup, connects to PostgreSQL, and runs all table migrations automatically. Existing SQLite deployments are unaffected — removing the variable reverts to SQLite.

Schema migrations

All tables are created with CREATE TABLE IF NOT EXISTS on every startup, so migrations are always idempotent. No external migration tool is required.

When the pgvector extension is available, Nibchat stores knowledge base embeddings as a native vector(1536) column with an HNSW index, enabling fast approximate nearest-neighbour search directly in SQL.

-- Nibchat creates this automatically when pgvector is present
CREATE INDEX IF NOT EXISTS knowledge_chunks_embedding_idx
ON knowledge_chunks USING hnsw (embedding vector_cosine_ops);

If pgvector is not installed, Nibchat falls back to in-memory cosine similarity automatically — no configuration change needed.

Installing pgvector

The easiest way is to use the official pgvector/pgvector Docker image:

services:
db:
image: pgvector/pgvector:pg16
environment:
POSTGRES_USER: nibchat
POSTGRES_PASSWORD: secret
POSTGRES_DB: nibchat
volumes:
- pg-data:/var/lib/postgresql/data

nibchat:
image: ghcr.io/nibchat-ai/nibchat:latest
environment:
- POSTGRESQL_DSN=postgres://nibchat:secret@db:5432/nibchat
depends_on:
- db

volumes:
pg-data:

Migrating from SQLite

There is no automated migration tool. If you need to carry over existing data, use a tool like pgloader or export/import via JSON. For most teams starting fresh with PostgreSQL is the practical approach.

Environment variables

VariableDescription
POSTGRESQL_DSNPostgreSQL connection string (e.g. postgres://user:pass@host:5432/db). When set, PostgreSQL is used instead of SQLite.