Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 8.7 — Vector Databases in Brief
LLM Engineering · Example 1 of 1

A toy approximate index: work against recall

500 random unit vectors from the course's tiny generator. Real indexes (HNSW, IVF) are far smarter, but the trade-off is the same.

A vector database stores embeddings and finds the nearest ones quickly. Exact search compares the query with every vector, which is fine for thousands of chunks; approximate indexes trade a little accuracy for speed at millions. Often a list in memory is enough.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

A collection has 200,000 chunks and the embedding model returns 768 numbers (4 bytes each). How many megabytes of raw vector data is that (1 MB = 1,000,000 bytes)? Print it with one decimal.

02

Write recall(true_ids, found_ids) returning the share of true_ids that appear in found_ids. Print it as a percentage with one decimal for [1, 2, 3] versus [2, 3, 9].

Explain it without notes

01

Why not compare the query with every vector, and when is that fine?

02

What is recall in vector search and how do you measure it?

03

Give three reasons to prefer a vector extension in your existing database over a separate vector database, and one reason against.

A toy approximate index: work against recall
Sign in to run this example in your browser.

Expected output

500 vectors, 9 dimensions, bucket sizes: 58 46 55 65 55 60 44 55 62
exact search: scanned 10000 vectors, found 60 of 60 true neighbours
search 1 bucket(s): scanned 1120 vectors, found 44 of 60 true neighbours
search 2 bucket(s): scanned 2259 vectors, found 59 of 60 true neighbours
search 3 bucket(s): scanned 3379 vectors, found 60 of 60 true neighbours