Rust · HNSW · hybrid retrieval

Embedded vector database in Rust: HNSW, SQL, and hybrid search

An embedded vector database runs beside application code rather than behind a separately operated service. The useful question is not only how fast ANN runs, but whether vectors, filters, writes, security, and recovery share one consistent data model.

Short answer: embedded vector storage is a strong fit for desktop, edge, local-first, agent-memory, and single-node RAG workloads. Choose a service when independent scaling, multi-region availability, or many remote writers matter more than deployment simplicity.

What makes a vector database embedded?

The engine opens local storage from the application process and vector queries avoid a network round trip. That removes a service, credentials, health checks, and synchronization between operational rows and embeddings. It also means the application owns memory, CPU contention, upgrades, exclusive file access, and backup coordination.

A useful embedded engine should persist source data and embeddings atomically. Otherwise “local” still leaves two stores whose versions can drift.

Selection criteria beyond ANN speed

QuestionWhy it matters
Are vectors transactional with source rows?Prevents search from returning an embedding for a deleted or uncommitted record.
Can metadata filters execute before decoding?Tenant, status, category, and time filters should reduce ANN work and unauthorized candidates.
Which ANN representation is stored?Dense, binary, and product-quantized vectors trade memory for recall and reranking quality.
Is exact reranking available?Approximate candidates can be reordered against stored full-precision vectors when correctness needs it.
How does recovery work?Indexes must reopen, rebuild, or recover consistently after a crash.
Can ordinary SQL and text search combine with ANN?Real retrieval rarely stops at nearest neighbors.

MongrelDB's embedded vector path

MongrelDB is written in Rust and stores operational rows, embeddings, and secondary indexes under one WAL and MVCC model. ANN supports HNSW with dense or binary-sign vectors, plus DiskANN and IVF dense paths. Product quantization is available as a flat PQ backend; its current hnsw selector is compatibility metadata, not an HNSW graph.

Every index family returns RowIds. A query can intersect vector candidates with Bitmap equality, learned numeric ranges, or FM substring constraints before row decoding. Named ANN, sparse, and MinHash retrievers can also fuse through reciprocal-rank fusion, followed by optional exact-vector reranking over a bounded candidate window.

Condition::Ann {
    column_id: 6,
    query: vec![0.10, 0.45, 0.78, 0.23],
    k: 10,
}

The query vector must match the embedding dimension. ANN is approximate; tests and production monitoring should compare a sample against brute-force results rather than treating one recall number as universal.

Hybrid retrieval without a second search service

Dense similarity catches semantic neighbors. Sparse vectors preserve rare terms and learned lexical signals. Exact substring constraints catch literal fragments. Equality and range indexes enforce metadata boundaries. Combining those signals is often more useful than making the ANN graph marginally faster.

MongrelDB exposes scored SQL table functions including ann_search_scored, sparse_search_scored, and hybrid_search_scored. Remote ranked queries use bounded scored functions rather than unrestricted Boolean ANN predicates, keeping deadlines and work ceilings explicit.

Read benchmark numbers correctly

The published MongrelDB measurements are local release-build engineering results, not cross-machine guarantees. On the documented Intel Core Ultra 9 386H system, a single accepted put without fsync measured 4.4828 microseconds and a durable commit measured 4.6721 milliseconds. Those figures describe the surrounding operational write path, not ANN throughput.

Benchmark rule: test your embedding dimensions, corpus distribution, filter selectivity, write rate, recall target, and memory ceiling. ANN numbers without those inputs are not portable.

When to embed—and when not to

Embed when

  • data should remain local or work offline;
  • one application or daemon owns the storage root;
  • operational writes and retrieval must commit together;
  • shipping one product is simpler than operating another service.

Use a vector service when

  • the index must scale independently across many machines;
  • many remote applications need concurrent service ownership;
  • managed failover and global replication are hard requirements;
  • the vector workload alone justifies a dedicated operations team.
Free vector inspection

MongrelDB Viewer

Inspect embedding columns and ANN indexes, install or rebuild Direct-mode ANN, run semantic searches, and expose tools over MCP.

Broader operations

Mongrel by VisorCraft

Manage MongrelDB with 30+ other database engines, terminals, remote files, Docker, Podman, Kubernetes, and API clients.

Sources and reproducibility