Skip to main content

vectrust_core/
item.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3use chrono::{DateTime, Utc};
4
5/// Maintains exact compatibility with Node.js VectorItem structure
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct VectorItem {
8    pub id: Uuid,
9    pub vector: Vec<f32>,
10    pub metadata: serde_json::Value,
11    
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub indexed: Option<serde_json::Value>,
14    
15    #[serde(default)]
16    pub deleted: bool,
17    
18    #[serde(default = "Utc::now")]
19    pub created_at: DateTime<Utc>,
20    
21    #[serde(default = "Utc::now")]
22    pub updated_at: DateTime<Utc>,
23    
24    #[serde(default)]
25    pub version: u32,
26}
27
28impl Default for VectorItem {
29    fn default() -> Self {
30        Self {
31            id: Uuid::new_v4(),
32            vector: Vec::new(),
33            metadata: serde_json::Value::Object(serde_json::Map::new()),
34            indexed: None,
35            deleted: false,
36            created_at: Utc::now(),
37            updated_at: Utc::now(),
38            version: 1,
39        }
40    }
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct UpdateRequest {
45    pub id: Uuid,
46    pub vector: Option<Vec<f32>>,
47    pub metadata: Option<serde_json::Value>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct UpdateResult {
52    pub id: Uuid,
53    pub version: u32,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct ListOptions {
58    pub limit: Option<usize>,
59    pub offset: Option<usize>,
60    pub filter: Option<serde_json::Value>,
61}