abu_rag/document/
model.rs1use std::{fmt::Display, path::PathBuf};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5#[serde(transparent)]
6pub struct Id(pub String);
7
8#[derive(Debug, Clone)]
9pub struct Document {
10 pub id: Id,
11 pub source: PathBuf,
12 pub text: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Chunk {
17 pub id: Id,
18 pub document_id: Id,
19 pub text: String,
20 pub start: usize,
21 pub end: usize,
22}
23
24impl Id {
25 pub fn new(inner: impl Into<String>) -> Self {
26 Self(inner.into())
27 }
28
29 pub fn uuid() -> Self {
30 Self::new(uuid::Uuid::new_v4())
31 }
32}
33
34impl Display for Id {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 write!(f, "{}", self.0)
37 }
38}