pgvector brings vector similarity search directly into PostgreSQL, and Supabase makes it easy to use. These exercises test your understanding of vector types, distance operators, ANN indexes, and security for vector workloads.
0 / 5 completed
1 / 5
At standup, a colleague asks what the pgvector extension adds to PostgreSQL. What is the correct answer?
pgvector extends PostgreSQL with a vector(N) data type and three distance operators: <-> (L2/Euclidean), <#> (negative inner product), and <=> (cosine distance). You can store embedding vectors as columns and run approximate or exact nearest-neighbour queries using SQL. Supabase enables pgvector via create extension vector and uses it as the backbone of its vector search features.
2 / 5
During a PR review, a teammate asks what embedding dimensions matter for a pgvector column. What is the correct explanation?
The N in vector(N) must exactly match the number of dimensions in your embedding model's output. For example, OpenAI's text-embedding-3-small produces 1536-dimensional vectors, so you declare vector(1536). Inserting a vector of a different dimension raises an error, and you cannot use distance operators to compare vectors of mismatched dimensions. pgvector does not automatically resize vectors.
3 / 5
In a design review, the team discusses adding an ivfflat index to a pgvector column. What does this index do?
The IVFFlat index in pgvector is an approximate nearest-neighbour (ANN) index. It partitions all vectors into lists clusters at build time using k-means. At query time, it scans only the probes nearest clusters (configurable via SET ivfflat.probes), trading recall for speed. More probes means higher recall but slower queries. The index is effective once you have enough vectors (Supabase recommends ≥ lists × 10 rows before building).
4 / 5
An incident report shows that RLS (Row Level Security) is blocking vector similarity searches. A senior engineer asks how to correctly apply RLS to a table with vector columns. What is correct?
RLS works normally on tables with vector columns in pgvector. You create CREATE POLICY statements on the table as usual, and Postgres applies them before or alongside the similarity ordering. The nearest-neighbour search (ORDER BY embedding <=> query_vector LIMIT k) only considers rows that pass the RLS policy, so users only see results from rows they are permitted to access. No special handling is required for the vector column.
5 / 5
During a code review, a senior engineer asks what the cosine similarity operator (<=>) in pgvector returns and when to prefer it over L2 distance (<->). What is accurate?
The <=> operator computes cosine distance (= 1 − cosine_similarity), where 0 means identical direction and 2 means opposite. It is preferred for text embeddings because it measures directional similarity independent of vector magnitude — useful when embeddings for short and long texts have different norms. L2 distance (<->) is sensitive to magnitude and works better for embeddings from models that explicitly encode magnitude as meaningful.