#547·turbovec

IdMapIndex persist-and-reconstruct 'parts' API (accessors + from_id_map_parts)

Author: gburdCreated Sep 26, 2026Updated Sep 26, 2026

Feature request: a persist-and-reconstruct "parts" API on IdMapIndex — five read accessors plus a from_id_map_parts constructor.

Context: a storage-backed consumer needs to (a) read the minimal set of arrays that fully determine an index out of a live IdMapIndex, persist them, and (b) reconstruct the index from exactly those arrays at open-time — without re-embedding or re-quantizing. In 1.0.0 the codebook and rotation are deterministic functions of (bit_width, dim), so the only things that must be persisted are the row-major packed codes, the per-vector scales, the slot→id table, and the TQ+ calibration arrays; everything else prepare() rebuilds. That is the whole basis of an out-of-core / relation-backed store (pg_turbovec persists exactly these into PostgreSQL relation forks).

Proposed surface (this is the widest of my three requests, so it's the one most worth designing together rather than me presenting a fait accompli):

  • packed_codes() -> &[u8], scales() -> &[f32], slot_to_id() -> &[u64], tqplus_shift() -> &[f32], tqplus_scale() -> &[f32] — borrow the persistable arrays.
  • from_id_map_parts(dim, bit_width, n_vectors, packed_codes, scales, slot_to_id, tqplus_shift, tqplus_scale) -> Result<IdMapIndex> — rebuild from them (TQ+ arrays may be empty = identity/uncalibrated).

The bikeshed surface I'd want your call on (all real, none I'm attached to):

  1. Positional 8-arg constructor vs. a Parts struct (IdMapIndex::from_parts(Parts { .. })). A struct is more future-proof if the persistable set ever grows.
  2. Five separate accessors vs. one parts(&self) -> PartsRef<'_> borrow.
  3. The from_parts/from_id_map_parts naming vs. the existing from_parts on TurboQuantIndex (#204/#210) — should these be unified or clearly distinct?
  4. Error type on the constructor (validation of id_to_slot.len() == slot_to_id.len() etc.).

You put a soft "maybe a fork concern" on the read/write side of #70 — I think the accessors are genuinely general (any persistence layer needs them), but I'd rather agree the shape here than push a design. If you'd prefer this stay downstream, that's a legitimate answer and I'll keep it as a fork carry.

Per CONTRIBUTING, issue-first. I have a working implementation matching the positional form; happy to reshape it to whatever you land on and open the PR if invited.