vectorless/client/
types.rs1use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9use crate::core::DocumentTree;
10use crate::document::DocumentFormat;
11
12#[derive(Debug, Clone)]
14pub struct IndexedDocument {
15 pub id: String,
17
18 pub format: DocumentFormat,
20
21 pub name: String,
23
24 pub description: Option<String>,
26
27 pub source_path: Option<PathBuf>,
29
30 pub page_count: Option<usize>,
32
33 pub line_count: Option<usize>,
35
36 pub tree: Option<DocumentTree>,
38
39 pub pages: Vec<PageContent>,
41}
42
43impl IndexedDocument {
44 pub fn new(id: impl Into<String>, format: DocumentFormat) -> Self {
46 Self {
47 id: id.into(),
48 format,
49 name: String::new(),
50 description: None,
51 source_path: None,
52 page_count: None,
53 line_count: None,
54 tree: None,
55 pages: Vec::new(),
56 }
57 }
58
59 pub fn with_name(mut self, name: impl Into<String>) -> Self {
61 self.name = name.into();
62 self
63 }
64
65 pub fn with_description(mut self, desc: impl Into<String>) -> Self {
67 self.description = Some(desc.into());
68 self
69 }
70
71 pub fn with_source_path(mut self, path: impl Into<PathBuf>) -> Self {
73 self.source_path = Some(path.into());
74 self
75 }
76
77 pub fn with_page_count(mut self, count: usize) -> Self {
79 self.page_count = Some(count);
80 self
81 }
82
83 pub fn with_line_count(mut self, count: usize) -> Self {
85 self.line_count = Some(count);
86 self
87 }
88
89 pub fn with_tree(mut self, tree: DocumentTree) -> Self {
91 self.tree = Some(tree);
92 self
93 }
94
95 pub fn add_page(&mut self, page: usize, content: impl Into<String>) {
97 self.pages.push(PageContent {
98 page,
99 content: content.into(),
100 });
101 }
102
103 pub fn is_loaded(&self) -> bool {
105 self.tree.is_some()
106 }
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct PageContent {
112 pub page: usize,
114
115 pub content: String,
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq)]
121pub enum IndexMode {
122 Auto,
124
125 Pdf,
127
128 Markdown,
130
131 Html,
133}
134
135impl Default for IndexMode {
136 fn default() -> Self {
137 Self::Auto
138 }
139}
140
141#[derive(Debug, Clone)]
143pub struct IndexOptions {
144 pub mode: IndexMode,
146
147 pub generate_summaries: bool,
149
150 pub include_text: bool,
152
153 pub generate_ids: bool,
155
156 pub generate_description: bool,
158}
159
160impl Default for IndexOptions {
161 fn default() -> Self {
162 Self {
163 mode: IndexMode::Auto,
164 generate_summaries: false, include_text: true,
166 generate_ids: true,
167 generate_description: false,
168 }
169 }
170}
171
172impl IndexOptions {
173 pub fn new() -> Self {
175 Self::default()
176 }
177
178 pub fn with_summaries(mut self) -> Self {
180 self.generate_summaries = true;
181 self
182 }
183
184 pub fn with_description(mut self) -> Self {
186 self.generate_description = true;
187 self
188 }
189}
190
191#[derive(Debug, Clone)]
193pub struct QueryResult {
194 pub doc_id: String,
196
197 pub node_ids: Vec<String>,
199
200 pub content: String,
202
203 pub score: f32,
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize)]
209pub struct DocumentInfo {
210 pub id: String,
212
213 pub name: String,
215
216 pub format: String,
218
219 pub description: Option<String>,
221
222 pub page_count: Option<usize>,
224
225 pub line_count: Option<usize>,
227}