use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FlatVectorData {
pub dim: usize,
pub vectors: Vec<Vec<f32>>,
pub doc_ids: Vec<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IVFRaBitQIndexData {
pub index: crate::structures::IVFRaBitQIndex,
pub centroids: crate::structures::CoarseCentroids,
pub codebook: crate::structures::RaBitQCodebook,
}
impl IVFRaBitQIndexData {
pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
serde_json::to_vec(self)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
}
pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
serde_json::from_slice(data)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScaNNIndexData {
pub index: crate::structures::IVFPQIndex,
pub centroids: crate::structures::CoarseCentroids,
pub codebook: crate::structures::PQCodebook,
}
impl ScaNNIndexData {
pub fn to_bytes(&self) -> std::io::Result<Vec<u8>> {
serde_json::to_vec(self)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
}
pub fn from_bytes(data: &[u8]) -> std::io::Result<Self> {
serde_json::from_slice(data)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
}
}