A Matryoshka model's 768-dimensional output can be cut to 512, 256 or 128 dimensions. Implement the cut, a way to measure what the cut does to retrieval, and the storage arithmetic that motivates it.
truncate_normalize(E, k)
k columns of the (n, d) array, each row divided by its L2 norm (eps = 1e-12 inside the square root).top_k(Q, D, k)
k documents with the highest cosine similarity, highest first, lower index on ties. Return a list of lists.ranking_agreement(Q, D, dims, k)
dim in dims, truncate both Q and D to dim, compute top_k, and measure the mean over queries of the overlap fraction with the full-dimension top_k (size of the intersection divided by k). Return a list of floats rounded to 4 decimals, one per dim.index_bytes(n_docs, dim, bytes_per_value)
n_docs * dim * bytes_per_value as an int.compression_ratio(full_dim, full_bytes, dim, bytes_per_value)
index_bytes at the full setting divided by index_bytes at the reduced one, rounded to 2 decimals.np.argsort(-scores, kind="stable")[:, :k] gives descending order with the lower index first on ties.len(set(a) & set(b)).