hermes-core 1.8.78

Core async search engine library with WASM support
Documentation
//! Shared ANN index constants and construction helpers.
//!
//! Constants are available on all platforms (including WASM).
//! Builder/serialization functions are native-only.

/// Index type discriminants stored in the vectors file TOC.
pub const IVF_PQ_TYPE: u8 = 2;
pub const FLAT_TYPE: u8 = 4;
/// Binary IVF payload backed by an index-level global quantizer.
pub const BINARY_IVF_TYPE: u8 = 6;

// --- Native-only builder/serialization functions ---

#[cfg(feature = "native")]
use crate::structures::{CoarseCentroids, IVFPQConfig, IVFPQIndex, PQCodebook};

/// Create a fresh IVF-PQ index ready for vector insertion.
#[cfg(feature = "native")]
pub fn new_ivf_pq(
    dim: usize,
    routing: crate::dsl::IvfRoutingMode,
    centroids: &CoarseCentroids,
    codebook: &PQCodebook,
) -> IVFPQIndex {
    let config = IVFPQConfig::new(dim, codebook.config.num_subspaces).with_routing(routing);
    IVFPQIndex::new(config, centroids.version, codebook.version)
}

/// Encode a populated IVF-PQ build into the merge-native segment format.
#[cfg(feature = "native")]
pub fn serialize_ivf_pq(index: IVFPQIndex, num_clusters: u32) -> crate::Result<Vec<u8>> {
    let mut bytes = Vec::new();
    crate::segment::ann_disk::write_built_ivf_pq(&index, num_clusters, &mut bytes)
        .map_err(crate::Error::Io)?;
    Ok(bytes)
}