Knowledge Base AIVECTOR DATABASE SEARCH
WEEK 3
pgvector + Supabase + Drizzle

Vector Database Search

Queries stored embeddings inside Supabase PostgreSQL using the <=> cosine distance operator from the pgvector extension — no in-memory math, real database I/O.

OPERATORembedding <=> query::vector

pgvector cosine distance (lower = more similar)

COLUMN TYPEvector(1536)

PostgreSQL column storing 1536 floats per row

SIMILARITY1 - (embedding <=> q)

Convert distance → similarity (0 to 1)

Query the Vector Database

Week 2 vs Week 3 Comparison

Week 2 — In-Memory
  • Vectors stored in React state (RAM only)
  • Lost on page refresh
  • Cosine math runs in browser JS
  • Cannot scale beyond current session
Week 3 — pgvector / Supabase
  • Vectors persisted in PostgreSQL
  • Survives restarts, accessible to any client
  • Cosine math runs in the database engine
  • Can index millions of rows with HNSW/IVFFlat