# kioxia-jp/aisaq-diskann architecture

> Architecture diagram of the GitHub repository kioxia-jp/aisaq-diskann, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kioxia-jp/aisaq-diskann
- Repository: https://github.com/kioxia-jp/aisaq-diskann

## Overview

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: [`src/index.cpp`](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/index.cpp) (Search engine), [`src/pq_flash_index.cpp`](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/pq_flash_index.cpp) (Disk index), [`CMakeLists.txt`](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/CMakeLists.txt) (Build & CI), [`apps/utils`](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/utils) (Prep tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cpp_core["C++ core"]
  node_cpp_interfaces["Core APIs<br/>abstract interfaces<br/>[abstract_index.h]"]
  node_cpp_search["Search engine<br/>ANN search<br/>[index.cpp]"]
  node_cpp_memory[("In-memory index<br/>DRAM index")]
  node_cpp_disk[("Disk index<br/>SSD index<br/>[pq_flash_index.cpp]")]
  node_cpp_aisaq["AiSAQ layer<br/>disk/PQ variant<br/>[aisaq.h]"]
  node_cpp_pq["PQ layer<br/>quantization<br/>[pq.cpp]"]
  node_cpp_storage["Storage I/O<br/>file & mmap"]
  node_cpp_runtime["Runtime utils<br/>common runtime<br/>[utils.cpp]"]
end

subgraph group_cpp_entry["C++ entrypoints"]
  node_cpp_cli["CLI tools<br/>build/search apps"]
  node_restapi["REST API<br/>service layer"]
end

subgraph group_python_pkg["Python package"]
  node_python_ext["Python ext<br/>native module<br/>[module.cpp]"]
  node_python_wrappers["Python wrappers<br/>index API<br/>[builder.h]"]
end

subgraph group_rust_stack["Rust workspace"]
  node_rust_core["Rust core<br/>ANN library<br/>[lib.rs]"]
  node_rust_drivers["Rust drivers<br/>cli tools"]
  node_rust_support["Rust support<br/>shared crates<br/>[lib.rs]"]
end

subgraph group_tooling["Tooling"]
  node_datasets["Datasets<br/>vector data"]
  node_preprocess["Prep tools<br/>data prep"]
  node_build_tooling["Build & CI<br/>tooling<br/>[CMakeLists.txt]"]
end

node_datasets -->|"prepare"| node_preprocess
node_preprocess -->|"feed"| node_cpp_cli
node_preprocess -->|"feed"| node_rust_drivers
node_cpp_interfaces -->|"define"| node_cpp_search
node_cpp_search -->|"runs on"| node_cpp_memory
node_cpp_search -->|"runs on"| node_cpp_disk
node_cpp_disk -->|"extends"| node_cpp_aisaq
node_cpp_search -->|"uses"| node_cpp_pq
node_cpp_disk -->|"reads via"| node_cpp_storage
node_cpp_memory -->|"uses"| node_cpp_runtime
node_cpp_disk -->|"uses"| node_cpp_runtime
node_cpp_cli -->|"invokes"| node_cpp_search
node_restapi -->|"wraps"| node_cpp_search
node_python_ext -->|"binds"| node_cpp_search
node_python_wrappers -->|"layers on"| node_python_ext
node_rust_core -->|"depends on"| node_rust_support
node_rust_drivers -->|"invokes"| node_rust_core
node_build_tooling -.->|"builds"| node_cpp_cli
node_build_tooling -.->|"packages"| node_python_ext
node_build_tooling -.->|"builds"| node_rust_core

click node_datasets "https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/utils"
click node_preprocess "https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/utils"
click node_cpp_interfaces "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/abstract_index.h"
click node_cpp_search "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/index.cpp"
click node_cpp_memory "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/in_mem_graph_store.cpp"
click node_cpp_disk "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/pq_flash_index.cpp"
click node_cpp_aisaq "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/aisaq.h"
click node_cpp_pq "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/pq.cpp"
click node_cpp_storage "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/aligned_file_reader.h"
click node_cpp_runtime "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/utils.cpp"
click node_cpp_cli "https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps"
click node_restapi "https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/restapi"
click node_python_ext "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/python/src/module.cpp"
click node_python_wrappers "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/python/include/builder.h"
click node_rust_core "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/rust/diskann/src/lib.rs"
click node_rust_drivers "https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/rust/cmd_drivers"
click node_rust_support "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/rust/vector/src/lib.rs"
click node_build_tooling "https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/CMakeLists.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cpp_interfaces,node_cpp_search,node_cpp_memory,node_cpp_disk,node_cpp_aisaq,node_cpp_pq,node_cpp_storage,node_cpp_runtime toneBlue
class node_cpp_cli,node_restapi toneAmber
class node_python_ext,node_python_wrappers toneMint
class node_rust_core,node_rust_drivers,node_rust_support toneRose
class node_datasets,node_preprocess,node_build_tooling toneIndigo
```

## Components

### C++ core

Native ANN engine, abstractions, storage, and core runtime

- [Core APIs](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/abstract_index.h): abstract interfaces · Abstract index, graph store, data store, and scratch interfaces · `include/abstract_index.h`
- [Search engine](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/index.cpp): ANN search · Graph traversal, distance evaluation, filtering, and query orchestration · `src/index.cpp`
- [In-memory index](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/in_mem_graph_store.cpp): DRAM index · Memory-resident graph search and dynamic update path · `src/in_mem_graph_store.cpp`
- [Disk index](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/pq_flash_index.cpp): SSD index · Disk-backed graph traversal with on-demand vector and PQ reads · `src/pq_flash_index.cpp`
- [AiSAQ layer](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/aisaq.h): disk/PQ variant · Inline PQ vectors, multiple entry points, rearrangement, and PQ caches · `include/aisaq.h`
- [PQ layer](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/pq.cpp): quantization · Product quantization tables, compressed vectors, and PQ distance support · `src/pq.cpp`
- [Storage I/O](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/include/aligned_file_reader.h): file & mmap · Aligned readers, mmap, cached I/O, and platform-specific SSD access · `include/aligned_file_reader.h`
- [Runtime utils](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/src/utils.cpp): common runtime · Logging, timers, exceptions, math, partitioning, and utility helpers · `src/utils.cpp`

### C++ entrypoints

Command-line tools and REST service wrappers

- [CLI tools](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps): build/search apps · C++ executables for building indexes, searching, range search, streaming, and diagnostics · `apps`
- [REST API](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/restapi): service layer · HTTP-style server/client wrappers over memory, SSD, and multi-SSD search · `apps/restapi`

### Python package

Typed extension module and helper scripts

- [Python ext](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/python/src/module.cpp): native module · diskannpy extension module and low-level bindings · `python/src/module.cpp`
- [Python wrappers](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/python/include/builder.h): index API · 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](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/rust/diskann/src/lib.rs): ANN library · Parallel Rust implementation of algorithms, models, storage, and scratch state · `rust/diskann/src/lib.rs`
- [Rust drivers](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/rust/cmd_drivers): cli tools · Standalone build, insert, search, and conversion utilities · `rust/cmd_drivers`
- [Rust support](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/rust/vector/src/lib.rs): shared crates · Vector math, platform I/O, logging, and base utilities · `rust/vector/src/lib.rs`

### Tooling

Build, workflow, and data-prep utilities

- [Datasets](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/utils): vector data · Raw binary/vector inputs and prepared evaluation data · `apps/utils`
- [Prep tools](https://github.com/kioxia-jp/aisaq-diskann/tree/aisaq_release/apps/utils): data prep · Format conversion, partitioning, PQ generation, labels, and ground-truth utilities · `apps/utils`
- [Build & CI](https://github.com/kioxia-jp/aisaq-diskann/blob/aisaq_release/CMakeLists.txt): tooling · CMake, Cargo, Python packaging, workflows, and release automation · `CMakeLists.txt`

## Connections

- 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
