A polynomial autoencoder beats PCA on transformer embeddings
TL;DR Highlight
Adding a quadratic decoder to PCA cuts 4× embedding compression loss to under 1.5 NDCG points.
Who Should Read
A search/RAG backend developer evaluating embedding compression such as PCA to cut vector DB memory costs.
Core Mechanics
- A quadratic decoder on top of PCA
- The encoder stays plain PCA, and only the decoder becomes a degree-2 polynomial fit with Ridge regression (linear regression with L2 regularization).
- It is closed-form via one np.linalg.solve, so there is no SGD, no epochs, and no hyperparameter search.
- It closes most of the PCA gap on FiQA
- With mxbai-embed-large-v1 (1024d) at 512 bytes per vector, NDCG@10 is 0.4533 raw, 0.4175 PCA, and 0.4445 poly-AE.
- That is +2.70 p.p. over vanilla PCA and +1.34 p.p. over the strongest PCA variant (half-whitened).
- At d=256, 4× compression loses under 1.5 p.p.
- Across all four models (nomic, mxbai, bge-base, e5-base), NDCG loss versus raw is 0.7 to 1.4 p.p.
- It beats half-whitened PCA by +0.57 to +2.65 p.p.
- At d=128 (8× compression) results vary by model
- Versus vanilla PCA, it wins on all four models by +1.07 to +4.34 p.p.
- Versus half-whitened PCA, it loses on nomic (-0.59) and e5 (-0.43 p.p.) and wins on mxbai (+1.23) and bge (+2.10 p.p.).
- Small corpora inflate the gain
- Over PCA, the gain was +1.36 p.p. on SciFact (5183 docs) but only +0.03 p.p. on FiQA (57K docs).
- If documents are few relative to the feature count M=(d+1)(d+2)/2, the decoder memorizes the corpus, so N should be 5–10× M.
- The usable scope is narrow
- The method needs a PCA fit on corpus statistics, so it only works for a fixed corpus.
- At d=256, M=33K and the Ridge solve takes 5–15 minutes on CPU, and since cost scales with M³, d=384 becomes impractical.
Community Reactions
- Commenters said the technique isn't new
- Several pointed out that expanding the feature space with quadratic terms is standard teaching for OLS, and that scikit-learn's KernelPCA with a degree-2 polynomial kernel is equivalent.
- The view was that the author's claim of it being rare in ML is not quite accurate.
- A commenter objected that it can fail out of distribution
- The quadratic decoder specializes to the corpus, so on out-of-distribution data it can be wrong in biased ways that PCA is not.
- They added that on a large enough corpus it may still generalize, since most data would be in-distribution.
- Critics said the geometric story doesn't single out this decoder
- The view was that the cone effect explains why PCA struggles but not why a quadratic decoder specifically fits.
- They said the real substance is just that second-order reconstruction helps empirically.
- Some linked it to TurboQuant and wanted to try it
- One commenter noted the similarity to KV cache quantization that uses random rotations to make data isotropic.
- A user who had been trying PCA plus various rotations for vector compression said they'd try it.
How to Apply
- Measure a PCA baseline on your own embeddings
- Today, compare NDCG@10 for PCA top-256 and half-whitened PCA against raw on a sample of your corpus embeddings.
- Half-whitened means cosine search on coordinates p / eigvals^(1/4).
- Check feasibility from document count and d
- Compute M=(d+1)(d+2)/2 and verify that your document count N is at least 5–10× M.
- The thresholds are N≳200K for d=256 and N≳50K for d=128.
- Reproduce with the author's beir_eval.py
- Clone github.com/IvanPleshkov/poly-autoencoder and run it with your model and corpus.
- The post says it takes 30–40 minutes on an M-series MacBook.
- Skip it for multi-tenant SaaS, streaming, and edge
- Where you can't fix corpus statistics, use an MRL-trained model with embedding[:d] slicing.
- Naively slicing a non-MRL model (bge, e5) drops NDCG by up to 15 p.p. at d=128.
Try It
# Paste into Claude/ChatGPT (simplified version of the post's method: a prompt asking for local numpy code)
Write Python (numpy) code for my embedding compression experiment.
Goal: compress embeddings to d dims with a PCA encoder + degree-2 polynomial Ridge decoder, then compare cosine retrieval quality of the reconstructed vectors (V̂) against raw.
Requirements:
1. Inputs: {{corpus embeddings .npy path}} (N x D), {{query embeddings .npy path}}, {{describe qrels format}}
2. d={{128 or 256}}; PCA subtracts the corpus mean and uses the top-d covariance eigenvectors (queries must not be used in the fit)
3. Normalize p as p / sqrt(eigvals), then scale so the max norm is 0.9
4. Lift: [1, p_i, p_i*p_j (i<=j)], dimension M=(d+1)(d+2)/2
5. Decoder: G = L.T@L + lam*trace(L.T@L)/M*I, lam=1e-3, W = np.linalg.solve(G, L.T@V)
6. Compare NDCG@10 for raw, PCA top-d, PCA half-whitened (p/eigvals^(1/4)), and poly-AE
7. Before starting, check that N is at least 5× M and print a warning if not
8. If memory is tight, accumulate L.T@L in chunksTerminology
Related Papers
FutureBench: A Renewable Framework for Evaluating Knowledge-Context Conflict in LLMs
Adding 'verify and prioritize the passage' to RAG prompts raised false-passage adoption; a knowledge-priority warning fixed it.
Faster Retrieval for Better, More Efficient RAG
Small neural nets learned query routing, hitting the same recall up to 8x faster in IVF search
Memorilla: Latent Semantic Memory for LLMs
Compressing documents into 16 memory tokens beat full-context accuracy on FactKG.
What the Author Wrote, What the Agent Reads: Silent Cue Loss in Enterprise Document Ingestion
Preserving red text and highlights in docx ingestion lifted marked-requirement F1 from 0.150 to 0.690.
Multimodal Reranking Is a System One Decision
One multiple-choice question to a VLM over 16 candidates reranks them, beating a dedicated 2B reranker.
You could have invented transformers from memory
Viewing linear, MLP and attention layers as memory stores: capacity goes ~64 to ~2,700 to over a million
Pointing AI at archives found a forgotten meteorite, lost rhinos, and more
Embedding search plus a cheap filter model surfaced unrecorded events in 400 years of archives
EmbeddingGemma 2: An open, lightweight multimodal embedding model
One open 740M model embeds text, images, audio and video into a single shared vector space