FastRustRAG
Rust-based document deduplication for RAG pipelines. 50-100x faster than Python implementations.
Why?
Python's MinHash libraries are slow. This uses Rust + Rayon for parallel processing. Built it because I needed fast deduplication for preprocessing large document collections.
Performance
Benchmarked against datasketch (popular Python MinHash library):
| Documents | Python | FastRustRAG | Speedup |
|---|---|---|---|
| 500 | 246ms | 2ms | 121x |
| 1,000 | 414ms | 5ms | 81x |
| 2,000 | 838ms | 10ms | 79x |
| 5,000 | 2.1s | 38ms | 56x |
| 10,000 | 4.2s | 360ms | 11x |
| 50,000 | 21s | 2.4s | 8x |
Best performance on 500-5000 document batches (typical RAG use case).
Installation
pip install fastrustrag
Usage
import fastrustrag
# Create pipeline
pipeline = fastrustrag.DeduplicationPipeline(
num_bands=20,
num_hashes=128,
shingle_size=3,
similarity_threshold=0.8
)
# Your documents
docs = [
"The quick brown fox jumps over the lazy dog",
"A quick brown fox jumps over a lazy dog",
"Completely different content",
]
# Process and find duplicates
pipeline.process_documents(docs)
duplicates = pipeline.deduplicate_corpus()
for i, j, similarity in duplicates:
print(f"Docs {i} and {j} are {similarity*100:.1f}% similar")
API
DeduplicationPipeline
Parameters:
num_bands(int): LSH bands. Higher = more precision, fewer false positives. Default: 20num_hashes(int): MinHash functions. Higher = more accuracy, slower. Default: 128shingle_size(int): n-gram size. Use 2-3 for short texts, 3-5 for longer documents. Default: 3similarity_threshold(float): Minimum similarity (0-1) to consider duplicates. Default: 0.8
Methods:
# Process documents (returns count)
count = pipeline.process_documents(documents: list[str]) -> int
# Find all duplicate pairs
duplicates = pipeline.deduplicate_corpus() -> list[tuple[int, int, float]]
# Returns: [(doc_id1, doc_id2, similarity), ...]
# Find duplicates for specific query
results = pipeline.find_duplicates(query: str) -> list[tuple[int, str, float]]
# Get document by ID
doc = pipeline.get_document(doc_id: int) -> str | None
How it works
- MinHash: Generates hash signatures for fast similarity estimation
- LSH: Locality-sensitive hashing for efficient candidate generation
- Rayon: Automatic parallelization across CPU cores
The speedup comes from:
- Compiled Rust (no Python interpreter overhead)
- Parallel processing with Rayon (uses all cores)
- Efficient memory layout
Use cases
- Remove duplicate documents before indexing for RAG
- Deduplicate web scraping results
- Find plagiarized or copied content
- Clean datasets before training
Technical details
- Built with PyO3 for Python bindings
- Uses Rayon for data parallelism
- Thread-safe with RwLock for concurrent access
- AHash for fast non-cryptographic hashing
License
MIT
Contributing
Issues and PRs welcome. Main areas for improvement:
- Streaming API for very large datasets
- Additional distance metrics
- Persistence (save/load index)
Metadata
Release files for fastrustrag 0.1.2
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 | |
|---|---|---|---|---|
| fastrustrag-0.1.2.tar.gz | 31.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastrustrag-0.1.2-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
Total release size: 313.4 kB
Release files / fastrustrag-0.1.2.tar.gz
| Download URL | fastrustrag-0.1.2.tar.gz |
|---|---|
| Size | 31.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d26c6cb802dcc199e137f0e5baab7a9ffdea17938a93b554b79dcc9e56c11372
|
|
BLAKE2b-256 checksum How to use checksums |
1457866c56e33228e3f4eb32d0b3bd377e449da62432f5ce8bfdd1b2580e73b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|
Release files / fastrustrag-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fastrustrag-0.1.2-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 281.7 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
21172fda9e21c800c81aab1815e1e0eec642cd21735dceae08dc2c92b5ef6f6c
|
|
BLAKE2b-256 checksum How to use checksums |
af6c7888a274dbdeaba29e4315b774757a397d471f5af726a83f3531bfaaf832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|
Security for fastrustrag 0.1.2
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.