Nadoo AI uses PostgreSQL 16 with the pgvector extension as its primary data store. PostgreSQL handles relational data, user accounts, documents, and vector embeddings for semantic search — all in a single database.The official Docker image pgvector/pgvector:pg16 ships with the vector extension pre-installed.
The initialization script creates the following extensions automatically:
Copy
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- UUID primary key generationCREATE EXTENSION IF NOT EXISTS "vector"; -- Vector similarity searchCREATE EXTENSION IF NOT EXISTS "pg_trgm"; -- Trigram-based text search
After installation, connect as a superuser and run the init script:
Copy
CREATE DATABASE nadoo;CREATE USER nadoo WITH PASSWORD 'your_secure_password';GRANT ALL PRIVILEGES ON DATABASE nadoo TO nadoo;\c nadooCREATE EXTENSION IF NOT EXISTS "uuid-ossp";CREATE EXTENSION IF NOT EXISTS "vector";CREATE EXTENSION IF NOT EXISTS "pg_trgm";CREATE SCHEMA IF NOT EXISTS nadoo;GRANT ALL ON SCHEMA nadoo TO nadoo;GRANT ALL ON SCHEMA public TO nadoo;
Never use the default development password (nadoo_local or 4432646294A404D6351) in production. Set a strong NADOO_DB_PASSWORD through environment variables or a .env file.
For large-scale embedding workloads, add these settings:
Copy
-- Increase work_mem for vector similarity operationsALTER SYSTEM SET work_mem = '64MB';-- Create an IVFFlat index for faster approximate nearest-neighbor searchCREATE INDEX ON embeddings USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);-- Or use HNSW for higher recall (PostgreSQL 16+ with pgvector 0.5+)CREATE INDEX ON embeddings USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64);
The backend configuration also exposes NADOO_EMBEDDING_DIMENSION (default 1536) and NADOO_VECTOR_STORE_TYPE (default pgvector). Make sure the index dimension matches your embedding model’s output dimension.
Always test your backup files in a separate environment before relying on them for disaster recovery. Restoring a backup into an existing database may cause conflicts with Alembic migration state.
Nadoo AI uses Alembic for schema migrations. After any model change, migrations must be created and applied through the CLI:
Copy
# Generate a new migration from model changesalembic revision --autogenerate -m "describe your change"# Apply all pending migrationsalembic upgrade head# Roll back the last migrationalembic downgrade -1
Never create migration files manually or edit existing revision IDs. Always use alembic revision --autogenerate and review the generated file before applying.
Ensure you are using the pgvector/pgvector:pg16 Docker image, not the standard postgres:16 image. The pgvector image ships with the extension pre-compiled.For standalone installs, verify the extension is available:
Copy
SELECT * FROM pg_available_extensions WHERE name = 'vector';
Too many connections
If you see FATAL: too many connections for role, increase max_connections or reduce the backend pool size:
Copy
# Check current connection countdocker exec nadoo-postgres psql -U nadoo -c "SELECT count(*) FROM pg_stat_activity;"
Adjust NADOO_DB_POOL_SIZE and NADOO_DB_MAX_OVERFLOW in your environment variables to match available connections.
Slow vector search queries
Create an appropriate index for your embedding dimension:
Copy
-- Check if an index existsSELECT indexname FROM pg_indexes WHERE tablename = 'embeddings';-- Create HNSW index (recommended for pgvector 0.5+)CREATE INDEX CONCURRENTLY ON embeddings USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64);