Abstract
We provide a simple method for improving the performance of the recently introduced learned Bloom filters, by showing that they perform better when the learned function is sandwiched between two Bloom filters.
Introduction
Bloom filters are fundamental probabilistic data structures used for membership testing with zero false negatives and a controllable false positive rate (FPR). Recently, "Learned Bloom Filters" (LBFs) have been proposed, which leverage machine learning models (oracles) to capture data distributions and reduce memory overhead. In a standard LBF, an oracle predicts membership; however, because oracles can produce false negatives, a backup Bloom filter is required to store elements the oracle misses. This paper investigates whether the standard two-stage architecture is optimal and proposes a superior "sandwiched" alternative.
The Sandwiched Architecture
The proposed Sandwiched Learned Bloom Filter (SLBF) introduces an additional "Initial Filter" before the learned oracle. This creates a three-stage pipeline:
- Initial Filter ($B_1$): Acts as a first-pass screen. If it returns "negative," the item is definitely not in the set.
- Learned Oracle ($f$): If the initial filter returns "positive," the ML model predicts membership.
- Backup Filter ($B_2$): If the oracle predicts "negative," the backup filter is checked to account for potential oracle false negatives.
By placing a filter before the oracle, the system can reject many negative queries before they ever reach the more computationally expensive or potentially biased learned model.
Theoretical Analysis and Optimization
A key contribution of this work is the mathematical derivation of optimal bit allocation across the filters. Given a fixed budget of $b$ bits per element, the goal is to minimize the total FPR.
The "Constant Backup" Result
Analysis reveals a surprising property: the optimal size for the backup filter ($b_2$) is a constant that depends only on the oracle's error rates ($F_p$ and $F_n$), independent of the total memory budget. Specifically, the optimal $b_2$ is defined as: $$b_2 = F_n \log_\alpha \frac{F_p}{(1 - F_p) (\frac{1}{F_n} - 1)}$$ where $\alpha$ relates to the Bloom filter efficiency (typically $1/2$ for optimal filters). Any additional memory allocated to the system should be directed entirely to the initial filter ($b_1$), rather than being distributed across both.
Results and Performance
The SLBF demonstrates significant performance gains over the standard LBF. In a representative scenario with a total budget of 8 bits per key and an oracle with a 1% false positive rate, the standard LBF achieves an FPR of approximately 0.010015. Under the same constraints, the SLBF reduces the FPR to 0.000777—representing a more than 10x improvement.
Furthermore, the initial filter provides a layer of robustness. In environments where the query distribution shifts away from the training data, the initial filter shields the oracle from many "out-of-distribution" negatives, maintaining a more stable overall FPR.
Conclusion
The "sandwiched" approach provides a more efficient and robust framework for learned probabilistic data structures. By treating the learned oracle as a component within a larger filtering pipeline rather than the primary logic, we can achieve order-of-magnitude improvements in space efficiency. Future research may explore joint optimization of the oracle's internal decision thresholds alongside the filter sizes to further push the boundaries of performance.
Summary updated