Skip to content

Mathematical Foundations: Spectral Geometry & Bounds

This document provides the formal mathematical framework underlying the Pithos Vector Search Engine, including isometric distance preservation, energy flattening, multi-index hashing collision bounds, and asymmetric distance computation.


1. Ingestion Pipeline & Isometric Embedding

Given a high-dimensional continuous embedding vector \(\mathbf{x} \in \mathbb{R}^d\) (with \(\|\mathbf{x}\|_2 = 1\)), Pithos applies an isometric orthogonal transformation prior to sign binarization:

  1. Rademacher Preconditioning (\(\mathbf{D}\)): Multiplication by a diagonal sign matrix \(\mathbf{D} \in \mathbb{R}^{d \times d}\) whose diagonal elements are independent and identically distributed (i.i.d.) Rademacher random variables:

    \[ D_{ii} \sim \text{Uniform}(\{-1, +1\}), \quad D_{ij} = 0 \text{ for } i \ne j \]
  2. Normalized Fast Walsh-Hadamard Transform (\(\mathbf{H}\)): Multiplication by an orthonormal Sylvester-Hadamard matrix \(\mathbf{H} = \frac{1}{\sqrt{d}} \mathbf{H}_d\), defined recursively as:

    \[ \mathbf{H}_2 = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, \quad \mathbf{H}_{2^k} = \mathbf{H}_2 \otimes \mathbf{H}_{2^{k-1}} \]

The resulting rotated vector \(\mathbf{z} \in \mathbb{R}^d\) is:

\[ \mathbf{z} = \mathbf{H} \mathbf{D} \mathbf{x} \]

Because both \(\mathbf{D}\) and \(\mathbf{H}\) are strictly orthonormal (\(\mathbf{D}^T \mathbf{D} = \mathbf{I}\), \(\mathbf{H}^T \mathbf{H} = \mathbf{I}\)), the transformation is an exact isometry:

\[ \|\mathbf{z}\|_2 = \|\mathbf{H} \mathbf{D} \mathbf{x}\|_2 = \|\mathbf{x}\|_2 = 1 \]

1.2 Arbitrary & Non-Power-of-Two Dimensions: Kronecker Orthogonal Rotation

While standard Walsh-Hadamard transforms require block dimensions to be exact powers of two (\(d = 2^k\)), modern representation models utilize arbitrary dimensionalities (e.g., \(d = 384, 768, 960, 1536\)).

Rather than zero-padding (which distorts angular distributions and wastes memory bandwidth), Pithos applies Kronecker-Factorized Orthogonal Rotation:

Theorem (Kronecker Isometry for Composite Dimensions)

Let the block width \(w\) be factorized into \(w = u \cdot v\), where \(u\) is the largest power-of-two divisor of \(w\) and \(v\) is the residual odd component. The composite rotation matrix \(\mathbf{R} \in \mathbb{R}^{w \times w}\) is constructed as the Kronecker product:

\[ \mathbf{R} = \mathbf{H}_u \otimes \mathbf{\Omega}_v \]

where \(\mathbf{H}_u \in \mathbb{R}^{u \times u}\) is the normalized \(u\)-dimensional Walsh-Hadamard matrix, and \(\mathbf{\Omega}_v \in \mathbb{R}^{v \times v}\) is an orthonormal Discrete Cosine Transform (DCT-II) basis matrix:

\[ \Omega_{0, j} = \frac{1}{\sqrt{v}}, \quad \Omega_{i, j} = \sqrt{\frac{2}{v}} \cos\left( \frac{\pi i (2j + 1)}{2v} \right) \quad \text{for } i \ge 1, \; 0 \le j < v \]

Proof of Exact Orthonormality & Norm Preservation

By the mixed-product property of the Kronecker product:

\[ \mathbf{R}^T \mathbf{R} = (\mathbf{H}_u \otimes \mathbf{\Omega}_v)^T (\mathbf{H}_u \otimes \mathbf{\Omega}_v) = (\mathbf{H}_u^T \mathbf{H}_u) \otimes (\mathbf{\Omega}_v^T \mathbf{\Omega}_v) = \mathbf{I}_u \otimes \mathbf{I}_v = \mathbf{I}_w \]

Consequently, for any input vector \(\mathbf{x} \in \mathbb{R}^w\):

\[ \|\mathbf{R} \mathbf{x}\|_2 = \sqrt{\mathbf{x}^T \mathbf{R}^T \mathbf{R} \mathbf{x}} = \sqrt{\mathbf{x}^T \mathbf{I}_w \mathbf{x}} = \|\mathbf{x}\|_2 \]

and for any two vectors \(\mathbf{x}, \mathbf{y} \in \mathbb{R}^w\), the inner product is strictly invariant: \(\langle \mathbf{R}\mathbf{x}, \mathbf{R}\mathbf{y} \rangle = \langle \mathbf{x}, \mathbf{y} \rangle\).

