Repository navigation
Database
ChatHub uses PostgreSQL exclusively. The browser and installed PWA are clients of the server API; there is no PGlite, IndexedDB/Dexie, or Electron database runtime. Old local-edition JSON exports are handled only by the account import workflow under Settings -> Storage.
Knowledge Base semantic retrieval is backed by the PostgreSQL vector
extension. For Docker Compose, use pgvector/pgvector:pg16; for managed
PostgreSQL, enable pgvector before starting ChatHub. Migration
0005_pgvector.sql runs CREATE EXTENSION IF NOT EXISTS vector.
Knowledge embeddings use vector(1024). The database has a B-tree index on
the account/provider fingerprint and a partial HNSW vector_cosine_ops index
for document-chunk nearest-neighbor search. Cached question vectors are not in
that ANN index. Retrieval orders by cosine distance so PostgreSQL can use
HNSW. See Knowledge Base and RAG.
Migration 0053_add_rag_embedding_indexes.sql creates the HNSW index with
regular CREATE INDEX because Drizzle runs migrations in a transaction and
PostgreSQL does not allow CREATE INDEX CONCURRENTLY there. Reads remain
available during the build, but writes to embeddings are blocked until it
finishes. Schedule a maintenance window before upgrading a deployment with a
large embedding table.
- Migrations live in
packages/database/migrations/and are baked into the Docker image - Drizzle ORM tracks applied migrations via the
drizzle_migrationstable in PostgreSQL - On a fresh empty DB, all migrations (0000 → latest) run automatically on first container start
-
Never use
bun run db:pushagainst production — it bypasses migration tracking
Every migration that adds a table or column also includes an idempotent ensure* helper (CREATE TABLE IF NOT EXISTS / ALTER TABLE ADD COLUMN IF NOT EXISTS) that runs on every container startup, protecting against journal drift.
Background conversation generation adds migrations 0054–0056
(conversation_generation_operations, events, and steps) plus
ensureConversationGenerationOperations.cjs. Graphile Worker migrates its own
graphile_worker schema; Drizzle does not manage it. See
Background Conversation Generation.
If the UI shows repeated Request failed errors and logs contain column ... assistant_memory does not exist (PostgreSQL 42703), the database never received migration 0043_add_agent_assistant_memory.sql.
Fix:
- Use a current image tag that includes
0043_add_agent_assistant_memory, setDATABASE_URL, thendocker compose pullanddocker compose up -d(add--force-recreatefor a new container). Check logs fordatabase migration pass. - Or apply the SQL manually:
ALTER TABLE agents ADD COLUMN IF NOT EXISTS assistant_memory text;If the database was created or altered outside Drizzle's migration chain, fixing drizzle_migrations by hand is error-prone. Prefer: restore from a known-good backup and run the official image entrypoint against it, or export data you need, wipe the Postgres volume, and let a fresh container apply 0000 → latest automatically.
bun run db:generate # generate migration SQL from schema changes
bun run db:migrate # apply migrations locally
bun run db:studio # open Drizzle Studio- Home
- Quick Start
- Docker Deployment and Upgrades
- Authentication
- Model Providers
- Knowledge Base and RAG
- MarkItDown Sidecar
- Sandbox (OpenSandbox)
- OpenAI Compatible Cache Matrix
- Model Extension Options
- Memory & Context Compaction
- Background Conversation Generation
- Pasted Text
- Search
- Context Export
- Data Backup and Restore
- Image Generation
- Artifacts
- Inline SVG Diagrams
- Tools Hub
- MCP OAuth
- MCP Management
- Agent Skills
- Database
- Development
- Debug and Diagnostics
- Architecture Overview
- Docker Release
- Release Workflow