Illuminating the geometry of your embedding space
Project description
spectralyte
Illuminating the geometry of your embedding space.
Most RAG failures are not model failures — they are geometry failures. If your embedding space is anisotropic, over-clustered, or low-dimensional, no amount of prompt engineering or model upgrades will fix the underlying retrieval problem.
Spectralyte makes the invisible geometry visible.
from spectralyte import Spectralyte
audit = Spectralyte(embeddings) # numpy array of shape (n, d)
report = audit.run()
report.summary()
Spectralyte Audit Report
════════════════════════════════════════
Anisotropy Score 0.61 ⚠ HIGH
Effective Dimensions 43 / 1536
Density CV 0.84 ⚠ CLUSTERED
Retrieval Stability 0.58 ⚠ BRITTLE
Intrinsic Dimension 31
════════════════════════════════════════
2 critical issues detected.
Run report.plot() for full visualization.
Run audit.transform('whiten') to fix anisotropy.
Why Spectralyte
When a RAG pipeline returns wrong results, engineers have three debugging tools: inspect individual queries, run ad-hoc similarity searches, or stare at raw vectors. None of them answer the foundational question: is my embedding space geometrically healthy?
Spectralyte answers that question with five geometric metrics derived from linear algebra and manifold theory — all computed locally, with no API calls and no cost beyond the compute already used to generate your embeddings.
| Metric | What It Catches |
|---|---|
| Anisotropy | Vectors clustered in one direction — cosine similarity loses discriminative power |
| Effective Dimensionality | Space is lower-dimensional than expected — distinct content collapses together |
| Density Distribution | Tight clusters with voids — small query changes flip entire result sets |
| Retrieval Sensitivity | Unstable regions — rephrasing a query returns completely different documents |
| Intrinsic Dimensionality | True manifold complexity — guides dimensionality reduction decisions |
Installation
pip install spectralyte
Requires Python 3.9+. Core dependencies: numpy, scipy, scikit-learn, matplotlib.
For large indices (>50k embeddings), install the optional FAISS backend:
pip install spectralyte[faiss]
Quick Start
import numpy as np
from spectralyte import Spectralyte
# Works with any embedding source — OpenAI, sentence-transformers, Cohere, etc.
# Just pass a numpy array of shape (n, d)
embeddings = np.load("my_embeddings.npy")
# Run the full geometric audit
audit = Spectralyte(embeddings)
report = audit.run()
# Human-readable summary
report.summary()
# Visualize all five metrics
report.plot()
# Export structured results
report.export("audit.json")
Fixing Detected Issues
For the two most common problems, Spectralyte can fix them directly — no re-embedding required.
# Fix anisotropy via whitening transform
fixed = audit.transform(embeddings, strategy="whiten")
# Fix anisotropy via All-but-the-Top (ABTT)
fixed = audit.transform(embeddings, strategy="abtt", k=3)
# Re-index with fixed embeddings
# your_vector_db.upsert(fixed)
Individual Metrics
Each metric is independently importable if you only need one.
from spectralyte.metrics import anisotropy, effective_dimensionality
from spectralyte.metrics import density, sensitivity, intrinsic_dim
# Anisotropy score (0 = isotropic, 1 = fully anisotropic)
result = anisotropy.compute(embeddings)
print(result.score)
# Effective dimensionality via SVD
result = effective_dimensionality.compute(embeddings, variance_threshold=0.95)
print(result.effective_dims, "/", result.nominal_dims)
# Retrieval Sensitivity Index
result = sensitivity.compute(embeddings, k=10, epsilon=0.05, m=5)
print(result.mean_stability)
Use Cases
Pre-deployment audit — catch geometry problems before your RAG pipeline reaches production.
Embedding model comparison — evaluate models on your specific corpus, not just generic benchmarks.
Chunking strategy validation — compare geometric health across different chunking approaches.
Index drift monitoring — detect when new documents degrade the geometric structure of your index.
Debugging retrieval failures — localize whether failures are geometric (brittle zones) or content-based (missing documents).
Configuration
audit = Spectralyte(
embeddings,
k=10, # nearest neighbors for density and sensitivity
sensitivity_epsilon=0.05, # perturbation scale as fraction of mean k-NN distance
sensitivity_m=5, # perturbations per embedding for RSI
variance_threshold=0.95, # cumulative variance for effective dimensionality
sample_size=None, # subsample for large indices (auto-set for n > 50k)
random_seed=42 # reproducibility
)
The Math
Spectralyte implements five geometric metrics with rigorous mathematical foundations:
- Anisotropy — Gram matrix formulation: measures average pairwise cosine similarity across all embedding pairs
- Effective Dimensionality — SVD-based: minimum principal components explaining 95% of variance
- Density Distribution — k-NN distance coefficient of variation + Local Outlier Factor
- Retrieval Sensitivity Index — Jaccard stability of top-k results under Gaussian perturbation
- Intrinsic Dimensionality — TwoNN estimator (Facco et al. 2017): fits d_int from nearest-neighbor distance ratios
Full mathematical derivations are available in the documentation.
Roadmap
- Anisotropy metric
- Effective dimensionality
- Density distribution
- Retrieval Sensitivity Index
- Intrinsic dimensionality (TwoNN)
- Whitening transform
- All-but-the-Top (ABTT) transform
- CLI entrypoint (
spectralyte audit embeddings.npy) - HTML report export
- FAISS backend for large indices
- Pinecone / Qdrant / Weaviate native integration
- Continuous drift monitoring
Contributing
Contributions are welcome. Please open an issue before submitting a PR so we can discuss the change.
git clone https://github.com/UniqueRed/spectralyte
cd spectralyte
pip install -e ".[dev]"
pytest
Citation
If you use Spectralyte in research, please cite:
@software{spectralyte2026,
author = {Thoppe, Adhviklal},
title = {Spectralyte: Illuminating the Geometry of Your Embedding Space},
year = {2026},
url = {https://github.com/UniqueRed/spectralyte}
}
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spectralyte-0.2.0.tar.gz.
File metadata
- Download URL: spectralyte-0.2.0.tar.gz
- Upload date:
- Size: 630.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0011da41c29ff6b6987253a5eb6ea66ddf21fe6881b6a0b88dfc5eb74fe8ff3
|
|
| MD5 |
502dc33c804c3f913256f5737b5a366b
|
|
| BLAKE2b-256 |
cde81bf5c7806eff55e3ddf28660130e763d38c08b3527b4e06d3ea5da1f02ff
|
File details
Details for the file spectralyte-0.2.0-py3-none-any.whl.
File metadata
- Download URL: spectralyte-0.2.0-py3-none-any.whl
- Upload date:
- Size: 54.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50f3a88b25c96158000120a2534a4f9ca3f6cb3208b4a7cdae6ae42073e404d
|
|
| MD5 |
9bd6f0b7bec016b8a56609c079747943
|
|
| BLAKE2b-256 |
893de1862e1faf0e1c43281ca8b8ebf882392db38a61f85e33e5e71d3d56c09d
|