Skip to main content

hermes_core/segment/
vector_data.rs

1//! Vector index data structures shared between builder and reader
2
3use serde::{Deserialize, Serialize};
4
5/// Flat vector data for brute-force search (accumulating state)
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct FlatVectorData {
8    pub dim: usize,
9    pub vectors: Vec<Vec<f32>>,
10    pub doc_ids: Vec<u32>,
11}
12
13/// IVF-RaBitQ index data with embedded centroids and codebook
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct IVFRaBitQIndexData {
16    pub index: crate::structures::IVFRaBitQIndex,
17    pub centroids: crate::structures::CoarseCentroids,
18    pub codebook: crate::structures::RaBitQCodebook,
19}
20
21impl IVFRaBitQIndexData {
22    pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
23        serde_json::to_vec(self)
24            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
25    }
26
27    pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
28        serde_json::from_slice(data)
29            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
30    }
31}
32
33/// ScaNN index data with embedded centroids and codebook
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct ScaNNIndexData {
36    pub index: crate::structures::IVFPQIndex,
37    pub centroids: crate::structures::CoarseCentroids,
38    pub codebook: crate::structures::PQCodebook,
39}
40
41impl ScaNNIndexData {
42    pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
43        serde_json::to_vec(self)
44            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
45    }
46
47    pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
48        serde_json::from_slice(data)
49            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
50    }
51}