Command Palette

Search for a command to run...

Hectal
Phase 2: Embeddings in Depth
RAG and Vector Search · Exercise 3 of 5 PreviousNext
Beginner

Plan the storage for a vector index

Write bytes_needed(n_vectors, dims, kind) for kind equal to "float32" (4 bytes per number), "int8" (1 byte per number) or "binary" (1 bit per number, so dims // 8 bytes). It returns a whole number of bytes. For any other kind raise ValueError.

Write fits(n_vectors, dims, kind, budget_gb, overhead=1.0): True when the bytes needed, multiplied by overhead (the index adds memory on top of the raw vectors), are at most budget_gb * 1e9.

What Check tests

  1. float32 uses 4 bytes per number
  2. int8 uses 1 byte per number
  3. binary uses 1 bit per number
  4. An unknown kind raises ValueError
  5. fits accounts for the index overhead

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.