PostgreSQL and pgvector: RAG setup with Ollama
Learn to set up PostgreSQL 16 with pgvector in Docker, generate embeddings with Ollama, and search a sample of 10 Airflow documentation pages.
Player not loading? Watch on YouTube
This tutorial builds a document search workflow with PostgreSQL 16, pgvector and Ollama. It covers the retrieval side of RAG: storing document embeddings and finding relevant pages. The demonstration ends with search results rather than a generated answer.
The presenter starts with a repository containing a Dockerfile and Docker Compose configuration. After launching PostgreSQL, he connects on localhost port 5432, enables the vector extension and creates a table with an embedding column. A Python script then scrapes Airflow documentation and stores each page's title, source URL, content and embedding. The sample run saves 10 pages.
Ollama supplies the local AI embeddings. The first script attempt fails because it cannot connect to Ollama; the presenter starts its separate Docker Compose service and waits for the model download before retrying. The setup also requires a Python virtual environment and the supplied requirements file. The metadata identifies the embedding model as nomic-embed-text.
A separate search interface demonstrates retrieval. Queries for "pip" and "Docker" bring an Airflow installation page to the top, while "local" returns the local executor documentation as the most relevant result. These examples show the behavior of the small sample dataset; they do not establish search quality or performance on larger collections.