Resonance-Based Semantic Protocol - Ultra-fast search and indexing
Project description
RBSP
Resonance-Based Semantic Protocol -- a zero-dependency, pure-Python search engine with BM25 ranking, HNSW vector search, resonance-based hybrid fusion, and a built-in HTTP API. 85 modules. 3,233 tests. No pip install required beyond Python 3.9+.
What is RBSP?
RBSP is a full-featured search engine written entirely in Python's standard library. It combines classical information retrieval (BM25, inverted index, Porter stemmer) with modern vector search (HNSW, binary/product quantization) and a novel resonance-based hybrid fusion algorithm. It ships as a library, CLI tool, and HTTP server -- all with zero external dependencies.
| 85 modules | Full IR stack: indexing, ranking, vector search, hybrid fusion, reranking |
| 3,233 tests | Comprehensive suite across 85 test files -- no external services needed |
| 0 dependencies | Pure Python stdlib. pip install rbsp and you are done |
| Python 3.9 -- 3.13 | Tested on every supported CPython release |
Installation
pip install rbsp
Or install from source:
git clone https://github.com/yethikrishna/rbsp-framework.git
cd rbsp-framework
pip install -e .
Quick Start
Python API
from rbsp import init, index, search
# Initialize and index a project
init("/path/to/project")
stats = index("/path/to/project")
print(f"Indexed {stats.files_indexed} files in {stats.duration:.2f}s")
# Search
results = search("authentication logic", max_results=10)
for r in results[:5]:
print(f"{r.path}:{r.line} ({r.score:.2f})")
Or use the one-line API -- resolve auto-initializes on first call:
from rbsp import resolve
results = resolve("database connection")
for r in results[:5]:
print(f"{r.path}:{r.line} ({r.score:.2f})")
CLI
# Initialize and index
rbsp init .
rbsp index .
# Search
rbsp search "authentication logic"
# Search with options
rbsp search "database" --limit 10 --verbose --json
# Watch for file changes and re-index automatically
rbsp watch .
# View index status
rbsp status
# Manage configuration
rbsp config max_results 50
HTTP API
Start the server:
from rbsp.runtime.server import RBSPServer
server = RBSPServer(host="127.0.0.1", port=7342, auto_init=".")
server.serve_forever()
Query via curl:
# Quick search via query params
curl "http://127.0.0.1:7342/api/v1/search?q=authentication"
# Full query with options
curl -X POST http://127.0.0.1:7342/api/v1/resolve \
-H "Content-Type: application/json" \
-d '{"query": "authentication logic", "max_results": 10}'
# Trigger indexing
curl -X POST http://127.0.0.1:7342/api/v1/index \
-H "Content-Type: application/json" \
-d '{"path": ".", "force": false}'
# Health check
curl http://127.0.0.1:7342/health
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Liveness probe |
| GET | /api/v1/status |
Engine status, metrics, and throttle stats |
| POST | /api/v1/resolve |
Full query (JSON body) |
| GET | /api/v1/search?q=... |
Query via query parameters |
| POST | /api/v1/index |
Trigger indexing |
| POST | /api/v1/init |
Initialize the engine |
| POST | /api/v1/watcher/start |
Start file watcher |
| POST | /api/v1/watcher/stop |
Stop file watcher |
| GET | /api/v1/watcher |
Watcher status |
Features
Classical Information Retrieval
- Okapi BM25 Ranking -- k1=1.2, b=0.75 with normalized scoring
- BM25F -- Field-weighted BM25 for multi-field documents
- Inverted Index -- Term-to-document posting lists with document frequency tracking
- WAND-style Early Termination -- Skips non-competitive candidates for top-K
- LSH (Locality-Sensitive Hashing) -- MinHash with configurable bands/rows
- Phrase Queries -- Exact and near-phrase matching with configurable slop
- Boolean Queries -- AND / OR / NOT query composition
- Wildcard Queries -- Prefix, suffix, and infix pattern matching
- Proximity Search -- Find terms within a positional window
- Porter Stemmer -- Algorithmic stemming at index and query time
- Spell Checking -- Edit-distance-based query correction
- Query Suggestions -- Typeahead / autocomplete from the index
- Query Expansion -- Automatic term expansion for broader recall
- Synonyms -- Synonym expansion for query enrichment
- Highlighting -- Snippet extraction with match highlighting
- Faceted Search -- Drill-down aggregations by field, directory, file type
- Freshness Scoring -- Time-decay boost for recently modified documents
- Diversity Ranking -- MMR-style result diversification
- Language Model Scoring -- Statistical language model retrieval
- Learning to Rank -- Pluggable LTR scoring with feature extraction
Vector Search
- HNSW Index -- Hierarchical Navigable Small World graph for O(log n) ANN search
- Binary Quantization -- Hamming distance via XOR + popcount on Python ints
- Product Quantization -- Subspace codebook compression for memory efficiency
- Unified VectorStore -- Four search modes: exact, hnsw, binary, hybrid
- FilterExpression DSL -- Composable metadata filters (
&,|,~operators) - Filtered HNSW -- 3-tier adaptive fallback (HNSW -> widened ef -> exact)
- Cosine and L2 Distance -- Pluggable distance functions
Hybrid Fusion
- Resonance Model -- Novel wave-interference-inspired fusion of BM25 + vector scores
- 3 Interference Modes -- Constructive, adaptive, and linear
- Coherence Scoring -- Based on rank agreement between signals
- Adaptive Resonance -- Self-tuning alpha via click feedback (EMA)
- Multi-Signal Resonance -- N-signal generalization beyond two rankers
- Ensemble Methods -- Linear, RRF, CombScore, CombMax, Borda, Min fusion
Reranking
- Cross-Encoder Pipeline -- Two-stage retrieve-then-rerank architecture
- Pluggable Backends -- Cohere Rerank, HuggingFace Transformers, or custom encoders
- DummyCrossEncoder -- Zero-dependency BM25-based heuristic for testing
- Score Fusion -- Linear interpolation with alpha blending
Embeddings
- Provider Abstraction -- Unified interface for OpenAI, Cohere, Ollama, and custom backends
- Document Chunking -- Fixed, sentence, and paragraph strategies with configurable overlap
- EmbeddingPipeline -- Chunk + embed in a single call
- DummyProvider -- Deterministic vectors for testing without API keys
Advanced Query
- Query Planning -- Cost-based query plan optimization
- Query Rewriting -- Automatic query normalization and transformation
- Score Explanation -- Per-result scoring breakdown for debugging
HTTP API
- REST/JSON Server -- Built on stdlib
http.serverwithThreadPoolExecutor - HTTP/1.1 Keep-Alive -- Configurable socket timeout
- API Key Authentication -- Optional
X-API-Keyheader validation - CORS Support -- Cross-origin headers for browser access
- Rate Limiting -- Token bucket + backpressure with
429/503andRetry-After - Slow Query Log -- Queries exceeding a latency threshold are logged
- Metrics -- Counters, histograms, and gauges for monitoring
- Graceful Shutdown -- Drains in-flight requests before stopping
Durability
- Write-Ahead Log -- Binary WAL with CRC32 integrity checks and crash recovery
- 7 Operation Types -- INSERT, DELETE, UPDATE, CHECKPOINT, SEGMENT_CREATE/MERGE/DELETE
- Configurable Sync -- FSYNC, FDATASYNC, or NONE modes
- Checkpointing -- Periodic WAL truncation at safe sequence numbers
- Snapshots -- Point-in-time index snapshots
- Segments -- Segmented index architecture with background merging
Distribution
- Jump Consistent Hash -- Minimal reassignment on shard count changes (Lamping & Veach 2014)
- Shard Partitions -- Each wraps its own VectorStore + InvertedIndex
- Scatter-Gather Queries -- Parallel query across shards with result merging
- Replica Manager -- Read replicas with health tracking
- Consistency Levels -- ONE, QUORUM, ALL for reads and writes
- Online Rebalancing -- Migrate to a new shard count without downtime
Indexing
- Incremental Indexing -- Only re-indexes changed files
- Concurrent Indexing -- Thread-pool-based parallel file processing
- File Watching -- Live re-indexing on file system changes
- MMap Store -- Memory-mapped binary storage for large indexes
- Positional Postings -- Term positions stored for phrase and proximity queries
- Doc Values -- Columnar storage for sort and aggregation fields
- Deletion Tracking -- Soft deletes with periodic compaction
- Index Warmup -- Pre-loads hot data into memory on startup
Data Structures
- Bloom Filter -- Probabilistic set membership with configurable false-positive rate
- Counting Bloom Filter -- Supports deletions via counters
- Roaring Bitmaps -- Compressed integer sets for posting list intersection
- Skip Lists -- O(log n) sorted set for ordered iteration
- Finite State Transducers -- FST for fast prefix/fuzzy lookups
- Levenshtein Automata -- Edit distance computation for fuzzy matching
- Varint Encoding -- Variable-length integer encoding for compact storage
- LZ4/Snappy-style Compression -- Block compression for stored fields
Integrations
- File System -- Recursive directory traversal with gitignore-style filtering
- Git -- Git-aware indexing (respects
.gitignore, tracks blame metadata) - Plugin System -- Extensible resolvers, indexers, and rankers via plugin registry
- Schema System -- Typed field definitions with validation
- Migration System -- Index schema migrations across versions
Advanced Usage
Vector Search
from rbsp.indexer.vector_store import VectorStore, FieldCondition
store = VectorStore(dim=128, distance="cosine")
store.insert("doc1", [0.1] * 128, metadata={"category": "tech"})
# HNSW search with metadata filter
results = store.search(
[0.1] * 128, k=5, mode="hnsw",
filter_expr=FieldCondition("category", "eq", "tech"),
)
Hybrid Retrieval
from rbsp.query.hybrid import HybridRetriever, ResonanceConfig
retriever = HybridRetriever(ResonanceConfig(interference_mode="adaptive"))
fused = retriever.fuse(bm25_ranking, vector_ranking, top_k=10)
Write-Ahead Log
from rbsp.indexer.wal import WriteAheadLog, WALConfig, WALOperation
with WriteAheadLog(WALConfig(log_dir="/tmp/rbsp-wal")) as wal:
wal.append(WALOperation.INSERT, b'{"doc_id": "abc"}')
wal.checkpoint()
entries = wal.recover() # Replay after crash
Distributed Sharding
from rbsp.runtime.distributed import ShardedIndex, ShardConfig
idx = ShardedIndex(ShardConfig(num_shards=4, replication_factor=2))
idx.insert("doc1", tokens=["python", "search"], vector=[0.1] * 128)
results = idx.search_vector([0.1] * 128, k=10)
Architecture
rbsp/
core/ Classical IR primitives (BM25, stemmer, LSH, bloom, HNSW,
quantization, embeddings, chunker, roaring bitmaps, FST, ...)
indexer/ Storage layer (inverted index, vector store, WAL, mmap,
segments, concurrent indexing, merge, ...)
query/ Query pipeline (hybrid fusion, reranker, ensemble, boolean,
phrase, wildcard, spellcheck, facets, learning-to-rank, ...)
runtime/ Orchestration (engine, config, plugins, CLI, HTTP server,
distributed sharding, monitoring, throttle, ...)
integration/ External integrations (filesystem, git)
How a query works
- Parse -- Tokenize and stem via Porter stemmer.
- Retrieve -- O(1) candidate lookup via InvertedIndex + LSH.
- Score -- BM25 with trigram fuzzy matching (0.8 / 0.2 blend).
- Prune -- WAND-style early termination skips non-competitive candidates.
- Rank --
heapq.nlargestfor top-K selection. - Snippet -- Extract best-matching lines only for final results.
Optionally, vector search (HNSW) retrieves dense-embedding candidates, resonance fusion merges BM25 and vector rankings via wave interference, and a cross-encoder reranker refines the final top candidates.
How indexing works
- Files are discovered via recursive directory traversal (respecting
.gitignore). - Each file is tokenized, stemmed, and added to the inverted index and LSH index.
- Term frequencies, document lengths, and trigrams are stored for BM25 and fuzzy matching.
- All mutations are recorded in the WAL before being applied.
- Periodic background merging compacts segments for efficient storage.
Design Philosophy
- Zero dependencies -- stdlib only, no C extensions, no pip install overhead.
- O(1) candidate retrieval -- InvertedIndex + LSH instead of brute-force scan.
- WAND early termination -- skips documents that cannot reach top-K.
- heapq everywhere --
nlargest/nsmallestavoids full sort. - Deferred snippet extraction -- only reads files for final top-K results.
- Binary quantization -- Python
intas SIMD: XOR + popcount in 2 ops. - Thread-safe by design --
threading.Lock/RLockon all shared structures. - Lazy initialization -- heavy resources allocated only on first use.
- MMapStore binary persistence -- fast index load and save.
- Jump consistent hash -- minimal reassignment on shard count changes.
Benchmarks
RBSP ships a benchmark suite covering core operations, indexing throughput, search latency, and vector search performance:
python benchmarks/benchmark_core.py # Signature, bloom, LSH, registry
python benchmarks/benchmark_index.py # Indexing throughput
python benchmarks/benchmark_search.py # Search latency vs corpus size
python benchmarks/benchmark_vector.py # HNSW and quantized vector search
python benchmarks/benchmark_e2e.py # End-to-end pipeline
Development
Prerequisites
- Python 3.9+
Setup
git clone https://github.com/yethikrishna/rbsp-framework.git
cd rbsp-framework
pip install -e ".[dev]"
Running Tests
python -m pytest tests/ -v
The full suite of 3,233 tests runs without any external services or API keys.
Python Version Support
| Python | Status |
|---|---|
| 3.9 | Supported |
| 3.10 | Supported |
| 3.11 | Supported |
| 3.12 | Supported |
| 3.13 | Supported |
Contributing
See CONTRIBUTING.md for guidelines on development setup, testing, code style, and the pull request process.
License
MIT -- Copyright (c) 2026 kkvin
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 rbsp-0.1.1.tar.gz.
File metadata
- Download URL: rbsp-0.1.1.tar.gz
- Upload date:
- Size: 405.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
163afe4e3095de7454f134af96104521e2821b8f184b50180a4df62e37dfe953
|
|
| MD5 |
2867d10647a7e2fac51526582523de0f
|
|
| BLAKE2b-256 |
6fe551b4f945c9f5b086f30b06d9c619beb223ba785a2c1a88653f1ee94bfda0
|
Provenance
The following attestation bundles were made for rbsp-0.1.1.tar.gz:
Publisher:
publish.yml on yethikrishna/rbsp-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rbsp-0.1.1.tar.gz -
Subject digest:
163afe4e3095de7454f134af96104521e2821b8f184b50180a4df62e37dfe953 - Sigstore transparency entry: 925100807
- Sigstore integration time:
-
Permalink:
yethikrishna/rbsp-framework@ed770cc17cdc2f74bc249090d55d1ac81d19848a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yethikrishna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ed770cc17cdc2f74bc249090d55d1ac81d19848a -
Trigger Event:
push
-
Statement type:
File details
Details for the file rbsp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rbsp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 274.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05b0c156c08e8f6ba5b3e827fc6c5895709f72a12cb07c4bcb2589b88e378c63
|
|
| MD5 |
f99144d86853ab330d68751c728d9b62
|
|
| BLAKE2b-256 |
8f9f54ceaeb1034b2f84bd34634243305661061346585b6c751a34cf2b6f3468
|
Provenance
The following attestation bundles were made for rbsp-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on yethikrishna/rbsp-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rbsp-0.1.1-py3-none-any.whl -
Subject digest:
05b0c156c08e8f6ba5b3e827fc6c5895709f72a12cb07c4bcb2589b88e378c63 - Sigstore transparency entry: 925100857
- Sigstore integration time:
-
Permalink:
yethikrishna/rbsp-framework@ed770cc17cdc2f74bc249090d55d1ac81d19848a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yethikrishna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ed770cc17cdc2f74bc249090d55d1ac81d19848a -
Trigger Event:
push
-
Statement type: