File size: 1,630 Bytes
b835e94 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | ---
license: apache-2.0
tags:
- embeddings
- vector-search
- quantization
---
# Embedding rotations
Fixed orthogonal matrices for embedding vectors. Each file is a constant: an embedding space whose
name ends in `-rot1` means exactly the bytes of `rot1/<dim>.npy`, forever. A different matrix gets a
new transform name (`rot2`), never a new revision of this file.
| Transform | Dim | File | sha256 |
| --- | --- | --- | --- |
| `rot1` | 768 | `rot1/768.npy` | `947552c113aff0959091773bb89536d75e8a8746112e7cd1fe8f0db0a07ad4c5` |
Pin a revision when you fetch it, and check the sha256.
An orthogonal matrix preserves every dot product and norm, so exact cosine search is unchanged,
while it spreads energy that is concentrated in a few dimensions over all of them. That can help
scalar quantization of such embeddings.
## Recipe (`rot1`)
```python
rng = numpy.random.default_rng(20261001)
g = rng.standard_normal((768, 768)) # float64
q, r = numpy.linalg.qr(g)
q *= numpy.sign(numpy.diag(r)) # Haar-distributed (Mezzadri 2007)
R = q.astype("<f4")
```
Generated once on 2026-10-01 with numpy 2.5.3. Do not regenerate it to "verify" it: QR output is
not bit-stable across numpy and BLAS versions. Load the file and check the sha256 instead.
## Applying it
- One vector: `v_rot = R @ v`. A batch of row vectors: `V_rot = V @ R.T`.
- Never truncate a rotated vector (no Matryoshka cut): the rotation mixes all dimensions, so the
first k dimensions of a rotated vector are not a smaller embedding.
- Normalization commutes with the rotation, so it can happen before or after.
## License
Apache-2.0.
|