How arpatnurmamat-dotcom/vectorvault works
Purpose and entry points
VectorVault is an embedded, persistent vector database: a C++17 static library with a stable C ABI, C++ wrapper, and local CLI. Applications open a single .vault file, insert/query/delete vectors with JSON metadata, and perform maintenance without a server. Public interfaces are include/vectorvault/vectorvault.h and include/vectorvault/vectorvault.hpp; the inspection/maintenance executable is tools/vv_cli.cpp.
API lifecycle and database orchestration
The database layer owns open/create, configuration validation, CRUD, synchronization, compaction, and teardown. It assembles storage, metadata, and the selected vector index behind the public API, while enforcing the documented concurrent-read / serialized-write model. Core paths: src/core/database.cpp, src/core/database.h, src/core/config.cpp.
Query execution boundary
Search requests flow through a query executor, which coordinates approximate or exact nearest-neighbor retrieval with optional metadata-filter evaluation and result handling. This is the boundary between caller-facing KNN semantics and index/storage internals. Paths: src/query/executor.cpp, src/query/executor.h, src/meta/filter.cpp.
Vector indexing and distance runtime dispatch
VectorIndex abstracts index implementations. HNSW is the primary incremental approximate index; Flat provides brute-force/exact search. HNSW persistence is separated into index I/O. Distance computation supports cosine, L2, and inner product, with platform-specific AVX2, SSE, and NEON implementations selected by runtime/platform support. Paths: src/index/vector_index.h, src/index/hnsw.cpp, src/index/flat.cpp; SIMD paths: src/index/distance.cpp, src/index/distance_avx2.cpp, src/index/distance_neon.cpp.
Metadata and filtering
Metadata is stored as JSON associated with vector IDs. A B-tree supplies ID-oriented metadata lookup and range-oriented access; the filter subsystem parses/evaluates expression predicates such as comparisons, boolean operators, and grouping against metadata. Paths: src/meta/btree.cpp, src/meta/btree.h, src/meta/filter.h.
Persistent storage engine
The single-file persistence layer is page-based (README specifies 4 KB pages). PageManager defines page allocation/layout and coordinates durable storage; BufferPool caches pages with LRU behavior; FreeList recovers reusable space after deletes/compaction. File I/O handles low-level reads/writes and WAL-related durability/recovery behavior. Paths: src/storage/page_manager.cpp, src/storage/buffer_pool.cpp, src/storage/free_list.cpp, src/storage/file_io.cpp.
End-to-end flows and infrastructure
On open, database/configuration initialization opens or creates the vault, recovers durable state as needed, initializes page-backed metadata/vector state, and restores the persisted HNSW graph. Insert writes vector/metadata records through storage, updates metadata and index structures, and records durable changes. Search executes index candidate retrieval, evaluates an optional filter, and returns nearest accepted results. Delete tombstones data; compaction reclaims space and rebuilds indexes. The only material runtime dependencies are C++/C system facilities—threading, filesystem/file descriptors, CPU-feature/platform support—with no network service or third-party dependency. Build integration is defined by CMakeLists.txt.
Components 18
Public interfaces
- Stable C ABI
include/vectorvault/vectorvault.h - C++ wrapper
include/vectorvault/vectorvault.hpp - vv CLI
tools/vv_cli.cpp
Database core
- Database · Owns vault lifecycle, CRUD, synchronization, and compaction.
src/core/database.cpp - Configuration
src/core/config.cpp
Query and metadata
- Query executor
src/query/executor.cpp - Metadata filters
src/meta/filter.cpp - Metadata B-tree · Provides ID lookup and range-oriented metadata access.
src/meta/btree.cpp
Vector indexing
- VectorIndex
src/index/vector_index.h - HNSW index · Primary incremental index with persisted graph state.
src/index/hnsw.cpp - Flat index
src/index/flat.cpp - Distance dispatch · Selects cosine, L2, or inner-product kernels by platform support.
src/index/distance.cpp - AVX2 distance
src/index/distance_avx2.cpp - NEON distance
src/index/distance_neon.cpp
Persistent storage
- Page manager · Manages 4 KB page allocation, layout, and durable state.
src/storage/page_manager.cpp - Buffer pool
src/storage/buffer_pool.cpp - Free list
src/storage/free_list.cpp - File I/O and recovery · Performs vault reads/writes and WAL-related recovery.
src/storage/file_io.cpp
Connections 23
- Stable C ABI → Database: opens and operates vaults
- C++ wrapper → Stable C ABI: wraps
- vv CLI → Database: inspects and maintains
- Database → Configuration: validates configuration
- Database → Query executor: executes searches
- Database → VectorIndex: selects and updates
- Database → Metadata B-tree: stores metadata
- Database → Page manager: opens, persists, compacts
- Query executor → VectorIndex: retrieves candidates
- Query executor → Metadata filters: evaluates optional predicates
- Metadata filters → Metadata B-tree: reads metadata
- VectorIndex → HNSW index: approximate implementation
- VectorIndex → Flat index: exact implementation
- HNSW index → Distance dispatch: computes distances
- Flat index → Distance dispatch: computes distances
- Distance dispatch → AVX2 distance: runtime-selected
- Distance dispatch → NEON distance: runtime-selected
- Metadata B-tree → Page manager: page-backed records
- HNSW index → Page manager: restores and persists graph
- Page manager → Buffer pool: caches pages
- Page manager → Free list: allocates reclaimed space
- Page manager → File I/O and recovery: reads and writes vault pages
- File I/O and recovery → Page manager: recovery state