Paravec is a research reference implementation for analyzing embedding spectra, allocating scalar-quantizer bits by variance, and pruning exact flat searches with PCA-prefix lower bounds.
Search and evaluation currently use squared Euclidean (L2) distance. Normalize rows before indexing if your intended metric is cosine similarity; inner-product search is not implemented.
python -m pip install -e .Save a finite two-dimensional matrix as a NumPy .npy file, then run:
paravec analyze embeddings.npy --budgets 16 32 64 --output spectrum.jsonThe report includes eigenvalue decay, effective dimensions at 90% and 99% variance, participation ratio, per-mode bit allocations, predicted distortion, and estimated basis overhead.
paravec validate embeddings.npy --queries 32 --k 10 --bit-budget 32 --output validation.jsonValidation uses a deterministic holdout split and checks PCA distance isometry, exact staged-search results against brute force, and deterministic quantization-bound coverage for every held-out query/database pair. The report also includes quantized top-k recall and coefficient-read fraction as dataset-specific diagnostics. Bound coverage uses the measured source-to-reconstruction error, so it checks the deterministic bound implementation; it is not probabilistic coverage evidence or a cross-dataset benchmark.
from paravec import SpectralIndex
index = SpectralIndex(database_vectors)
result = index.search(query_vector, k=10, stages=[16, 64, database_vectors.shape[1]])
print(result.indices, result.squared_distances)SpectralIndex keeps exact spectral coefficients and returns exact top-k results using lossless PCA-prefix pruning. PackedSpectralIndex applies the scalar quantizer to the stored coefficients; its per-vector distance intervals use measured coefficient reconstruction error.
PackedSpectralIndex stores variance-allocated codes in a mode-major variable-bit stream and keeps a per-vector quantization-error norm. It supports approximate lookup with distance intervals, or exact reranking when original vectors are retained:
from paravec import PackedSpectralIndex
index = PackedSpectralIndex(database_vectors, bit_budget_bits_per_vector=64)
index.save("index.npz")
restored_index = PackedSpectralIndex.load("index.npz")
result = restored_index.search(query_vector, k=10)Packed queries decode at most block_size vectors at a time; the default adapts to dimension and limits each decoded block to four million coefficient elements. For exact reranking, build with store_original=True and call search(..., exact_rerank=True); retaining originals removes most of the storage savings. The analyzer includes packed code, error-bound, allocation, and basis costs in estimated bytes and float32/float64 ratios. These numeric estimates exclude Python object and archive overhead and are not measured recall or throughput.
On a supplied embedding matrix, compare approximate packed recall and exact-rerank recall against brute-force float64 neighbors:
paravec evaluate embeddings.npy --budgets 32 64 128 --queries 32 --k 10 --repeats 3 --output evaluation.jsonThe report compares variance-allocated spectral quantization with uniform original-space scalar quantization at the same nominal code-bit budget. The scalar ranges are fit on each training database split. Results include packed-only and original-backed storage estimates, mean recall@k and standard deviation across seeds, and rerank shortlist fraction for each budget. Repeats use deterministic seeds beginning at 42 by default. Metadata overhead means actual bytes differ even though code bytes are equal; compare against PQ/OPQ at equal total bytes before drawing compression-quality conclusions. No throughput benchmark is performed.
This is not yet a production vector database or a demonstrated retrieval win. IVF/local bases, updates, optimized kernels, equal-total-byte PQ/OPQ baselines, and multi-dataset recall-vs-bytes studies remain unimplemented. Predicted distortion is a model estimate, not measured recall. See docs/spec for the original design and evaluation gates.
Run the test suite with:
python -m unittest discover -s tests -v