Skip to main content

Module mmap

Module mmap 

Source
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_bytes loads (no unaligned from_raw_parts casts) — correct on all platforms and free of UB under mmap base-alignment variance.
  • Publish path is write temp + rename for crash safety.

Structs§

CsrCompiler
Compiler that bakes nodes, edges, and optional vectors into graph.mmap.
CsrMmapGraph
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.