Vector Search Systems · Tiered Retrieval & Spatial Indexing
A multi-tiered vector search engine that combines sub-5 microsecond exact byte-hash caching with KDTree spatial indexing and distance-weighted voting under Gaussian noise. Built to eliminate redundant spatial tree traversals in production workloads without external vector database dependencies.
Execute single vector queries or simulate a Pareto workload of 50 requests. Observe how the engine intercepts repeat vectors at the L1 byte-hash tier (sub-5μs) while routing noisy or novel vectors to the L2 spatial KDTree index.
Real-time switching between L1 \(\mathcal{O}(1)\) byte-hash table and L2 KDTree spatial index
Execution Path
Hash: 8f4a2e9c... (O(1))
Observed Latency
36× faster than tree search
Cache Hit Ratio
19 / 23 hits
Retrieved Neighbor Documents & Distance-Weighted Votes
| Rank | Document / Class | Distance | Weight | Status |
|---|
Engine Dispatch Log Stream
Multi-tier retrieval exploits the dualism between strict discrete equality and continuous spatial geometry.
For any normalized floating-point embedding vector \(\mathbf{v} \in \mathbb{R}^D\), we map its IEEE 754 bit-pattern directly into a 64-bit integer hash using MurmurHash3 / xxHash:
Since cryptographic collision probability is negligible (\(< 10^{-18}\) for 64-bit space), a match in the hash table guarantees exact mathematical equivalence, executing in \(\mathcal{O}(1)\) time without calculating distances.
When a query vector has been perturbed by noise \(\mathbf{q} = \mathbf{v} + \mathbf{\epsilon}\), the hash misses. The engine falls back to the L2 spatial KDTree index, which partitions the \(D\)-dimensional space via orthogonal hyperplanes in \(\mathcal{O}(k \log N)\) time. To aggregate the top-\(k\) nearest neighbors \(\{\mathbf{x}_1, \dots, \mathbf{x}_k\}\), each neighbor casts a distance-weighted vote:
The winning label is returned to the user and immediately written into the L1 hash cache alongside its query signature, ensuring all future identical calls resolve in microseconds.
Data flow diagram depicting the two-tier lookup and automatic cache injection loop.
Inbound Vector Query: q in R^D
│
▼ [64-bit Byte Hashing: h = hash(q.tobytes())]
L1 Direct Hash Cache Lookup (O(1))
│
├── Cache Hit! ──────────────────────────────────┐
│ (Match found in hash table) │
│ ▼
│ Return Stored Result (3.2 μs)
│
▼ Cache Miss (Novel or Noisy Query)
L2 Spatial KDTree Walk (O(k log N))
│
├── Compute Euclidean Distances to Partitions
├── Retrieve k-Nearest Neighbors
├── Calculate Distance-Weighted Voting: w_i = 1 / (d_i + eps)
│
▼
Populate L1 Hash Cache: cache[h] = {winner, confidence, neighbors}
│
▼
Return Nearest Neighbors (178 μs)
src/hybrid_engine.py — Multi-Tier Engine
Contains the HybridRetrievalEngine class. Coordinates thread-safe dictionary lookups, KDTree indexing via scipy.spatial.KDTree, and automatic LRU cache eviction when storage exceeds memory budgets.
tests/test_hybrid.py — Test SuiteSeven unit tests verifying: cache hit on exact vector, cache miss on noisy perturbation, distance weighting correctness, thread safety, and latency benchmarking assertions.
Across different compiler flags or architectures (ARM vs x86-64), minor IEEE 754 precision drift in the least significant bit produced distinct hash codes for conceptually identical vectors. Solution: Inputs are normalized and rounded to 6 decimal places before hashing, establishing strict hash reproducibility.
If queries are continuously novel (e.g. random image embeddings), the L1 hash cache becomes pure overhead. The engine dynamically tracks rolling hit-rate: if the 5-minute hit rate falls below 15%, L1 hashing is temporarily bypassed.