StudyToCert

All certifications / AI-200 / Lessons

Microsoft Certified: Azure AI Cloud Developer Associate AI-200 (replaced AZ-204) · Domain 2: Develop AI solutions by using Azure data management services

Pgvector: vector(n) columns, distance operators (<-> L2, <=> cosine, <#> inner product), HNSW vs IVFFlat indexes and tuning (m, ef_search, lists, probes)

▶ Watch the overview video

Last reviewed October 6, 2026 · Leer en español

Explain it simpler

Once pgvector is turned on, you add a column that holds a list of numbers of a fixed length, like a column for phone numbers that must all have ten digits. To find similar items, you sort by distance using a small symbol: one symbol measures straight-line distance, one measures the angle between lists (cosine), and one uses a multiplication score (inner product). Comparing against every row is exact but slow for big tables, so you add an index, a shortcut that checks only promising rows. There are two kinds: HNSW, like a network of signposts, and IVFFlat, like sorting books into bins first. The index only helps if it was built for the same symbol you use in the query.

Grace runs the search team at Maple Leaf Libraries, a fictional public library network that lets patrons search 3 million book summaries by meaning. Yesterday she added an index to the embedding column to speed things up. This morning, the search page still takes four seconds, and when she runs EXPLAIN on the query, PostgreSQL shows a sequential scan, reading every single row. The index exists, it is valid, and the planner is simply ignoring it. Her colleague suggests buying a bigger server. Before anyone spends money, Grace looks closely at two small symbols: the one in the query and the one in the index definition. What does she find?

With the extension created, you store embeddings in a column of type vector(n), where n is the number of dimensions your embedding model returns. Inserting a vector with a different length fails with an error, which protects you from accidentally mixing embeddings from two models in one column. A typical table keeps the chunk text, its metadata and its embedding together, so a single SQL query can filter on metadata and rank by similarity at the same time. That combination is one of the main reasons teams choose PostgreSQL for vector work.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 8 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study AI-200 for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the AI-200 study plan