A fast, memory-efficient hybrid search system combining BM25 and vector search
Reason this release was yanked:
bm25-chroma is correct name
Project description
Enhanced Hybrid Retriever
A fast, memory-efficient hybrid search system combining optimized BM25 and vector search with Reciprocal Rank Fusion (RRF).
Features
- Optimized BM25: Memory-efficient with integer indices and pre-sorted postings
- Vector Search: Semantic similarity using ChromaDB and sentence transformers
- Hybrid Fusion: Industry-standard Reciprocal Rank Fusion (RRF)
- Dual Processing Modes: Sequential or unified batch processing
- State Persistence: Automatic save/load of BM25 index
Quick Start
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from hybrid_retriever import HybridRetriever as HybridRetriever
# Initialize
retriever = HybridRetriever(
chroma_path="./my_db",
collection_name="my_docs"
)
# Add documents
documents = [
"Machine learning helps analyze data patterns.",
"Natural language processing understands human text.",
"Deep learning uses neural networks for complex tasks."
]
retriever.add_documents_batch(
documents,
mode="unified", # or "sequential"
show_progress=True
)
# Search
results = retriever.hybrid_search("machine learning", top_k=5)
for doc_id, score, metadata in results:
print(f"{doc_id}: {score:.3f} - {metadata['text'][:100]}...")
Installation
pip install -r requirements.txt
Testing
Run tests to verify functionality:
pytest tests/
Or run directly:
python tests/test_examples.py
Examples
examples/basic_usage.py- Simple example with custom documentsexamples/brown_corpus_demo.py- Full demo with Brown corpus
Processing Modes
Unified Mode (Recommended)
- Processes both BM25 and ChromaDB together
- Usually faster for large datasets
- Better for production use
Sequential Mode
- Processes ChromaDB first, then BM25
- Better for debugging and optimization
- Separate timing for each system
Performance
The system is designed for efficiency through incremental operations:
No Full Recalculation: Adding or removing documents updates only affected components:
- Vocabulary set adds/removes only new/orphaned terms
- Inverted index updates only posting lists for changed terms
- Document statistics incrementally adjust averages and counts
Python Native Libraries: Heavy lifting handled by optimized built-ins:
Counter.most_common()provides pre-sorted frequency listsheapq.merge()efficiently combines sorted posting listssetoperations for O(1) vocabulary lookups and updatesdefaultdict(Counter)for sparse term-document matrices
Batch Processing: Configurable batch sizes balance memory usage and processing speed:
- Pending additions buffer reduces index update frequency
- Automatic flush mechanism maintains data consistency
- Progress tracking for large document collections
API
Main Classes
BM25: Fast BM25 implementationHybridRetriever: Main hybrid search interface
Key Methods
add_documents_batch(): Add documents in batchessearch_bm25(): BM25-only searchsearch_vector(): Vector-only searchhybrid_search(): Combined search with RRFget_system_stats(): Performance statistics
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hybrid_retriever-0.1.0.tar.gz.
File metadata
- Download URL: hybrid_retriever-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e921fe1850891bc304de4840ac74a761ee9ac8ad85d65d739e257119ae38b44d
|
|
| MD5 |
4ceb5f760f70a207d0448319d91d116a
|
|
| BLAKE2b-256 |
654e8e7ce1001fa362fa61fe20e016984dec9b04398f51f5e797785cf6df3eb0
|
File details
Details for the file hybrid_retriever-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hybrid_retriever-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c7a64e484fddb69751ab59a43a725a0697ff9a35c748374dc6b8d218cb8215e
|
|
| MD5 |
749e5c45ce3ee67ada6075d757450f71
|
|
| BLAKE2b-256 |
f3f0f2b6f89b859334fc7d6d8759223b72da083643abc793ea012a714f902a51
|