RMI Minimal Demo
A 50-line 2-stage Recursive Model Index (RMI) to accompany the article 学习型索引再审视:RMI、ALEX、PGM.
Dependencies
- Python 3.9+
numpy==1.26.4
Install:
pip install numpy==1.26.4Run
python rmi_minimal.pyWhat it shows
- Train a 2-stage RMI on 1M uniformly distributed sorted
int64keys. - Report
avg_errandmax_errof the predicted position vs. the real position. - Compare average probe counts of
rmi_lookup(prediction + bounded local binary search) against plain binary search on the same sample. - Inject 1% random inserts without retraining and
re-measure error — the
max_errtypically explodes, which is exactly the reason ALEX / PGM / RadixSpline exist.
Offline
The demo uses only numpy and deterministic
seeds. No network or dataset download is required.