This document is the language-neutral compatibility contract for prolly-map
ports. The Rust implementation remains the reference; the checked-in
conformance fixtures are generated from Rust.
- Keys, values, node bytes, and store keys are byte strings.
- Fixture JSON encodes byte strings as lowercase hex.
- A node CID is
SHA-256(node_bytes). - Stores persist nodes under the raw 32-byte CID and store the exact serialized node bytes as the value.
New nodes are encoded in a deterministic compact binary format:
- magic bytes: ASCII
CRAB - unsigned LEB128 varint version, currently
1 - unsigned LEB128 leaf flag:
1for leaf,0for internal - unsigned LEB128 level, where leaves are level
0 - unsigned LEB128
min_chunk_size - unsigned LEB128
max_chunk_size - unsigned LEB128
chunking_factor - unsigned LEB128
hash_seed - encoding tag:
0raw,1CBOR,2JSON,3custom - for custom encoding, unsigned LEB128 UTF-8 name length plus name bytes
- unsigned LEB128 entry count
- entries in sorted key order
Each entry stores the key as a prefix-compressed delta from the previous key:
- unsigned LEB128 shared prefix length
- unsigned LEB128 suffix length
- suffix bytes
Leaf values are varint length + value bytes.
Internal values are child pointers:
- tag
0plus 32 CID bytes when the value length is exactly 32 bytes - tag
1plusvarint length + bytesfor non-CID legacy/internal payloads
Decoders may read legacy CBOR node bytes for old stores. Writers must write
CRAB version 1.
- Raw byte keys are ordered lexicographically.
- Internal node keys are the first key of each child.
- Lookup in an internal node descends to the exact matching separator if found; otherwise it descends to the previous separator. If the insertion point is zero, the key is absent.
- Empty trees have no root CID.
- Tree snapshots are immutable; writes return a new root.
- Delete and an empty byte value are distinct states.
The chunk boundary predicate is:
- if current chunk entry count is below
min_chunk_size, no boundary - if count is at or above
max_chunk_size, boundary - otherwise compute xxHash64 with
hash_seedoverkey || value - take the lower 32 bits and compare
<= floor(u32::MAX / chunking_factor)
Ports must match the Rust xxHash64 result exactly for writer compatibility.
u64,u128, and timestamp keys use big-endian unsigned bytes.i64andi128flip the sign bit before big-endian encoding.- Composite segments escape
0x00as00 ffand terminate each segment with00 00. - Prefix ranges are half-open:
[prefix, prefix_end(prefix)); an empty or allffprefix has no exclusive upper bound.
VersionedValue bytes:
- magic
PLVV - one-byte wire version
1 - one-byte encoding tag using the node encoding tags
- big-endian
u64schema version - big-endian
u32schema length - big-endian
u32custom encoding name length - big-endian
u64payload length - schema UTF-8 bytes
- custom encoding UTF-8 bytes
- payload bytes
ValueRef bytes:
- magic
PLVB - one-byte version
1 - one-byte kind:
0inline,1blob - inline: big-endian
u64length plus value bytes - blob: 32-byte blob CID plus big-endian
u64blob length
Non-PLVB stored values are interpreted as inline bytes by large-value helpers.
RootManifest is packed CBOR containing version 1, optional root CID,
Config, and optional Unix millisecond timestamps. Ports that implement named
roots must decode the conformance manifest fixture and preserve CAS semantics.
The current format is a hard cutoff. Legacy proximity objects are rejected with
UnsupportedProximityVersion; no decoder guesses or upgrades legacy bytes.
Ordered CRAB version 1 nodes are unchanged.
All proximity integers use canonical unsigned LEB128 unless explicitly fixed width. CIDs are 32 raw SHA-256 bytes. Floating-point words are canonical finite little-endian IEEE-754; negative zero becomes positive zero. Every decoder rejects truncation, non-canonical lengths, allocation overflow, unknown flags, bad ordering/counts/references, unsupported encodings, and trailing bytes.
| Magic | Object | Committed content |
|---|---|---|
PRVR |
exact record | current format, f32-le tag, dimension count, vector, opaque value |
PRXI |
descriptor | metric/normalization, dimensions/count, hierarchy, overflow, vector/SQ8 config, complete ordered tree, PRXN root, radius policy, config fingerprint |
PRXN |
physical hierarchy node | kind/level, subtree summary, optional PQS8 CID, sorted entries, child/key bounds/radii/vector references |
PRXV |
external vector | current vector encoding and components |
PQS8 |
local scalar quantizer | dimensions/grouping/count, scales, signed codes, maximum error |
PQPQ |
product-quantization manifest | source PRXI, metric/config, code-tree root, codebooks, quality |
TQTQ |
TurboQuant-MSE manifest | source PRXI, dimension/metric/count, bit width/rerank/seed, frozen transform and codebook IDs, code-tree root, routing reconstruction quality, zero-vector count, configuration fingerprint |
HNSW |
HNSW manifest | source PRXI, metric/config/fingerprint, graph root, entry point, level, canonical flag |
HNSN |
HNSW graph value | level and key-sorted neighbors by layer |
CRMF |
typed content-root manifest | typed CID, optional PRXN dimensions, logical version/time, sorted metadata |
PRXN physical kinds distinguish ordinary leaves/routes from overflow pages and recursive overflow directories. Inline/external vectors and quantizer/child CIDs use explicit tags. The descriptor commits Euclidean-radius rounding and metric normalization policies, preventing a reader from interpreting bounds under different math.
TurboQuant code-tree values contain one canonical finite nonnegative f64-le
norm followed by exactly ceil(dimensions * bit_width / 8) bytes of packed
little-endian centroid indices. Supported dimensions are divisible by eight,
so persisted production codes have no unused tail bits; the decoder still
rejects nonzero padding in bounded codec tests. A zero norm requires positive
zero and all-zero codes.
Search policies, budgets, async settings, query kernels, transform-plan caches,
and worker counts are runtime only. PQ, TurboQuant, and HNSW have independent
manifests because they are rebuildable source-bound accelerators. Frozen exact
bytes and CIDs are maintained in conformance/proximity-fixtures.json; legacy
canonical fixtures are test-only rejection inputs.