use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexedDocument {
pub id: u64,
pub url: String,
pub title: String,
pub content: String,
pub domain: String,
pub fetched_at: DateTime<Utc>,
pub content_hash: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub embedding: Option<Vec<f32>>,
}
impl IndexedDocument {
pub fn is_embedded(&self) -> bool {
self.embedding.is_some()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexStats {
pub document_count: usize,
pub embedded_count: usize,
pub index_size_bytes: u64,
pub vector_index_ready: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_embedded_returns_correct_values() {
let mut doc = IndexedDocument {
id: 1,
url: "https://example.com".into(),
title: "Test".into(),
content: "content".into(),
domain: "example.com".into(),
fetched_at: Utc::now(),
content_hash: "abc".into(),
embedding: None,
};
assert!(!doc.is_embedded());
doc.embedding = Some(vec![0.0; 384]);
assert!(doc.is_embedded());
}
}