hermes_core/segment/
vector_data.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct FlatVectorData {
8 pub dim: usize,
9 pub vectors: Vec<Vec<f32>>,
10 pub doc_ids: Vec<(u32, u16)>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct IVFRaBitQIndexData {
18 pub index: crate::structures::IVFRaBitQIndex,
19 pub centroids: crate::structures::CoarseCentroids,
20 pub codebook: crate::structures::RaBitQCodebook,
21}
22
23impl IVFRaBitQIndexData {
24 pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
25 serde_json::to_vec(self)
26 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
27 }
28
29 pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
30 serde_json::from_slice(data)
31 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
32 }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct ScaNNIndexData {
38 pub index: crate::structures::IVFPQIndex,
39 pub centroids: crate::structures::CoarseCentroids,
40 pub codebook: crate::structures::PQCodebook,
41}
42
43impl ScaNNIndexData {
44 pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
45 serde_json::to_vec(self)
46 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
47 }
48
49 pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
50 serde_json::from_slice(data)
51 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
52 }
53}