Skip to main content

UrnaFileBuilder

Struct UrnaFileBuilder 

Source
pub struct UrnaFileBuilder { /* private fields */ }
Expand description

High-level builder. Accepts canonical chunks plus an optional provenance blob. Computes chunk_ids, lays out the file, writes deterministic bytes.

Implementations§

Source§

impl UrnaFileBuilder

Source

pub fn build_bytes(self) -> Result<Vec<u8>>

Build the file in memory. Pure computation — no I/O.

Source§

impl UrnaFileBuilder

Source

pub fn new(manifest: Manifest) -> Self

Source

pub fn add_chunk(self, c: ChunkInput) -> Self

Source

pub fn add_chunks<I: IntoIterator<Item = ChunkInput>>(self, chunks: I) -> Self

Source

pub fn with_provenance(self, v: Value) -> Self

Source

pub fn reproducible(self, on: bool) -> Self

Reproducible build mode. When enabled, the writer overrides the manifest’s created timestamp to REPRODUCIBLE_CREATED so that two builds with identical inputs produce byte-identical output. Provenance JSON is not rewritten — callers are responsible for keeping provenance deterministic if they want bit-for-bit equality.

Source

pub fn text_encoding(self, enc: SectionEncoding) -> Self

Encoding for text-heavy sections (chunks_canonical, original_spans, provenance, search_contract). Zstd shrinks PT-BR text by ~3-5× in practice. chunk_ids stays raw because it is high-entropy and almost incompressible.

Source

pub fn embedding_dtype(self, dt: EmbeddingDType) -> Self

Embedding dtype + on-disk encoding. Mutates the manifest’s dtype to match. Quantized variants (Float16, Int8) are lossy; the runtime always accumulates dot products in f32.

Source

pub fn hnsw_index(self, payload: Vec<u8>) -> Self

Attach an HNSW index payload (already encoded by urna-runtime). Sets index_type=hnsw, rerank_policy=exact, supports_ann=true.

Source

pub fn bm25_index(self, payload: Vec<u8>) -> Self

Attach a BM25 index payload.

Source

pub fn graph_adjacency(self, payload: Vec<u8>) -> Self

Attach a graph_adjacency (0x0C) csr payload (chunk-to-chunk edges, already encoded by encode_graph_adjacency). Sets the additive capabilities_ext.graph_present = Some(true) flag so the runtime opens the section behind a capability, exactly like hnsw/bm25. The section is EXCLUDED from content_hash, so adding a graph never invalidates a urna:// citation. Emitted raw, like hnsw.

Source

pub fn blob_refs(self, payload: Vec<u8>) -> Self

Attach a blob_refs (0x14) payload (already encoded by encode_blob_refs): the content-hash reference table for source media blobs. Sets the additive capabilities_ext.blobs_present flag so the runtime opens the section behind a capability, exactly like hnsw/bm25/graph. The section is EXCLUDED from content_hash, so a self-contained media corpus keeps the content_hash (and the urna:// citations) of its text-only twin. Emitted raw, like hnsw.

Source

pub fn blob_data(self, payload: Vec<u8>) -> Self

Attach a blob_data (0x17) payload (already encoded by encode_blob_data): the inlined media bytes whose offset table parallels the 0x14 record order, making the file self-contained with no media sidecar. additive and EXCLUDED from content_hash; implies blobs_present (the table indexes the 0x14 records).

Source

pub fn blob_span_overlay(self, payload: Vec<u8>) -> Self

Attach a blob_span_overlay (0x16) payload (already encoded by encode_blob_span_overlay): per-chunk blob-relative spans that the runtime prefers over chunks_original_spans (0x03) for cite/retrieve, so 0x03 never has to carry an ordinal disguised as a byte range. additive and EXCLUDED from content_hash; also implies blobs_present (the overlay indexes the 0x14 table).

Source

pub fn space_table(self, payload: Vec<u8>) -> Self

Attach a space_table (0x15) payload (already encoded by encode_space_table): the multimodal per-space directory. Sets the additive capabilities_ext.supports_multimodal flag so the runtime opens the space bands behind a capability, exactly like the other optional sections. EXCLUDED from content_hash, so a multimodal corpus keeps the citations of its text-only twin. Emitted raw.

Source

pub fn space_band( self, space_index: u8, encoding: u32, payload: Vec<u8>, ) -> Self

Attach one per-space vector band: the fixed-stride slab at section 0x20 + space_index. encoding is the dtype encoding (SECTION_ENCODING_RAW for f32, or float16/int8/int4), NEVER zstd (the reader rejects it for band ids). EXCLUDED from content_hash; also implies supports_multimodal (a band without a table is still a multimodal file, though the runtime only opens listed spaces).

Source

pub fn hybrid(self) -> Self

Mark the search path as hybrid (BM25 + cosine). Requires both an HNSW or exact path and a BM25 index. Caller is responsible for declaring score_type=hybrid_rrf if they want that, otherwise score_type stays “cosine”.

Source

pub fn write_to_path(self, path: impl AsRef<Path>) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.