← Learning

pgvector

A linear, one-concept-per-lesson path through pgvector, the Postgres extension that turns an ordinary relational database into a place to store and search embeddings, from your first vector column to a production-shaped FastAPI RAG service. 28 lessons · 3 tiers.

Prerequisites: Completion of LangChain & Agent Building Lessons 27-29, where notes.txt was loaded, split into chunks, embedded, and searched with InMemoryVectorStore. That lesson was honest about its own limit: fine for learning, not for production. This course picks up exactly there and builds the durable, production-shaped version, on Postgres.

Lessons use Google's Gemini free tier (gemini-embedding-001 for embeddings, gemini-3.5-flash-lite for chat), the same models as the other courses. Setup also needs a local Postgres with pgvector, run via `docker compose up -d` from the project root, a normal Postgres 17 with the vector extension already compiled in, exposed on localhost:5433 to avoid clashing with any other Postgres already running.

Built on pgvector, the Postgres extension this course teaches.

Course source

Every lesson's README and lesson.py for this course live in the ai-agent-engineering repo.

View on GitHub →
pgvector

Beginner

Postgres as a place to store and search vectors.

  1. 01What Is pgvector?GitHub
  2. 02Connecting With psycopgGitHub
  3. 03The vector(N) Column TypeGitHub
  4. 04Storing Real EmbeddingsGitHub
  5. 05The Three Distance OperatorsGitHub
  6. 06Similarity Search BasicsGitHub
  7. 07Filtering With MetadataGitHub
  8. 08Updating and Deleting VectorsGitHub
  9. 09Checkpoint: Notes Semantic Search CLIGitHub

Intermediate

Indexing, hybrid search, and talking to Postgres like an app would.

  1. 10Exact vs. Approximate SearchGitHub
  2. 11The ivfflat IndexGitHub
  3. 12The hnsw IndexGitHub
  4. 13Choosing a Distance MetricGitHub
  5. 14EXPLAIN ANALYZE for Vector QueriesGitHub
  6. 15Batch Inserts and UpsertsGitHub
  7. 16Hybrid Search: Text and VectorGitHub
  8. 17Reranking ResultsGitHub
  9. 18Connection PoolingGitHub
  10. 19Checkpoint: Hybrid Search APIGitHub

Advanced

Production concerns, and closing the loop with LangChain.

  1. 20LangChain pgvector IntegrationGitHub
  2. 21A Persistent RAG PipelineGitHub
  3. 22Schema Design for Multi-Tenant VectorsGitHub
  4. 23Partitioning Large TablesGitHub
  5. 24Index Build Performance and MaintenanceGitHub
  6. 25Quantization and halfvecGitHub
  7. 26Monitoring and ObservabilityGitHub
  8. 27Migrations and Re-Embedding DriftGitHub
  9. 28Capstone: A FastAPI RAG ServiceGitHub
Start at Lesson 1

Contact

Book a Call