NumPy allowed · plain Python earns 10 bonus points
Cosine-like similarity scores ranked before context assembly
Implement scalar quantization, the memory-compression technique real vector databases (Qdrant, Milvus, FAISS's ScalarQuantizer) use to shrink float32 embeddings down to 8-bit (or fewer) integer codes so billions of vectors fit in RAM.
Implement scalar_quantize(vector, num_bits): map each float in vector linearly from [min(vector), max(vector)] onto integer codes in [0, 2**num_bits - 1], rounding to the nearest code.
scalar_quantize(vector: list[float], num_bits: int) -> list[int]