How kioxia-jp/aisaq-diskann works
1. Project shape
This repo is a multi-language ANN search system centered on DiskANN/AiSAQ. The primary production code is the C++ library and command-line tools; there is also a Rust implementation/workspace and a Python extension package built on top of the core search primitives.
2. Core architecture: ANN engine
The C++ core is organized around a small set of interfaces in include/ and concrete implementations in src/:
- abstract index / graph / data-store / scratch interfaces
- in-memory and disk-backed index variants
- product-quantization support
- common utilities, logging, timing, filtering, and exceptions
This separation is the main architectural boundary: search algorithms operate over abstract index/data-store/scratch types, while storage and runtime choices are swapped underneath.
3. Index types and storage modes
The repo supports two main execution/storage models:
- In-memory indexes for DRAM-resident graph search and dynamic updates
- Disk/SSD indexes where graph traversal is coupled with on-demand vector/PQ reads from storage
AiSAQ extends the disk mode with inline PQ vectors, multiple entry points, vector rearrangement, and static/dynamic PQ caches to reduce I/O.
4. Build-time pipeline
Index creation is a distinct stage from query serving. Build apps under apps/ and rust/cmd_drivers/ ingest raw vector datasets, partition or rearrange them, compute PQ codes, and emit on-disk or in-memory index artifacts. Supporting utilities convert dataset formats, compute ground truth, generate labels, and estimate recall/performance.
5. Query-time pipeline
Search follows a graph traversal pattern with per-query scratch state:
- load or map the index
- initialize query scratch/work queues
- perform greedy graph expansion and PQ-based distance evaluation
- optionally apply filters/labels
- return nearest-neighbor results
The query path is optimized differently for memory and SSD indexes, but both rely on the same search concepts and shared distance/PQ code.
6. SSD-specific runtime boundaries
Disk search uses explicit I/O abstractions such as aligned file readers, memory mapping, cached I/O, and Linux async I/O via liburing for PQ reads. This is a major architectural boundary: graph navigation is CPU-side, while candidate vector/PQ retrieval is storage-side and carefully batched/cached. The disk implementation also carries platform-specific support for Windows aligned I/O.
7. Executable entry points
The main C++ command-line programs under apps/ cover:
- build memory index
- build disk index
- search memory index
- search disk index
- range search
- stitched/multi-shard and streaming/dynamic scenarios
- testing/benchmark helpers
These are the primary user-facing entry points for offline build and online search workflows.
8. REST API service
apps/restapi and src/restapi provide a server/client layer that wraps the search engine behind HTTP-style service endpoints. There are separate server variants for in-memory, SSD, and multi-SSD configurations, which suggests the API layer is a thin orchestration boundary over the same index/search core.
9. Python package
The python/ tree is a packaged extension module (diskannpy) with typed wrappers, builder helpers, and higher-level Python classes for static memory, static disk, and dynamic memory indexes. It exposes the native index lifecycle to Python users while keeping the heavy ANN logic in native code.
10. Rust workspace
The rust/ tree is a parallel Rust implementation and ecosystem:
- rust/diskann contains the algorithm, model, storage, instrumentation, and tests
- rust/cmd_drivers contains standalone build/search utilities
- rust/vector, rust/platform, and rust/logger provide shared support crates
This is useful for benchmarking, alternate implementations, and lower-level experimentation, but it is architecturally separate from the C++/Python path.
11. Data and file artifacts
The system is file-centric. Inputs are typically binary vector datasets; outputs are index files containing graph structure, compressed/PQ data, and metadata. Tests and sample data under rust/diskann/tests/data and python/tests/fixtures show that index artifacts are first-class deployable outputs, not just in-memory objects.
12. Operational and build tooling
The repo is built with CMake for C++, Cargo for Rust, and pyproject.toml/setup.py for Python packaging. CI workflows cover formatting, unit tests, build matrices, Python wheels, performance runs, and release automation. External dependencies that materially affect architecture are libaio/liburing, MKL/BLAS-style math libraries, Boost, and gperftools/tcmalloc for performance.
13. Where to draw the architecture diagram
A good diagram should show:
- datasets and preprocessing utilities feeding index builders
- builders producing disk or in-memory index artifacts
- query clients reaching either native CLI tools, REST servers, or Python bindings
- the core ANN engine in the middle
- separate storage/I/O layers for memory vs SSD
- optional label/filter support as a side input into search
- the Rust implementation as a parallel subsystem, not as a dependency of the C++ runtime
Main entry points: index.cpp Search engine · pq_flash_index.cpp Disk index · CMakeLists.txt Build & CI · utils Prep tools
Components 18
C++ core
Native ANN engine, abstractions, storage, and core runtime
- Core APIs · Abstract index, graph store, data store, and scratch interfaces
include/abstract_index.h - Search engine · Graph traversal, distance evaluation, filtering, and query orchestration
src/index.cpp - In-memory index · Memory-resident graph search and dynamic update path
src/in_mem_graph_store.cpp - Disk index · Disk-backed graph traversal with on-demand vector and PQ reads
src/pq_flash_index.cpp - AiSAQ layer · Inline PQ vectors, multiple entry points, rearrangement, and PQ caches
include/aisaq.h - PQ layer · Product quantization tables, compressed vectors, and PQ distance support
src/pq.cpp - Storage I/O · Aligned readers, mmap, cached I/O, and platform-specific SSD access
include/aligned_file_reader.h - Runtime utils · Logging, timers, exceptions, math, partitioning, and utility helpers
src/utils.cpp
C++ entrypoints
Command-line tools and REST service wrappers
Python package
Typed extension module and helper scripts
- Python ext · diskannpy extension module and low-level bindings
python/src/module.cpp - Python wrappers · Builder helpers and static/dynamic memory and disk index classes
python/include/builder.h
Rust workspace
Parallel Rust implementation, drivers, and support crates
- Rust core · Parallel Rust implementation of algorithms, models, storage, and scratch state
rust/diskann/src/lib.rs - Rust drivers · Standalone build, insert, search, and conversion utilities
rust/cmd_drivers - Rust support · Vector math, platform I/O, logging, and base utilities
rust/vector/src/lib.rs
Tooling
Build, workflow, and data-prep utilities
- Datasets · Raw binary/vector inputs and prepared evaluation data
apps/utils - Prep tools · Format conversion, partitioning, PQ generation, labels, and ground-truth utilities
apps/utils - Build & CI · CMake, Cargo, Python packaging, workflows, and release automation
CMakeLists.txt
Connections 20
- Datasets → Prep tools: prepare · Raw datasets are converted, partitioned, labeled, and ground-truthed
- Prep tools → CLI tools: feed · Prepared data drives index construction and evaluation workflows
- Prep tools → Rust drivers: feed · Rust command drivers use the same file-centric data pipeline
- Core APIs → Search engine: define · Search operates over abstract index, graph, data-store, and scratch contracts
- Search engine → In-memory index: runs on · DRAM search uses in-memory graph and data stores
- Search engine → Disk index: runs on · SSD search uses disk-backed graph and vector retrieval
- Disk index → AiSAQ layer: extends · AiSAQ specializes the disk path with inline PQ and caching
- Search engine → PQ layer: uses · Distance evaluation relies on shared product-quantization primitives
- Disk index → Storage I/O: reads via · Disk traversal depends on aligned reads, mmap, and cached I/O
- In-memory index → Runtime utils: uses · Shared runtime utilities support memory-index execution
- Disk index → Runtime utils: uses · Shared runtime utilities support SSD execution and logging
- CLI tools → Search engine: invokes · CLI binaries orchestrate build and query flows over the core engine
- REST API → Search engine: wraps · REST endpoints delegate to the same native search core
- Python ext → Search engine: binds · Python extension exposes native build and search primitives
- Python wrappers → Python ext: layers on · Typed Python classes and builders sit above the extension module
- Rust core → Rust support: depends on · Rust ANN code shares vector, platform, and logging crates
- Rust drivers → Rust core: invokes · Rust command-line tools drive build and search operations
- Build & CI → CLI tools: builds · CMake and workflows build the native executables
- Build & CI → Python ext: packages · Python packaging and CI produce extension wheels
- Build & CI → Rust core: builds · Cargo workspace builds the Rust implementation and drivers