All engineering notes
001 — Algorithms

Designing ArrowSpace and graph wiring

How graph wiring in the feature-space Laplacian powers spectral indexing for vector retrieval, why it closes the semantic gap that cosine leaves open, and what the experimental evidence shows on CVE and TREC-COVID.

Vector retrieval systems overwhelmingly rely on cosine similarity. Given a query and a corpus item, cosine measures their angular proximity in the ambient embedding space. What it does not do is account for the statistical and topological structure of the corpus from which those embeddings are drawn.

This creates a problem we call the semantic gap: items may be geometrically close while belonging to different regions of the feature manifold, whereas geometrically distant items may still share structural affinity through the corpus topology. The gap is most visible in the tail of ranked retrieval results, where weakly grounded or noisy evidence can affect downstream applications like Retrieval-Augmented Generation. A result set with high average cosine similarity may still be topologically scattered.

This post walks through how Graph Wiring (GW) and Spectral Indexing (SPIN) address this gap, presenting the algorithm as published in our paper and the experimental evidence that supports it.

1. The feature-space graph Laplacian

Classical spectral graph theory operates in the item-space: given a weighted undirected graph $G=(V,E,W)$ with adjacency matrix $A \in \mathbb{R}^{N \times N}$ and degree matrix $D$, the combinatorial Laplacian is $L = D - A$. For production systems with millions of vectors, building an $N \times N$ adjacency is impractical.

Graph Wiring takes a different path. We work in the feature-space rather than the item-space:

  1. Reduce the data matrix from $N \times F$ to $C \times F$ via incremental centroid clustering, where $C \ll N$ and the optimal $C$ is computed via the Johnson–Lindenstrauss lemma.
  2. Transpose to obtain an $F \times C$ matrix.
  3. Compute the graph Laplacian $L_F \in \mathbb{R}^{F \times F}$ on this transposed space.

The result is a Laplacian over features, not items. The feature-space is the semantic web of the dataset — it encodes how dimensions correlate across the corpus. An item vector $x_i \in \mathbb{R}^{N \times F}$, when blended with $L_F$, carries measurably more discriminative information than its geometric measurement alone.

Complexity: Index construction is $O(F \cdot \mathrm{nnz}(L_F))$ following an $O(N \cdot F)$ clustering step. Memory is $O(F \cdot N)$ for dense features, $O(F \cdot \mathrm{nnz}(L_F))$ for the Laplacian, and $O(N)$ for the scalar $\lambda_\tau$ index. The spectral operations run on sparse feature-space, not dense item-space.

2. The Rayleigh quotient as spectral energy

Once $L_F$ is available, we compute the Rayleigh quotient for each vector $x$:

$$R(x) = \frac{x^\top L_F x}{x^\top x}$$

This is the normalized Dirichlet energy — physically, potential energy per unit mass on the feature manifold. The interpretation is direct:

  • High energy (peaks, rough): the item is anomalous, topologically isolated, or out-of-distribution.
  • Low energy (hills, smooth): the item is typical, well-connected, semantically aligned with the corpus.

A semantically typical item produces a smooth signal on $L_F$: adjacent feature nodes receive similar activation values. An anomalous or OOD item produces a rough, high-energy signal. This is structural information that geometric search cannot access.

The graph is not an approximation of the data. For spectral methods, it is the data structure.

3. Bounded spectral scores

The Rayleigh quotient is unbounded, which makes it hard to compare across datasets with different energy scales. We apply a Gini-like dispersion transform to produce a bounded score:

$$\lambda_\tau^x = \frac{R(x)}{R(x) + \epsilon} \in [0, 1)$$

This bounded score — called taumode — is a 1D positional score that synthesizes where each vector sits in the spectral structure. At query time, spectral similarity becomes:

$$\mathrm{sim}_\lambda = \lambda_\tau^q - \lambda_\tau^i$$

The $\lambda_\tau$ score is bounded to $[0, 1)$ regardless of corpus energy scale, making it stable across heterogeneous datasets — something cosine ($[-1, 1]$) and $\ell_2$ ($[0, \infty)$) do not provide.

4. SPIN: lambda-aware similarity search

SPIN (SPectral INdexing) combines geometric and spectral similarity through a linear combination controlled by a parameter $\alpha$, which we call tau ($\tau$):

$$\mathrm{dist}_{SPIN} = \alpha \cdot \mathrm{sim}_{\cos}(q, i) + (1 - \alpha) \cdot \mathrm{sim}_\lambda(q, i)$$

The first term is the geometric component (cosine). The second term is the spectral component, which acts as a differentiator of the geometric signal. If cosine picks a false neighbor from a different topological community, the spectral distance corrects the measurement.

