rsetsim
Exact set similarity search and all-pairs similarity join for Python,
implemented in Rust via PyO3. It is a fast, multi-threaded,
API-compatible replacement for
SetSimilaritySearch.
from rsetsim import all_pairs, SearchIndex
sets = [["a", "b", "c"], ["a", "b", "d"], ["x", "y"], ["a", "b", "c", "e"]]
# Every pair with Jaccard >= 0.5: [(x, y, similarity), ...] with x > y
all_pairs(sets, similarity_func_name="jaccard", similarity_threshold=0.5)
# [(1, 0, 0.5), (3, 0, 0.75)]
index = SearchIndex(sets, similarity_func_name="jaccard", similarity_threshold=0.5)
index.query(["a", "b", "c"]) # [(0, 1.0), (3, 0.75), (1, 0.5)]
index.query_batch([q1, q2, ...]) # parallel, GIL released
Why
Finding near-duplicate records, documents (as shingle sets), users with
similar histories, or matching entities is a set similarity join. The
practical exact algorithms (AllPairs, Bayardo et al. 2007; PPJoin, Xiao et
al. 2008) are well known. In Python, the only implementation is
SetSimilaritySearch, which is pure Python + numpy, and its README directs
users to a Go port for performance. MinHash LSH (datasketch, rensa) is
the usual alternative, but it is approximate: it misses some pairs and
needs tuning. rsetsim gives exact answers, fast.
Install
pip install rsetsim
Prebuilt abi3 wheels (Linux/macOS/Windows, Python 3.11+).
Benchmarks
Synthetic Zipf-distributed token sets (5–50 tokens from a 50k vocabulary,
20% planted near-duplicates), Jaccard ≥ 0.5, 8 threads. Source:
benchmarks/bench.py.
| task | n sets | rsetsim | SetSimilaritySearch | speedup |
|---|---|---|---|---|
all_pairs |
10,000 | 0.046s | 5.75s | 126x |
all_pairs |
100,000 | 1.13s | 629s | ~560x |
build SearchIndex |
100,000 | 0.22s | 1.69s | 8x |
10k × query() |
100,000 | 1.52s | 117s | 77x |
10k queries via query_batch() |
100,000 | 0.28s | 117s | ~410x |
all_pairs |
1,000,000 | 150s (1.1M pairs) | (not run) | |
10k queries via query_batch() |
1,000,000 | 7.3s | (not run) |
The pure-Python reference was not run at 1M sets. Results were checked to
be identical to SetSimilaritySearch (same pairs, same similarities)
wherever both ran.
API
all_pairs(sets, similarity_func_name="jaccard", similarity_threshold=0.5)
returns a list of (x, y, similarity) with x > y (indices into sets),
sorted by (x, y). It supports the symmetric measures jaccard, cosine,
and containment_min.
SearchIndex(sets, similarity_func_name="jaccard", similarity_threshold=0.5)
has the following methods:
.query(s)returns[(index, similarity), ...], sorted by similarity (highest first), then by index..query_batch(queries)runs many queries in parallel (the GIL is released).len(index),.similarity_func_name,.similarity_threshold.
Sets can be any iterables of hashable tokens (str, int, tuples, ...).
| measure | definition |
|---|---|
jaccard |
|A∩B| / |A∪B| |
cosine |
|A∩B| / √(|A|·|B|) |
containment (query only) |
|Q∩S| / |Q| |
containment_min |
|A∩B| / max(|A|,|B|), i.e. the smaller of the two containments |
Semantics
- Exact: there are no false positives or false negatives. Every candidate is verified with a full intersection, and all filters are provable bounds, rounded toward the safe side.
- Pairs that share no token are never reported, even at threshold 0 (same as the reference).
- Duplicate tokens within a set are ignored (the reference requires unique tokens and gives wrong answers otherwise).
- In
query, tokens the index has never seen count toward the query's size (same as the reference). - Thread count is controlled by
RAYON_NUM_THREADS(default: all cores).
How it works
- Frequency ordering: tokens are re-labelled by global frequency, rarest first, so set prefixes contain rare tokens.
- Prefix filter: if two sets need overlap ≥ α, their first
|s|-α+1tokens must intersect, so only prefixes are indexed and probed. Separate probe-side and index-side bounds are derived for each measure. - Size filter: partners whose size makes the threshold unreachable are skipped by binary search, because posting lists are ordered by set size.
- Positional filter (PPJoin): during the all-pairs probe and queries, a candidate is dropped as soon as its matched count plus the remaining tokens can't reach α.
- Verification: a sorted-merge intersection on
u32ranks.
Python tokens are mapped to dense u32 ids through a dict (so equality
and hashing follow Python semantics). Everything after that runs in Rust,
with the GIL released, in parallel across rayon threads.
Development
cargo test --no-default-features # includes brute-force equivalence tests
pip install -e '.[dev]' && maturin develop --release
pytest # Hypothesis tests vs brute force + vs SetSimilaritySearch
python benchmarks/bench.py # slow: the reference takes ~10 min at 100k
Metadata
Release files for rsetsim 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 |
|---|---|---|---|---|
| rsetsim-0.1.0.tar.gz | 19.6 kB | With provenance | Details for rsetsim-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| rsetsim-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for rsetsim-0.1.0-cp311-abi3-win_amd64.whl |
| rsetsim-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for rsetsim-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| rsetsim-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for rsetsim-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| rsetsim-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for rsetsim-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
| rsetsim-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for rsetsim-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 1.6 MB
Release files / rsetsim-0.1.0.tar.gz
| Download URL | rsetsim-0.1.0.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2151acac44804da0f1b51de0ffa02aa3c66faf1890a743f7d3dbf595f445cc2
|
|
BLAKE2b-256 checksum How to use checksums |
f5848f3f2b04027b82968a2843dd5027b4fd046eb0fa08250e55cab3a5d3f4f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rsetsim-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | rsetsim-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 233.0 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
300faa0104ab42261e15a8c1589926056b0fdb9d2076a75cceed1cbfbd0a39af
|
|
BLAKE2b-256 checksum How to use checksums |
3f765f1cb7ffa91caa2ee0a567f9d923269f1c70bf8fffe7c88b7b9fe56212ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rsetsim-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | rsetsim-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 345.3 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
72f54124f425b09f006b781e0484940dcc23b46eaf13878f3b5ec6ee98ba6f3c
|
|
BLAKE2b-256 checksum How to use checksums |
dd1def7196e5013ca953eb2213260dd2f986ee4ef710bc4c693b372c5d40046e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rsetsim-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | rsetsim-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 340.9 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
7c52e3e0c8ec21243c3988630c1de4dc834a76e344d1e9c240f0aff556913422
|
|
BLAKE2b-256 checksum How to use checksums |
2eba1546c947705117675c6bdba59f1700394965850d7b735405e298b59bd64c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rsetsim-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | rsetsim-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 309.6 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
14f59eb7b48bc74004a4f1a1c87fc515de5d3d60781f84acd15a17e5efbf1897
|
|
BLAKE2b-256 checksum How to use checksums |
d3c42b7a74d2febb302479c215f5e7c5e2e10050582d937933687ddeb1bc6967
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rsetsim-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | rsetsim-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 321.2 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
65f14e325b96c64f1881cdf78cb1d8169508d25f7ad567c0384625039752bd3d
|
|
BLAKE2b-256 checksum How to use checksums |
26ead3217f74ea1f3974381911e284cc46fa6515ffa0537c67ba07264e2e77ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for rsetsim 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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for rsetsim-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA 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.