Skip to main content
HexxlaDB uses a hexagonal coordinate grid where every data cell lives at a specific coordinate. This spatial addressing enables deterministic ring walks, efficient neighborhood queries, and physical locality in the on-disk format.

Axial coordinates

Cells are addressed by axial coordinates (q, r) with implicit cube coordinate s = -q - r:
Key properties:
  • Each cell has exactly six symmetric neighbors
  • Ring walks and radius-bounded expansion are deterministic
  • Distance between cells is exact and computable

Hex distance formula

The distance between two cells is derived from cube Manhattan distance:
This returns the exact number of steps between any two cells and defines ring boundaries precisely.

Coordinate methods

The Coord type provides several utility methods:

Morton packing

For storage, coordinates are Morton-encoded into a 128-bit PackedCoord:
Why Morton encoding?
  • Preserves spatial locality in the B+ tree
  • Nearby coordinates have nearby keys
  • Ring walks become efficient prefix scans
  • Scales with ring area, not database size

Ring walks

A ring walk visits all cells at a fixed distance from a center:
Ring walks are deterministic:
  • Same order every time
  • Axial spiral order within each ring starting from positive-q direction
  • Stable across database size

Ring walks with validity filtering

For time-travel queries, filter by validity window:

Context loading

Load a neighborhood around a center coordinate:
LoadContext returns cells in concentric rings from center outward, then axial spiral order within each ring.

Coordinate selection strategies

Choosing where to place cells is application-specific:

Semantic clustering

Place semantically related content near each other:
  • Architecture decisions in one region
  • Bug reports in another
  • User preferences in a third

Temporal clustering

Place temporally related content together:
  • Session-based regions
  • Time-based rings

Random placement

For simple use cases, random coordinates work fine:
  • Ring walks still provide locality
  • HNSW embedding search finds relevant content

Hybrid approaches

Combine strategies:
  • Use embeddings for semantic search
  • Use ring walks for context assembly
  • Use edges for explicit relationships

Coordinate arithmetic

Why hexagonal?

A hexagonal lattice provides:
  • 6-neighbor connectivity — Natural for neighborhood queries
  • Natural ring enumeration — Easy to define concentric rings
  • Exact deterministic distance — No floating-point ambiguity
  • Hierarchical clustering — Super-hex regions for multi-level summarization
These properties make locality, neighborhood traversal, and summarization first-class and efficient.

See also