Intermediate
A vector store sizing calculator
Write vector_bytes(n, dims, bytes_per_number=4) that returns the bytes needed by n vectors, using n * (bytes_per_number * dims + 8) (pgvector's 4 * dimensions + 8 for 4-byte numbers).
Write fits(n, dims, ram_mb, copies=1, index_bytes_per_vector=128) that adds n * index_bytes_per_vector for the index, multiplies by copies, and returns True when the total is at most half of ram_mb megabytes (1 MB = 1,000,000 bytes).
What Check tests
- 1,000 vectors of 384 numbers
- 2-byte numbers halve the number part
- One million 384-number vectors fit in 16000 MB
- Copies multiply the total
- The limit is half the memory
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.