Vector database lab: Qdrant and PostgreSQL with pgvector
This lab gives each student two real vector databases holding the same data: Qdrant, built for vector search, and PostgreSQL with the pgvector extension. They look at collections and namespaces, compare an exact search with an approximate one, build HNSW and IVF indexes and measure their recall, quantise vectors, filter, run a hybrid search, upsert and delete, and cut a collection into shards.
The vectors are made-up numbers, not embeddings from a model: 20,000 documents of 48 numbers grouped round 40 topics, made from a fixed seed when the lab starts, so every copy holds the same data. Nothing is downloaded and no AI service is called. Every copy has no route to the internet beyond the platform’s list of allowed hosts and none to any other student.
What students learn
How a vector database stores and searches vectors, and how to choose one. They see that a collection takes one length of vector and refuses another, and search one shop of a canteen inside a shared collection. They compare 20,000 vectors one by one, then measure an HNSW index: recall@10 about 0.85 at its lowest setting, rising to 1.0.
They build pgvector indexes, see one probe of an IVF index miss neighbours that five probes find, and compare int8 and product quantisation. A rare filter returns no rows from pgvector until an iterative scan is turned on, and 10 from Qdrant. A hybrid search finds an error code that a search by meaning misses.
Run it in your browser
The lab starts three services. qdrant is Qdrant 1.20 on port 6333, with the collections shop, docs and notes. pg is PostgreSQL 18 with pgvector 0.8, with the tables items, docs and questions. tools is Python with short scripts in steps/. The terminal beside the lab reaches them with docker exec and curl.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find Vector databases: Qdrant and pgvector.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start. The data takes under a minute to load.
- Open it. On the lab's page, press Open terminal and type docker exec tools python3 steps/recall.py to see the recall of Qdrant's HNSW index at five settings.
What to ask students to hand in
A short report on their own copy: recall@10 of pgvector's HNSW index for four values of hnsw.ef_search and of its IVFFlat index for four values of ivfflat.probes, a filtered search for the college hilltop compared in both stores, and a paragraph choosing a store for a college's 2 million documents. Nothing is marked automatically: the paragraph shows whether it was understood.
A basic lesson on this lab
Vector Database Basics is a small lesson worked in this lab. In it a student looks at both stores, searches one shop, runs an exact search and builds an HNSW index in pgvector and measures its recall.
Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library's Basics folder. It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. The module Vector databases in practice goes further in six lessons.
The code on GitHub
The compose file has no Dockerfile: it runs three stock public images pinned by digest, Qdrant (Apache 2.0), pgvector's PostgreSQL 18 (the PostgreSQL licence) and Python 3.12 on Alpine (the PSF licence), none distributed by us. Qdrant and the Python run as unprivileged accounts. The file writes the data and the scripts from fixed text when it starts, so nothing is downloaded. Indexes a student builds are lost when the lab stops.
Set it as work
Say in the task what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-vector-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to load data of your own.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Try this lab, and what it costs
A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.
Questions people ask
- Are the vectors real embeddings?
- No. They are made-up numbers from a fixed seed, grouped round 40 centres the way embeddings of 40 topics would be. The lab is about the store, not the model, so indexes, recall, filters and shards behave as they would with real embeddings, and every copy holds the same data.
- Why do two students see slightly different recall?
- An approximate index is built with chance in it: HNSW chooses each point's layer at random and IVF starts k-means from random rows. Recall can differ by a point or two between copies. Exact answers are the same in every copy.
- Why are the timings so small?
- 20,000 vectors is a small collection, so even an exact search takes milliseconds. The lessons measure recall, which shows the trade-off at any size, and quote no time.
- Does it cost anything or use credits for AI?
- No AI is used, so nothing is charged for it. The lab runs like any other container lab.
- Can students try Pinecone, Weaviate or Milvus here?
- No. The lab has no way out to the internet and runs only Qdrant and PostgreSQL. The module compares the other stores in words.