query, key, merge_weight, compress_ratio=compress_ratio,
sparse_count=sparse_count, topk_blocks=topk_blocks,
block_size=block_size, query_offset=query_offset,
reduce_sum=reduce_sum, minimum_key_indices=minimum_key_indices)
if selected is not None:
return selected
batch_size, sequence_length, _, head_dim = query.shape
if key.ndim != 3 or key.shape[0] != batch_size or key.shape[2] != head_dim:
raise ValueError(
"compressed index key must have shape [batch, compressed_sequence, head_dim]"