Summary

An embedded hybrid search database written in Rust that runs in-process on memory-mapped local files. A single query combines BM25 full-text search, 1-bit RaBitQ dense vectors, learned sparse terms, and typed attribute filters, fused inside the engine with immediate read-after-write visibility.

Most search systems assume a separate server process and a network hop. Hinny takes the opposite starting point: an embedded library in Rust, with Python (PyO3, zero-copy NumPy), Node.js (N-API), and C bindings, built for local RAG, coding agents, desktop apps, and CLI tools where search belongs inside the application process. An optional HTTP server (hinny-server) and read-replica layer (hinny-replica) sit on top of the same engine when a shared service is needed.

Storage and concurrency

Each namespace is an independent log-structured merge-tree (LSM) backed by immutable, memory-mapped files. Every write batch appends one CRC32-checksummed record to a write-ahead log and inserts an immutable chunk into the active memtable, so writes are searchable the moment the call returns. When the memtable reaches its threshold, it freezes and flushes in the background while new writes continue into a fresh memtable; size-tiered merges combine segments without re-tokenizing or re-embedding documents.

Stored document text is separated from the index following WiscKey: segments keep only a 16-byte reference per passage pointing into separate blob files of 4~KiB zstd-compressed blocks. Merges copy references rather than rewriting text, and blocks are decompressed only for the final top-kk hits and snippets.

Concurrency uses lock-free multi-version reads:

  • Every write batch increments a monotonic sequence number and publishes a new immutable View via atomic pointer swap. Queries grab the current View without ever acquiring the writer lock.
  • Each passage carries an atomic delete stamp (00 if live, or the sequence number that deleted it), so a snapshot at sequence nn sees a passage iff its stamp is 00 or >n> n. Deletes are a single atomic store with no bitmap cloning per write.
  • Copy-on-write namespace forks (ns.fork(...)) hard-link immutable segments, blobs, and deletion files into a staged directory and swap a fresh manifest into place. Forking a one-million-document namespace takes 3.9~ms with zero extra disk until writes diverge.

Every file format carries an explicit version tag and checksum (whole-file CRC32 on manifests and deletion files, per-batch CRC32 on WAL records, per-MiB CRC32 on segment bodies, and zstd checksums on text blobs). Crash safety is verified against 344 injected I/O fault points, 40 random SIGKILL runs during concurrent flushes and merges, and single-bit corruption tests.

Full-text, sparse, and columnar filters

Full-text indexing implements BM25 with Snowball stemming across 18 languages, 128-document SIMD-BP128 posting blocks, Pareto impact bounds, and block-max MaxScore pruning. Because block upper bounds store the Pareto front of term frequency and document length rather than precomputed BM25 scores, global IDF and average field lengths stay exact across immutable segments. Learned sparse fields (such as SPLADE or inference-free sparse encoders) quantize term weights to hundredths and share the same inverted-index format, switching to term-at-a-time accumulation when query posting lists cover most of a segment.

Typed attributes (integers, order-preserving floats, dictionary-encoded strings, and inverted-list tags) are stored per segment as compact columns with 1,024-document zone maps and a 32-entry per-segment bitmap cache. Filters execute inside search rather than as post-filters: selective bitmaps drive scoring directly, while dense bitmaps check membership before top-kk insertion.

Vector search and hybrid fusion

Vector search is memory-bandwidth bound, so Hinny stores vectors compressed with 1-bit RaBitQ codes after a randomized Hadamard rotation, pre-packed on disk into 32-code FastScan SIMD blocks (NEON on ARM; runtime-dispatched AVX2/FMA/F16C or SSE2 on x86-64). Only candidates whose RaBitQ lower bound beats the current kk-th hit are reranked from half-precision (f16) rows laid out in cluster order—typically fewer than 0.5%0.5\% of the collection.

Segments share centroid generations sized for 2N\sqrt{2N} so flushes and merges copy cluster lists without re-clustering, retraining automatically once a namespace grows 4×4\times. Each generation self-calibrates its probe budget at build time on 256 sampled vectors to hit 0.9970.997 recall@10 across varying data distributions. For dot-product search under wide vector-length skew, Hinny clusters unit-normalized directions and decomposes each vector orthogonally as

x=λc+r,r⊥c,x = \lambda c + r, \qquad r \perp c,

storing exact λ\lambda alongside the quantized residual rr so ⟨q,x⟩=λ⟨q,c⟩+⟨q′,r⟩\langle q, x \rangle = \lambda \langle q, c \rangle + \langle q', r \rangle remains accurate regardless of vector magnitude.

Hybrid queries run BM25, sparse, and vector retrievers in parallel under the same filter with fixed candidate depths (200 text, 100 vector, 200 sparse by default) and combine scores via min–max convex fusion (0.5 lexical / 0.5 vector by default, with Reciprocal Rank Fusion available as an option).

Measurements

Single-threaded warm-cache measurements on Apple Silicon (full methodology and reproduction scripts live in the repository and on hinny.dev/benchmarks):

Workload Dataset Hinny Baseline
Hybrid latency BEIR FiQA (57,638 docs) 0.29~ms p50 11–21×\times faster than LanceDB across 5 BEIR sets
Vector search 1M×2561\text{M} \times 256-d clustered 0.089~ms p50 / 0.133~ms p99 0.999 recall@10, 597~MB index
Full-text OR 1.1M passages, top 200 7.8~ms p99 Tantivy: 34.5~ms p99 (identical BM25 scores)
Concurrent writes 80,000 writes + live queries 1.1~s total (0.05~ms p99) 19~s under a reader–writer lock
File names 9.2M macOS paths (hinny-names) 0.08~ms p50 SQLite FTS5 trigram: 0.5–320~ms