use chrono::Utc; use derive_setters::Setters; use serde::{Deserialize, Serialize}; use uuid::Uuid; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct PointId(Uuid); impl PointId { pub fn generate() -> Self { Self(Uuid::new_v4()) } pub fn into_uuid(self) -> Uuid { self.0 } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Point { pub id: PointId, pub content: C, pub embedding: Vec, pub created_at: chrono::DateTime, pub updated_at: chrono::DateTime, } impl Point { /// Embedding can be created from a part or more of the actual content. pub fn new(content: C, embedding: Vec) -> Self { let now = Utc::now(); Self { id: PointId::generate(), content, embedding, created_at: now, updated_at: now, } } pub fn try_map( self, f: impl FnOnce(C) -> std::result::Result, ) -> std::result::Result, E> { Ok(Point { content: f(self.content)?, id: self.id, embedding: self.embedding, created_at: self.created_at, updated_at: self.updated_at, }) } } #[derive(Debug, Clone, Setters)] #[setters(strip_option, into)] pub struct Query { pub embedding: Vec, pub limit: Option, pub distance: Option, } impl Query { pub fn new(embedding: Vec) -> Self { Self { embedding, limit: None, distance: None } } }