Algorithmic Evaluation in \(O(w \cdot (\log u + v))\) Time

Pithos evaluates \(\mathbf{R} \mathbf{x}\) without explicitly materializing the \(w \times w\) matrix: 1. Reshape the \(w\)-dimensional slice into a \(u \times v\) row-major matrix \(\mathbf{X}\). 2. Apply the \(v \times v\) DCT-II transform \(\mathbf{\Omega}_v\) to each of the \(u\) rows: \(\mathbf{Y} = \mathbf{X} \mathbf{\Omega}_v^T\). 3. Apply the Fast Walsh-Hadamard butterfly network \(\mathbf{H}_u\) down each of the \(v\) column vectors of length \(u\): \(\mathbf{Z} = \mathbf{H}_u \mathbf{Y}\). 4. Flatten \(\mathbf{Z}\) back into the continuous transformed coordinate array.


1.3 Quantization & Bitpacking Alignment for Non-Multiple-of-64 Dimensions

For datasets where the total dimension \(d\) is not a multiple of 64: - 1-Bit / 2-Bit Sign Packing: Packed into \(\lceil d / 64 \rceil\) 64-bit integer words (uint64_t). Trailing bits in the final word beyond \(d\) are strictly zero-masked, ensuring zero corruption during SIMD popcount operations (_mm512_popcnt_epi64 / vaddlvq_u8). - Gate 3 NVFP4 Microscaling: Sliced into \(\lceil d / 16 \rceil\) blocks of 16 dimensions each. Unused trailing dimensions within the terminal block are padded with \(0.0\) prior to scale extraction, and distance reranking accumulates only the valid active dimensions \([0, d)\). - Gate 3 FP8 / FP16 Sidecars: Serialized with exact element counts (\(d \times 1\) Byte / \(d \times 2\) Bytes per record) with 64-byte row-offset cache-line alignment.


2. Energy Distribution & Peak-to-Average Flattening

Raw neural network embeddings often exhibit high directional kurtosis and coordinate spikes (anisotropic cone distributions). Direct sign quantization \(\text{sign}(\mathbf{x})\) on raw vectors causes severe information loss.

Theorem 1 (Sub-Gaussian Coordinate Energy Bounds)

For any unit vector \(\mathbf{x} \in \mathbb{R}^d\) (\(\|\mathbf{x}\|_2 = 1\)) and Rademacher matrix \(\mathbf{D}\), the coordinates of \(\mathbf{z} = \mathbf{H} \mathbf{D} \mathbf{x}\) are sub-Gaussian random variables. The maximum absolute coordinate is bounded by:

\[ \mathbb{P}\left( \|\mathbf{z}\|_{\infty} \ge t \right) \le 2 d \exp\left( -\frac{d \cdot t^2}{2} \right) \]

Setting the failure probability to \(\delta \in (0, 1)\) yields the bound:

\[ \|\mathbf{z}\|_{\infty} \le \sqrt{\frac{2 \ln(2d / \delta)}{d}} \]

with probability at least \(1 - \delta\).

Implication: The Walsh-Hadamard transform spreads spectral energy uniformly across all \(d\) dimensions with high probability, eliminating coordinate spikes and enabling unbiased sign binarization.


3. Angular Distance Preservation & Charikar Theorem

After projection, Pithos applies 1-bit sign quantization:

\[ \mathbf{b} = \text{sign}(\mathbf{z}) = \text{sign}(\mathbf{H} \mathbf{D} \mathbf{x}) \in \{-1, +1\}^d \]

Let \(\mathbf{x}, \mathbf{y} \in \mathbb{R}^d\) be two unit vectors, and let \(\theta = \arccos(\langle \mathbf{x}, \mathbf{y} \rangle) \in [0, \pi]\) denote the geodesic angular distance between them.

Theorem 2 (Grothendieck / Charikar Relation)

The pair \((\mathbf{H}, \mathbf{D})\) acts as a Fast Johnson-Lindenstrauss Transform (FJLT). The probability that corresponding quantized bits match across dimension \(i\) is:

\[ \mathbb{P}\left( \text{sign}((\mathbf{H}\mathbf{D}\mathbf{x})_i) = \text{sign}((\mathbf{H}\mathbf{D}\mathbf{y})_i) \right) = 1 - \frac{\theta}{\pi} \]

The normalized Hamming distance \(d_H(\mathbf{b}_{\mathbf{x}}, \mathbf{b}_{\mathbf{y}}) = \frac{1}{d} \sum_{i=1}^d \mathbb{I}(b_{\mathbf{x},i} \ne b_{\mathbf{y},i})\) has expected value:

\[ \mathbb{E}\left[ d_H(\mathbf{b}_{\mathbf{x}}, \mathbf{b}_{\mathbf{y}}) \right] = \frac{\theta}{\pi} = \frac{\arccos(\langle \mathbf{x}, \mathbf{y} \rangle)}{\pi} \]

