1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Storage traits for vectors and payloads.
//!
//! This module defines the core storage abstractions used by `VelesDB`.
use std::io;
/// Trait defining storage operations for vectors.
pub trait VectorStorage: Send + Sync {
/// Stores a vector with the given ID.
///
/// Durability note: implementations may buffer writes. Call [`flush`](Self::flush)
/// to obtain an explicit durability barrier.
///
/// # Errors
///
/// Returns an error if the write operation fails.
fn store(&mut self, id: u64, vector: &[f32]) -> io::Result<()>;
/// Stores multiple vectors in a single batch operation.
///
/// This is optimized for bulk imports:
/// - Single WAL write for the entire batch
/// - Contiguous memory writes
///
/// Durability note: batch writes may be buffered. Call [`flush`](Self::flush)
/// after `store_batch` to force persistence guarantees.
///
/// # Errors
///
/// Returns an error if the write operation fails.
fn store_batch(&mut self, vectors: &[(u64, &[f32])]) -> io::Result<usize>;
/// Retrieves a vector by ID.
///
/// # Errors
///
/// Returns an error if the read operation fails.
fn retrieve(&self, id: u64) -> io::Result<Option<Vec<f32>>>;
/// Deletes a vector by ID.
///
/// # Errors
///
/// Returns an error if the delete operation fails.
fn delete(&mut self, id: u64) -> io::Result<()>;
/// Flushes pending writes to disk.
///
/// This is the explicit durability barrier. Callers that require
/// deterministic crash consistency must call this method.
///
/// # Errors
///
/// Returns an error if the flush operation fails.
fn flush(&mut self) -> io::Result<()>;
/// Returns the number of vectors stored.
fn len(&self) -> usize;
/// Returns true if the storage is empty.
fn is_empty(&self) -> bool {
self.len() == 0
}
/// Returns all stored IDs.
fn ids(&self) -> Vec<u64>;
}
/// Trait defining storage operations for metadata payloads.
pub trait PayloadStorage: Send + Sync {
/// Stores a payload with the given ID.
///
/// Durability note: implementations may buffer writes. Call [`flush`](Self::flush)
/// to obtain an explicit durability barrier.
///
/// # Errors
///
/// Returns an error if the write operation fails.
fn store(&mut self, id: u64, payload: &serde_json::Value) -> io::Result<()>;
/// Retrieves a payload by ID.
///
/// # Errors
///
/// Returns an error if the read operation fails.
fn retrieve(&self, id: u64) -> io::Result<Option<serde_json::Value>>;
/// Deletes a payload by ID.
///
/// # Errors
///
/// Returns an error if the delete operation fails.
fn delete(&mut self, id: u64) -> io::Result<()>;
/// Flushes pending writes to disk.
///
/// This is the explicit durability barrier. Callers that require
/// deterministic crash consistency must call this method.
///
/// # Errors
///
/// Returns an error if the flush operation fails.
fn flush(&mut self) -> io::Result<()>;
/// Returns all stored IDs.
fn ids(&self) -> Vec<u64>;
}