# google/ginger architecture

> Architecture diagram of the GitHub repository google/ginger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/ginger
- Repository: https://github.com/google/ginger

## Overview

GINGER is a C++ approximate-nearest-neighbor library for vector retrieval and graph construction. The main workflow accepts a dataset and configuration, builds a graph index (PiPNN or Vamana), optionally projects, reorders, quantizes, and compresses it, then searches the graph and returns nearest neighbors with configurable scoring and reranking. Separate capabilities include standalone approximate kNN graph construction, index persistence, and custom distance metrics. The graph follows documented usage and indexed source references; unsampled details and uncertain call paths are omitted.

Main entry points: [`ginger/searcher_builder.cc`](https://github.com/google/ginger/blob/main/ginger/searcher_builder.cc) (Searcher builder), [`ginger/searcher.cc`](https://github.com/google/ginger/blob/main/ginger/searcher.cc) (Searcher API), [`ginger/pipnn/pipnn.cc`](https://github.com/google/ginger/blob/main/ginger/pipnn/pipnn.cc) (PiPNN builder), [`ginger/graph/flat_graph.h`](https://github.com/google/ginger/blob/main/ginger/graph/flat_graph.h) (Graph representations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and datasets"]
  node_dataset[("Vector dataset<br/>[dataset.h]")]
  node_config["Recommended config"]
end

subgraph group_build["Index construction"]
  node_builder["Searcher builder"]
  node_pipnn["PiPNN builder<br/>[pipnn.cc]"]
  node_vamana["Vamana builder<br/>[index_builder.cc]"]
  node_projection["PCA projection<br/>[pca.h]"]
  node_reordering["Graph reordering"]
  node_graph[("Graph representations<br/>[flat_graph.h]")]
  node_knn["PiPNN kNN graph<br/>[pipnn_knn.cc]"]
end

subgraph group_quant["Compression and scoring"]
  node_compressed_graph[("Compressed graph<br/>[compressed_graph.h]")]
  node_codec["TurboQuant codec<br/>[codec.h]"]
  node_encoded_vectors["Encoded datapoints<br/>[encode_datapoint.h]"]
  node_soa_dataset[("Quantized dataset<br/>[dataset_soa.h]")]
  node_norms["Norm storage<br/>[norm_storage.h]"]
end

subgraph group_query["Search and retrieval"]
  node_query_encode["Query encoding<br/>[encode_query.cc]"]
  node_turbo_query["TurboQuant query<br/>[query.h]"]
  node_searcher["Searcher API<br/>[searcher.cc]"]
  node_beam["Beam search<br/>[beam_search.h]"]
  node_scoring["Distance scoring<br/>[search_functors.h]"]
  node_jl["JL candidate filter<br/>[jl.cc]"]
  node_results["Neighbor results<br/>[types.h]"]
end

subgraph group_support["Persistence and evaluation"]
  node_save_load["Index persistence<br/>[index_io.cc]"]
  node_recall["Recall evaluation<br/>[recall.cc]"]
end

node_user(("Client"))
node_knn_actor(("kNN graph client"))

node_user -->|"supplies vectors"| node_dataset
node_user -->|"requests defaults"| node_config
node_user -->|"configures build"| node_builder
node_builder -->|"builds graph"| node_pipnn
node_builder -->|"builds graph"| node_vamana
node_builder -->|"fits projection"| node_projection
node_builder -->|"reorders graph"| node_reordering
node_builder -->|"uses graph"| node_graph
node_builder -.->|"configures quantization"| node_codec
node_pipnn -->|"produces graph"| node_graph
node_vamana -->|"produces graph"| node_graph
node_builder -->|"compresses graph"| node_compressed_graph
node_codec -->|"encodes vectors"| node_encoded_vectors
node_encoded_vectors -->|"populates dataset"| node_soa_dataset
node_soa_dataset -->|"stores norms"| node_norms
node_user -->|"submits query"| node_searcher
node_searcher -->|"searches graph"| node_beam
node_searcher -->|"encodes query"| node_query_encode
node_query_encode -->|"creates query"| node_turbo_query
node_searcher -->|"scores candidates"| node_scoring
node_searcher -->|"filters candidates"| node_jl
node_searcher -.->|"traverses graph"| node_compressed_graph
node_searcher -->|"returns neighbors"| node_results
node_user -->|"saves or loads"| node_save_load
node_searcher -->|"serializes index"| node_save_load
node_user -.->|"evaluates results"| node_recall
node_knn_actor -->|"requests graph"| node_knn
node_knn -.->|"uses PiPNN"| node_pipnn

click node_dataset "https://github.com/google/ginger/blob/main/ginger/dataset.h"
click node_config "https://github.com/google/ginger/blob/main/ginger/config_recommender.cc"
click node_builder "https://github.com/google/ginger/blob/main/ginger/searcher_builder.cc"
click node_pipnn "https://github.com/google/ginger/blob/main/ginger/pipnn/pipnn.cc"
click node_vamana "https://github.com/google/ginger/blob/main/ginger/vamana/index_builder.cc"
click node_projection "https://github.com/google/ginger/blob/main/ginger/projection/pca.h"
click node_reordering "https://github.com/google/ginger/blob/main/ginger/reordering/recursive_graph_partitioning.cc"
click node_graph "https://github.com/google/ginger/blob/main/ginger/graph/flat_graph.h"
click node_compressed_graph "https://github.com/google/ginger/blob/main/ginger/graph/compressed_graph.h"
click node_codec "https://github.com/google/ginger/blob/main/ginger/turboquant/codec/codec.h"
click node_encoded_vectors "https://github.com/google/ginger/blob/main/ginger/turboquant/datapoint/encode_datapoint.h"
click node_soa_dataset "https://github.com/google/ginger/blob/main/ginger/turboquant/layout/dataset_soa.h"
click node_norms "https://github.com/google/ginger/blob/main/ginger/turboquant/layout/norm_storage.h"
click node_query_encode "https://github.com/google/ginger/blob/main/ginger/turboquant/query/encode_query.cc"
click node_turbo_query "https://github.com/google/ginger/blob/main/ginger/turboquant/query/query.h"
click node_searcher "https://github.com/google/ginger/blob/main/ginger/searcher.cc"
click node_beam "https://github.com/google/ginger/blob/main/ginger/search/beam_search.h"
click node_scoring "https://github.com/google/ginger/blob/main/ginger/search/search_functors.h"
click node_jl "https://github.com/google/ginger/blob/main/ginger/candidate_filtering/jl.cc"
click node_save_load "https://github.com/google/ginger/blob/main/ginger/io/index_io.cc"
click node_recall "https://github.com/google/ginger/blob/main/ginger/eval/recall.cc"
click node_knn "https://github.com/google/ginger/blob/main/ginger/pipnn/pipnn_knn.cc"
click node_results "https://github.com/google/ginger/blob/main/ginger/types.h"

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_dataset,node_config,node_user,node_knn_actor toneBlue
class node_builder,node_pipnn,node_vamana,node_projection,node_reordering,node_graph,node_knn toneAmber
class node_compressed_graph,node_codec,node_encoded_vectors,node_soa_dataset,node_norms toneMint
class node_query_encode,node_turbo_query,node_searcher,node_beam,node_scoring,node_jl,node_results toneRose
class node_save_load,node_recall toneIndigo
```

## Components

### API and datasets

- [Vector dataset](https://github.com/google/ginger/blob/main/ginger/dataset.h): `ginger/dataset.h`
- [Recommended config](https://github.com/google/ginger/blob/main/ginger/config_recommender.cc): `ginger/config_recommender.cc`

### Index construction

- [Searcher builder](https://github.com/google/ginger/blob/main/ginger/searcher_builder.cc): `ginger/searcher_builder.cc`
- [PiPNN builder](https://github.com/google/ginger/blob/main/ginger/pipnn/pipnn.cc): `ginger/pipnn/pipnn.cc`
- [Vamana builder](https://github.com/google/ginger/blob/main/ginger/vamana/index_builder.cc): `ginger/vamana/index_builder.cc`
- [PCA projection](https://github.com/google/ginger/blob/main/ginger/projection/pca.h): `ginger/projection/pca.h`
- [Graph reordering](https://github.com/google/ginger/blob/main/ginger/reordering/recursive_graph_partitioning.cc): `ginger/reordering/recursive_graph_partitioning.cc`
- [Graph representations](https://github.com/google/ginger/blob/main/ginger/graph/flat_graph.h): `ginger/graph/flat_graph.h`
- [PiPNN kNN graph](https://github.com/google/ginger/blob/main/ginger/pipnn/pipnn_knn.cc): `ginger/pipnn/pipnn_knn.cc`

### Compression and scoring

- [Compressed graph](https://github.com/google/ginger/blob/main/ginger/graph/compressed_graph.h): `ginger/graph/compressed_graph.h`
- [TurboQuant codec](https://github.com/google/ginger/blob/main/ginger/turboquant/codec/codec.h): `ginger/turboquant/codec/codec.h`
- [Encoded datapoints](https://github.com/google/ginger/blob/main/ginger/turboquant/datapoint/encode_datapoint.h): `ginger/turboquant/datapoint/encode_datapoint.h`
- [Quantized dataset](https://github.com/google/ginger/blob/main/ginger/turboquant/layout/dataset_soa.h): `ginger/turboquant/layout/dataset_soa.h`
- [Norm storage](https://github.com/google/ginger/blob/main/ginger/turboquant/layout/norm_storage.h): `ginger/turboquant/layout/norm_storage.h`

### Search and retrieval

- [Query encoding](https://github.com/google/ginger/blob/main/ginger/turboquant/query/encode_query.cc): `ginger/turboquant/query/encode_query.cc`
- [TurboQuant query](https://github.com/google/ginger/blob/main/ginger/turboquant/query/query.h): `ginger/turboquant/query/query.h`
- [Searcher API](https://github.com/google/ginger/blob/main/ginger/searcher.cc): `ginger/searcher.cc`
- [Beam search](https://github.com/google/ginger/blob/main/ginger/search/beam_search.h): `ginger/search/beam_search.h`
- [Distance scoring](https://github.com/google/ginger/blob/main/ginger/search/search_functors.h): `ginger/search/search_functors.h`
- [JL candidate filter](https://github.com/google/ginger/blob/main/ginger/candidate_filtering/jl.cc): `ginger/candidate_filtering/jl.cc`
- [Neighbor results](https://github.com/google/ginger/blob/main/ginger/types.h): `ginger/types.h`

### Persistence and evaluation

- [Index persistence](https://github.com/google/ginger/blob/main/ginger/io/index_io.cc): `ginger/io/index_io.cc`
- [Recall evaluation](https://github.com/google/ginger/blob/main/ginger/eval/recall.cc): `ginger/eval/recall.cc`

### Other components

- **Client**
- **kNN graph client**

## Connections

- Client → Vector dataset: supplies vectors (evidence: `README.md`)
- Client → Recommended config: requests defaults (evidence: `README.md`)
- Client → Searcher builder: configures build (evidence: `README.md`)
- Searcher builder → PiPNN builder: builds graph (evidence: `ginger/searcher_builder.cc`)
- Searcher builder → Vamana builder: builds graph (evidence: `ginger/searcher_builder.cc`)
- Searcher builder → PCA projection: fits projection (evidence: `ginger/searcher_builder.cc`)
- Searcher builder → Graph reordering: reorders graph (evidence: `ginger/searcher_builder.cc`)
- Searcher builder → Graph representations: uses graph (evidence: `ginger/searcher_builder.cc`)
- Searcher builder → TurboQuant codec: configures quantization
- PiPNN builder → Graph representations: produces graph (evidence: `ginger/pipnn/pipnn.cc`)
- Vamana builder → Graph representations: produces graph (evidence: `ginger/vamana/index_builder.cc`)
- Searcher builder → Compressed graph: compresses graph (evidence: `ginger/searcher_builder.cc`)
- TurboQuant codec → Encoded datapoints: encodes vectors (evidence: `ginger/turboquant/codec/codec.h`)
- Encoded datapoints → Quantized dataset: populates dataset (evidence: `ginger/turboquant/layout/dataset_soa.h`)
- Quantized dataset → Norm storage: stores norms (evidence: `ginger/turboquant/layout/dataset_soa.h`)
- Client → Searcher API: submits query (evidence: `README.md`)
- Searcher API → Beam search: searches graph (evidence: `ginger/searcher.cc`)
- Searcher API → Query encoding: encodes query (evidence: `ginger/searcher.cc`)
- Query encoding → TurboQuant query: creates query
- Searcher API → Distance scoring: scores candidates (evidence: `ginger/searcher.cc`)
- Searcher API → JL candidate filter: filters candidates (evidence: `ginger/searcher.cc`)
- Searcher API → Compressed graph: traverses graph
- Searcher API → Neighbor results: returns neighbors (evidence: `README.md`)
- Client → Index persistence: saves or loads (evidence: `README.md`)
- Searcher API → Index persistence: serializes index (evidence: `ginger/io/index_io.cc`)
- Client → Recall evaluation: evaluates results
- kNN graph client → PiPNN kNN graph: requests graph (evidence: `README.md`)
- PiPNN kNN graph → PiPNN builder: uses PiPNN