Concentration of Measure Bound

Applying Hoeffding's inequality over \(d\) independent coordinate projections:

\[ \mathbb{P}\left( \left| d_H(\mathbf{b}_{\mathbf{x}}, \mathbf{b}_{\mathbf{y}}) - \frac{\theta}{\pi} \right| \ge \epsilon \right) \le 2 \exp(-2 d \epsilon^2) \]

For a database of \(N\) vectors, achieving a pairwise distortion bound of \(\epsilon\) with failure probability \(\gamma\) requires:

\[ d \ge \frac{1}{2 \epsilon^2} \ln\left( \frac{2 N^2}{\gamma} \right) = O\left( \frac{\log N}{\epsilon^2} \right) \]

4. Gate 0: Multi-Index Hashing (MIH) Collision Bounds

Pithos implements 4x8-Bit Multi-Index Hashing (MIH) to prune candidate search space in \(O(1)\) time.

The 64-bit Tier-0 binary descriptor \(\mathbf{b} \in \{0, 1\}^{64}\) is partitioned into \(m = 4\) orthogonal 8-bit sub-words:

\[ \mathbf{b} = [\mathbf{u}^{(1)} \,\|\, \mathbf{u}^{(2)} \,\|\, \mathbf{u}^{(3)} \,\|\, \mathbf{u}^{(4)}], \quad \mathbf{u}^{(j)} \in \{0, 1\}^8 \]

Theorem 3 (Pigeonhole Principle for Hamming Distance)

If two binary descriptors \(\mathbf{b}_q\) and \(\mathbf{b}_t\) have total Hamming distance \(d_H(\mathbf{b}_q, \mathbf{b}_t) \le r\), then across \(m\) disjoint sub-vectors:

\[ \min_{j \in \{1, \dots, m\}} d_H\left(\mathbf{u}_q^{(j)}, \mathbf{u}_t^{(j)}\right) \le \left\lfloor \frac{r}{m} \right\rfloor \]

For \(m = 4\) and a Hamming radius threshold \(r = 3\):

\[ \left\lfloor \frac{3}{4} \right\rfloor = 0 \]

Guarantee: Any target vector within Hamming distance \(r \le 3\) is guaranteed to collide exactly with the query vector in at least one 8-bit sub-table (\(2^8 = 256\) buckets). Probing 256 buckets across 4 sub-tables prunes \(98.5\%\) to \(99.2\%\) of candidates in sub-microsecond time.


5. Gate 3: Asymmetric Distance Computation & Early Distance Cutoff

For top-ranked candidates, Gate 3 evaluates exact Euclidean distance using precomputed continuous Look-Up Tables (LUTs) with zero runtime floating-point multiplications.

Asymmetric Query LUT Formulation

Let \(\mathbf{q} \in \mathbb{R}^d\) be the continuous query vector. For an 8-bit quantized database vector \(\mathbf{x}\) represented by indices \(c_j \in \{0, \dots, 255\}\), the squared Euclidean distance is:

\[ \|\mathbf{q} - \mathbf{x}\|_2^2 = \|\mathbf{q}\|_2^2 + \|\mathbf{x}\|_2^2 - 2 \langle \mathbf{q}, \mathbf{x} \rangle \]

For unit-normalized vectors (\(\|\mathbf{q}\|_2 = \|\mathbf{x}\|_2 = 1\)):

\[ \|\mathbf{q} - \mathbf{x}\|_2^2 = 2 - 2 \sum_{j=1}^d q_j \cdot \mathcal{Q}(x_j) \]

Pithos precomputes a table \(\mathbf{T} \in \mathbb{R}^{d \times 256}\) where \(T(j, c) = (q_j - \mathcal{Q}(c))^2\). Distance evaluation for candidate \(\mathbf{x}\) is a sum of table lookups:

\[ \mathcal{D}(\mathbf{q}, \mathbf{x}) = \sum_{j=1}^d T(j, x_j) \]

Monotonic Early Distance Cutoff

Because each term \(T(j, x_j) \ge 0\), the partial distance sum is strictly monotonically non-decreasing:

\[ S_m = \sum_{j=1}^m T(j, x_j) \le S_{m+1} \le \dots \le S_d \]

Let \(\tau_k = \max_{i \in \text{Top-}k} \text{dist}_i\) be the \(k\)-th smallest distance in the current search heap. If at any dimension \(m < d\):

\[ S_m > \tau_k \]

the vector \(\mathbf{x}\) cannot enter the top-\(k\) result set. Evaluation terminates immediately at dimension \(m\).

Theoretical Efficiency: In high-dimensional spaces (\(d = 384\)), non-matching candidates exceed \(\tau_k\) within \(m \in [64, 128]\) dimensions, saving \(60\%\) to \(75\%\) of memory lookups while guaranteeing \(100\%\) exact mathematical recall.