The tau parameter controls the balance:

  • $\tau = 1.0$: pure cosine retrieval (no spectral signal)
  • $\tau = 0.42$: 58% spectral signal (optimal for the CVE dataset)
  • $\tau \to 0$: fully spectral retrieval

Cosine is the high-locality signal; $\mathrm{sim}_\lambda$ is the corpus-structure signal. They are complementary, not competing.

5. Tau-modulation for adaptive retrieval

The tau parameter is not a hyperparameter you tune once and freeze. It is a runtime control that enables adaptive search — adjusting retrieval behavior based on the phase of context formation in a RAG pipeline:

  • Early phase (broad frame): $\tau \approx 1.0$ — rely more on geometric signal to establish context.
  • Later phase (specific evidence): $\tau \approx 0.4$ — embed more spectral signal for finer corpus sieving.

We call this process tau-modulation. A simple feedback loop on $\tau$ can avoid deadlocks caused by poor retrieval in long-context applications. This is where spectral intelligence becomes operational rather than theoretical.

6. Experimental evidence

We evaluated SPIN on two retrieval benchmarks. The first is the CVE™ vulnerability corpus: 347,113 reports with 50 LLM-generated queries emulating realistic cybersecurity search scenarios. The second is TREC-COVID: approximately 171,000 scientific articles with 50 expert-designed topics and graded human relevance judgments.

Documents and queries are encoded using a domain-adapted Sentence-BERT model with lightweight fine-tuning on 3–5% of the target corpus. We compare three configurations: cosine ($\tau=1.0$), hybrid ($\tau=0.72$), and taumode ($\tau=0.42$).

CVE: flatter tails, near-perfect recall

On CVE, taumode produces flatter and more stable score tails while preserving near-perfect Tolerant Recall. The tail metrics are the key finding: cosine retrieval degrades rapidly in the tail, while SPIN maintains semantic coherence deeper into the ranking.

Table 1: Mean tail-shape metrics at $K_h = 3$ (CVE)

Method Head mean Tail mean T/H Ratio Tail CV Tail Decay
Cosine ($\tau=1.0$) 0.843 0.831 0.986 0.00396 0.000512
Hybrid ($\tau=0.72$) 0.875 0.863 0.986 0.00382 0.000509
Taumode ($\tau=0.42$) 0.924 0.915 0.991 0.00254 0.000359

Compared to cosine, taumode achieves 29.9% lower Tail CV and 29.8% lower Tail Decay, with Tolerant Recall of 0.993 and an average Semantic Uplift of +0.573 (cosine provides zero uplift by construction).

TREC-COVID: gains on human-labeled relevance

On TREC-COVID, intermediate tau values improve both Relevance Recall and NDCG over cosine. The gains are strongest in hybrid settings ($\tau \approx 0.65$–$0.80$), not in purely spectral regimes — confirming that geometric and spectral signals are complementary.

Table 2: Retrieval quality on TREC-COVID at $k=10$

Method Relevance Recall@10 NDCG@10 Semantic Uplift
Cosine ($\tau=1.0$) 0.508 0.455 0.000
Hybrid ($\tau=0.70$) 0.522 0.467 0.184
Taumode ($\tau=0.40$) 0.510 0.459 0.334

The hybrid setting achieves approximately 2.8% gain in Relevance Recall and 2.6% gain in NDCG over cosine. Taumode pushes Semantic Uplift from 0.000 (cosine) to 0.334, indicating that feature-space topology helps retrieve more semantically coherent neighborhoods beyond pure geometric similarity.

7. What this means in practice

The evidence supports a clear reading: cosine similarity is a strong local baseline but a limited global semantic index. SPIN reorders the ranked list according to the graph's spectral-topological layout, integrating both local geometry and corpus-level connectivity.

Four engineering takeaways:

  1. Graph wiring is the foundation. The feature-space Laplacian is where all the structural signal lives. Getting it right — deterministic clustering, validated symmetry, connected components — is prerequisite to everything downstream.
  2. Tau is a runtime control, not a frozen hyperparameter. Different queries, different phases of retrieval, and different corpora all benefit from different tau values. Build your system to modulate it.
  3. The tail matters more than the head. Cosine already does well on top results. The value of spectral search is in producing coherent, non-degrading tails — which is exactly where RAG context windows pull from.
  4. Complexity is manageable. The spectral operations work on sparse feature-space ($O(F \cdot \mathrm{nnz}(L_F))$), not dense item-space. This scales to production corpora.

The full algorithmic pipeline, theoretical foundation through epiplexity, and experimental details are in the paper. The reference implementation is open source: pip install arrowspace.

Cite as: Lorenzo Moriondo, Ilias Azizi. From Embedding Geometry to Spectral Search: Energy Dispersion Networks For Vector Retrieval. arXiv:2606.21535 [cs.IR], 2026.