Expand description
CSR graph mmap cache (format v1).
The file .brain/graph.mmap is compiled from SQLite by CsrCompiler and
read by CsrMmapGraph. It enables fast neighborhood expansion for agent
context without re-querying SQLite for every hop.
Full layout: repository docs/MMAP_FORMAT.md.
§Design notes
- All multi-byte integers are little-endian.
- Sections are size-validated before any access.
- Neighbor/vector accessors use explicit
from_le_bytesloads (no unalignedfrom_raw_partscasts) — correct on all platforms and free of UB under mmap base-alignment variance. - Publish path is write temp +
renamefor crash safety.
Structs§
- CsrCompiler
- Compiler that bakes nodes, edges, and optional vectors into
graph.mmap. - CsrMmap
Graph - Memory-mapped CSR graph reader with safe unaligned loads.
Constants§
- FLAG_
HAS_ IDS - Flag bit: id string table is present after the vector matrix.
- HEADER_
SIZE - Header size in bytes.
- MAGIC_
BYTES - Magic bytes:
RBRNMAP1 - MMAP_
VERSION - On-disk format version for
graph.mmap.