spark_lshbloom
spark_lshbloom is a Spark package for approximate text deduplication using
MinHash LSH band keys and mergeable Bloom Filters.
The package exposes two execution modes:
mode="lshbloom": primary LSHBloom mode. It builds partition-local Bloom filters, merges them into a global filter, and broadcasts the global filter for read-only duplicate queries.mode="minhash_lsh": distributed MinHashLSH-style baseline usingexplode(band_keys) -> groupBy(band_key).
Backward-compatible aliases are supported: bloom/bloom_filter map to
lshbloom, and banding maps to minhash_lsh.
Install
From the repository root:
pip install -e .\spark_lshbloom
Basic Usage
from spark_lshbloom import SparkLSHBloom
lsh = SparkLSHBloom(threshold=0.85, num_perm=256, mode="lshbloom")
# Production-style usage: fit a reference corpus, then query new documents.
lsh.fit(reference_df, text_col="text", id_col="id")
lsh.save("runs/my_bloom_filter")
lsh = SparkLSHBloom.load("runs/my_bloom_filter")
result_df = lsh.transform(new_df, text_col="text", id_col="id")
unique_new_df = result_df.filter(~result_df["is_duplicate"])
One-shot Deduplication
For experiments:
unique_df = lsh.deduplicate(df, text_col="text", id_col="id")
In mode="lshbloom", one-shot deduplication uses chunked incremental processing:
each chunk is queried against Bloom filters built from earlier chunks. This
keeps the LSHBloom idea and avoids fitting on the whole dataset before querying
the same dataset. Duplicates inside the same chunk may not be removed, so use
more chunks for stricter experiments.
For exact distributed LSH bucket baseline:
banding = SparkLSHBloom(threshold=0.85, num_perm=256, mode="minhash_lsh")
unique_df = banding.deduplicate(df, text_col="text", id_col="id")
peS2o Benchmark
The benchmark compares the primary LSHBloom index against a distributed MinHashLSH band table:
python spark_lshbloom\benchmarks\benchmark_pes2o.py `
--input-path MinHash-OPH-DOPH-benchmark\data\pes2o_50k `
--out-dir spark_lshbloom\runs\pes2o_benchmark_50k `
--sizes 10000,50000 `
--num-perm 128 `
--num-bands 32 `
--shingle-size 5 `
--max-shingles 2048 `
--master local[4] `
--local-io-mode pyarrow
The main output is:
spark_lshbloom/runs/pes2o_benchmark_50k/benchmark_results.csv
Important benchmark columns:
method:lshbloomorminhash_lsh.wall_clock_sec: elapsed time for building the index.index_size_gb: saved index size on disk.band_entries: number of LSH band keys represented.driver_rss_delta_gb: approximate driver memory increase.
For lshbloom, index_size_gb is the saved Bloom filter size. For
minhash_lsh, it is the compressed Parquet size of the explicit band table.
On a local peS2o 50k benchmark with num_perm=128, num_bands=32, and
max_shingles=2048, the prototype showed about 3.1x faster index
construction and about 7x smaller index size for lshbloom compared with
the explicit distributed minhash_lsh band table.
On Windows, use --local-io-mode python if Spark/Arrow workers are unstable.
Important Design Notes
- Broadcast Bloom filters are read-only on Spark executors.
- Distributed updates are handled by partition-local Bloom filters followed by driver-side merge.
- Character n-gram shingling is supported by default.
- Pandas UDFs are used for band-key generation when Spark executes the pipeline.
max_shinglescan cap per-document shingle work for long documents.
Outputs and Metrics
Useful columns and metrics for reporting:
is_duplicate: approximate membership result.band_keys: generated LSH band keys.bloom.num_bits,bloom.num_hashes: Bloom filter configuration.- Bloom filter file size from
save(path). - Spark job wall-clock time and partition counts.
Metadata
Release files for spark-lshbloom 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spark_lshbloom-0.1.0.tar.gz | 13.4 kB | Without provenance | Details for spark_lshbloom-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spark_lshbloom-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for spark_lshbloom-0.1.0-py3-none-any.whl |
Total release size: 23.5 kB
Release files / spark_lshbloom-0.1.0.tar.gz
| Download URL | spark_lshbloom-0.1.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9540ee521f2e661dbadf4436675f5adc1b41e51db362ae14027cbeea13e96ebf
|
|
BLAKE2b-256 checksum How to use checksums |
fdab85a701bbe81a5dddd175937d1349432a7e3cea468af4219a4e28bb2ff85c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / spark_lshbloom-0.1.0-py3-none-any.whl
| Download URL | spark_lshbloom-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e8591b478b5e56d15b8e2da987c77483c161df8232859c5c4b860c01e2cc2f8
|
|
BLAKE2b-256 checksum How to use checksums |
22c8e27b321832f5602f0e03f3bf7cd39a0d1c066e524974a6d6d1dab0f203b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for spark-lshbloom 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.