Field notes from working through example 06 of Ardan Labs’ Ultimate AI course by Bill Kennedy and Florin Pățan (Apache 2.0). My fork: PratikDhanave/ai-training. Thank you Bill and Florin for teaching this material — the patterns in this post are derived from the course; the production reflections at the end are mine.
What the example teaches
pgvector is a Postgres extension that stores vectors and supports nearest-neighbour search. The example walks through:
- Schema:
embedding VECTOR(1024)column. - Index: IVFFlat or HNSW for approximate nearest neighbour.
- Query:
ORDER BY embedding <=> $1 LIMIT 5.
What it looks like
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE chunks (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
embedding VECTOR(1024) NOT NULL
);
CREATE INDEX chunks_embedding_idx
ON chunks USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
-- Query
SELECT id, content, embedding <=> $1 AS distance
FROM chunks
ORDER BY embedding <=> $1
LIMIT 5;
What I learned
HNSW > IVFFlat in 2026. HNSW indexes are bigger and slower to build but query 5-10× faster with better recall. Unless you have memory constraints, default to HNSW.
Cosine distance vs L2 matters. Embeddings from most LLM APIs are normalised; cosine and L2 give the same ranking. For un-normalised vectors (some local models), cosine is the safer default.
Production connection
Postgres + pgvector is Genie’s vector store. AlloyDB AI (which Bancnet used for the 37% latency win) is the GCP-managed version of the same shape. The Ardan example is “pgvector explained in 50 lines”; everything else builds on it.
Credit & reference. This post is field notes on example 06 from Ardan Labs’ Ultimate AI by Bill Kennedy + Florin Pățan, licensed Apache 2.0. The original example: cmd/examples/example06-vector-db/. My fork with notes: PratikDhanave/ai-training. Highly recommend the course for anyone building AI applications in Go — the material is rigorous and the Kronk + yzma + llama.cpp pipeline gives you hardware-accelerated local inference end-to-end. Thank you, Bill and Florin.