use std::collections::BTreeMap;
use std::path::Path;
use serde::{Deserialize, Serialize};
use smartcore::linalg::basic::matrix::DenseMatrix;
use crate::StorageResult;
use crate::traits::backend::StorageBackend;
use crate::zzarr::ZarrArray;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NodeKind {
Array,
Group,
}
impl NodeKind {
pub const fn as_str(&self) -> &'static str {
match self {
NodeKind::Array => "array",
NodeKind::Group => "group",
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DatasetSummary {
pub dataset_id: String,
pub root: String,
pub path: String,
pub shape: Vec<u64>,
pub dtype: String,
pub chunks: Option<Vec<u64>>,
pub fill_value: Option<serde_json::Value>,
pub kind: NodeKind,
pub extra: BTreeMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RowUpdate {
pub row_index: usize,
pub vector: Vec<f64>,
}
pub trait ZarrStorageOps: StorageBackend {
async fn list_datasets(&self) -> StorageResult<Vec<DatasetSummary>>;
async fn open(&self, dataset_id: &str) -> StorageResult<ZarrArray>;
async fn summarize(&self, dataset_id: &str, fs_path: &Path) -> StorageResult<DatasetSummary>;
async fn append_vectors(
&self,
dataset_id: &str,
vecs: &DenseMatrix<f64>,
) -> StorageResult<(usize, usize)>;
async fn overwrite_vectors(
&self,
dataset_id: &str,
updates: &[RowUpdate],
) -> StorageResult<usize>;
}