Stop managing four services for what should be one query. Vector search, RAG pipelines, feature stores, and in-database ML — all from the database you already run.

-- Find products by meaning, not keywords WITH query AS ( SELECT ai.ollama_embed( 'nomic-embed-text', 'comfortable running shoes for beginners' ) AS embedding ) SELECT p.name, p.category, 1 - (p.embedding <=> q.embedding) AS similarity FROM products p, query q WHERE p.embedding IS NOT NULL ORDER BY p.embedding <=> q.embedding LIMIT 5;
Through a running example — RecSys, an AI-powered recommendation platform — you'll implement production patterns chapter by chapter.
pgvector with HNSW, IVFFlat, and DiskANN indexes. Hybrid search combining semantic similarity with full-text ranking and business filters.
$ psql ai_db CREATE INDEX idx_products_hnsw ON products USING hnsw ( embedding vector_cosine_ops ) WITH (m = 16, ef_construction = 128); ✓ index created — 0.47s
In-database embedding generation, chunking strategies, prompt engineering, semantic caching, and evaluation — all through SQL and pgai.
-- RAG: retrieve & generate in one query SELECT ai.ollama_chat_complete( 'llama3', jsonb_build_array( jsonb_build_object( 'role', 'system', 'content', 'Answer using context:' || ( SELECT string_agg(chunk, E'\n') FROM docs ORDER BY embedding <=> $query_vec LIMIT 5 ) ) ) );
Point-in-time correct features with window functions, materialized views, continuous aggregates, and a lightweight feature registry.
Train and serve models with PostgresML. Regression, classification, anomaly detection, and custom PL/Python pipelines — no external infrastructure.
LISTEN/NOTIFY, pg_cron scheduling, SKIP LOCKED job queues, and Debezium CDC for streaming AI pipelines that react to data changes.
Performance tuning, security hardening, cloud deployment, monitoring, backup strategies, and CI/CD patterns for AI-enhanced PostgreSQL.
Each chapter builds on the last. Every code example runs against a real PostgreSQL instance via Docker Compose.
Whether you're adding AI to an existing app or architecting from scratch, the book meets you where you are.
You run PostgreSQL in production and want to add semantic search, recommendations, or LLM features — without new infrastructure or vendor lock-in.
You know ML but not databases. Learn how feature engineering, model serving, and vector search work inside the database that stores your data.
You're weighing dedicated vector databases and ML platforms against what PostgreSQL handles natively. Get the benchmarks and decision frameworks.
Software engineer and technical author specializing in PostgreSQL, artificial intelligence, and the intersection of databases with modern AI systems. Every pattern in this book comes from production experience.
No. The book introduces every concept from scratch. You need working SQL knowledge and basic Python. All ML theory is explained inline, with code you can run immediately.
PostgreSQL 17 via Docker Compose. The included stack bundles pgvector, TimescaleDB, pg_cron, and PostgresML — one command to get everything running.
Not yet. The book ships as DRM-free PDF + EPUB. Both are optimized for reading — code blocks are syntax-highlighted and all diagrams are vector graphics.
No. All examples use Ollama with CPU-friendly models (nomic-embed-text, llama3.2). A laptop with 16 GB RAM is sufficient. GPU just makes things faster.
Yes. The patterns work on any PostgreSQL with pgvector: AWS RDS, Google Cloud SQL, Azure Flexible Server, Supabase, Neon, or your own setup.
Yes. You get free lifetime updates for the edition you purchased. When pgvector 0.9 or PostgreSQL 18 lands, the book will be updated and you’ll get the new version.