1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct GpuVector {
9 pub id: String,
11 pub data: Vec<f32>,
13 pub metadata: HashMap<String, String>,
15}
16
17impl GpuVector {
18 pub fn new(id: String, data: Vec<f32>) -> Self {
20 Self {
21 id,
22 data,
23 metadata: HashMap::new(),
24 }
25 }
26
27 pub fn with_metadata(id: String, data: Vec<f32>, metadata: HashMap<String, String>) -> Self {
29 Self { id, data, metadata }
30 }
31
32 pub fn dimension(&self) -> usize {
34 self.data.len()
35 }
36
37 pub fn memory_size(&self) -> usize {
39 self.data.len() * std::mem::size_of::<f32>() + self.id.len() + self.metadata.len() * 32 }
41}
42
43impl From<&GpuVector> for Vec<f32> {
44 fn from(v: &GpuVector) -> Self {
45 v.data.clone()
46 }
47}
48
49#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
51#[serde(rename_all = "lowercase")]
52pub enum GpuDistanceMetric {
53 Cosine,
55 Euclidean,
57 DotProduct,
59}
60
61impl std::fmt::Display for GpuDistanceMetric {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 match self {
64 GpuDistanceMetric::Cosine => write!(f, "cosine"),
65 GpuDistanceMetric::Euclidean => write!(f, "euclidean"),
66 GpuDistanceMetric::DotProduct => write!(f, "dot_product"),
67 }
68 }
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct GpuSearchResult {
74 pub id: String,
76 pub score: f32,
78 pub index: usize,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct GpuDeviceInfo {
85 pub name: String,
87 pub device_type: String,
89 pub memory_bytes: u64,
91 pub max_buffer_size: u64,
93 pub compute_capability: Option<String>,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct GpuCapabilities {
100 pub supports_hnsw: bool,
102 pub supports_batch: bool,
104 pub max_dimension: usize,
106 pub max_batch_size: usize,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct GpuMemoryStats {
113 pub total_allocated: usize,
115 pub available: usize,
117 pub utilization: f32,
119 pub buffer_count: usize,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct HnswConfig {
126 pub max_connections: usize,
128 pub ef_construction: usize,
130 pub ef_search: usize,
132 pub max_level: usize,
134 pub level_multiplier: f32,
136 pub seed: Option<u64>,
138}
139
140impl Default for HnswConfig {
141 fn default() -> Self {
142 Self {
143 max_connections: 16,
144 ef_construction: 100,
145 ef_search: 50,
146 max_level: 8,
147 level_multiplier: 0.5,
148 seed: None,
149 }
150 }
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
155pub struct VectorMetadata {
156 pub original_id: String,
158 pub index: usize,
160 pub timestamp: u64,
162}