Master pgvector, RAG pipelines, and in-database ML. From embeddings to production — everything you need to build AI applications in 1,065 pages.

-- 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-- 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
)
)
)
);In-database embedding generation, chunking strategies, prompt engineering, semantic caching, and evaluation — all through SQL and pgai.
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.
Replaced our entire Pinecone setup with pgvector after reading Chapter 3. Same latency, one fewer service to maintain.
The RAG chapter alone saved us weeks. Production-ready patterns, not academic exercises.
Finally a book that treats PostgreSQL as a first-class AI platform. The feature engineering chapter is gold.
PostgreSQL for AI is a comprehensive technical book that teaches developers how to use PostgreSQL as a unified platform for AI applications. It covers pgvector, RAG pipelines, recommendation systems, feature engineering, and in-database machine learning across 13 chapters and 1,065 pages. Instead of managing separate vector databases and ML platforms, you learn to build everything within PostgreSQL.
pgvector is a PostgreSQL extension that adds vector similarity search directly inside your existing database. Unlike dedicated vector databases like Pinecone or Weaviate, pgvector lets you join vectors with relational data, use ACID transactions, and avoid syncing data between systems. The book covers HNSW, IVFFlat, and DiskANN indexes for production-grade performance.
In-database machine learning means training and running ML models directly inside PostgreSQL using extensions like PostgresML — no need to export data to external tools. The book teaches you to build feature engineering pipelines with SQL window functions, train models, and serve predictions all within your database.
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.