Skip to content

Day 1 -- Embeddings & Vector Stores

You can't build RAG without embeddings. They're the bridge between natural language and math that lets a database find "sentences about cats" when you type "feline behavior." Day 1 takes you from zero to a working vector store: what embeddings are, how to generate them, how to stuff them into PostgreSQL with pgvector, and how to query them with similarity search. By the end of today you'll have a database that understands meaning, not just keywords.

What you'll have by the end of today

  • A working PostgreSQL database with pgvector, populated with real embeddings and queryable by semantic similarity
  • The ability to generate embeddings from OpenAI, Gemini, or Cohere APIs with working Python code
  • A clear understanding of what an embedding is, why cosine similarity matters, and when k-NN search breaks down
  • Hands-on experience with HNSW indexes, distance thresholds, and metadata filtering

Before you start

ToolVersionPurposeInstall
Python3.10+All code examplespython.org
PostgreSQL16+Vector store hostapt install postgresql-16
pgvector extension0.7+Vector type + indexesapt install postgresql-16-pgvector
An API key--Embeddings providerOpenAI, Google Gemini, or Cohere
bash
pip install psycopg2-binary pgvector openai

You'll also want the psql client available. If PostgreSQL isn't set up yet, run through the Practical Fundamentals database setup -- it takes about 20 minutes.

Lessons

  1. What Are Embeddings -- dense vectors that capture semantic meaning, the embedding space, cosine similarity, and why embeddings work for search when keywords fail
  2. Generating Embeddings -- calling OpenAI text-embedding-3-small, Gemini embedding-2, and Cohere embed; understanding dimensionality, batching, and cost per token
  3. pgvector Setup -- CREATE EXTENSION vector, creating tables with vector(768), HNSW indexes, connecting from Python with psycopg2
  4. Storing and Querying -- INSERT with embeddings, cosine similarity search with <=>, ORDER BY distance, LIMIT, and basic filtering
  5. Similarity Search -- k-NN fundamentals, threshold filtering to avoid garbage results, metadata filtering, and interpreting distance scores

Next: Day 2 -- Chunking & Ingestion