Skip to content

Commit 1e7d1d7

Browse files
committed
refactor(examples): clean up code formatting and imports in example files
- Remove unnecessary blank lines and trailing spaces - Consolidate multi-line variable declarations into single lines where appropriate - Reorder imports to follow standard conventions refactor(engine): improve code readability in engine implementation - Format long method chains with proper indentation - Break down complex expressions into readable blocks - Clean up error message formatting refactor(indexer): enhance code formatting in indexing components - Standardize multi-line function calls and method chaining - Improve readability of complex operations - Consolidate redundant blank lines refactor(retriever): clean up retriever and related modules - Format long expressions and method calls consistently - Remove unused imports and declarations - Improve code organization in TOC processing modules refactor(llm): streamline LLM executor and pool implementations - Clean up error messages and string formatting - Improve readability of conditional statements - Standardize async method calls refactor(search): restructure search algorithm implementations - Format complex calculations and expressions clearly - Remove unused imports and exports - Clean up test cases and remove obsolete tests
1 parent eabe090 commit 1e7d1d7

37 files changed

Lines changed: 263 additions & 307 deletions

rust/examples/advanced.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> vectorless::Result<()> {
2929
// The config file must include api_key and model.
3030
// If environment variables are set, they override the config file values.
3131
let mut builder = EngineBuilder::new().with_config_path("./config.toml");
32-
32+
3333
// Override config with env vars if present
3434
if let Ok(api_key) = std::env::var("LLM_API_KEY") {
3535
builder = builder.with_key(&api_key);
@@ -72,4 +72,4 @@ async fn main() -> vectorless::Result<()> {
7272

7373
println!("\n=== Done ===");
7474
Ok(())
75-
}
75+
}

rust/examples/events.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
100100

101101
// Build engine with LLM configuration from environment or defaults.
102102
// Adjust the defaults below to match your setup.
103-
let api_key = std::env::var("LLM_API_KEY")
104-
.unwrap_or_else(|_| "sk-...".to_string());
105-
let model = std::env::var("LLM_MODEL")
106-
.unwrap_or_else(|_| "gpt-4o".to_string());
107-
let endpoint = std::env::var("LLM_ENDPOINT")
108-
.unwrap_or_else(|_| "https://api.openai.com/v1".to_string());
103+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-...".to_string());
104+
let model = std::env::var("LLM_MODEL").unwrap_or_else(|_| "gpt-4o".to_string());
105+
let endpoint =
106+
std::env::var("LLM_ENDPOINT").unwrap_or_else(|_| "https://api.openai.com/v1".to_string());
109107

110108
// 2. Create engine with events
111109
println!("Step 2: Creating engine with event emitter...");
@@ -130,10 +128,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
130128
// 4. Query with events
131129
println!("Step 4: Querying (with events)...");
132130
let result = engine
133-
.query(
134-
QueryContext::new("What is vectorless?")
135-
.with_doc_id(&doc_id)
136-
)
131+
.query(QueryContext::new("What is vectorless?").with_doc_id(&doc_id))
137132
.await?;
138133
if let Some(item) = result.single() {
139134
println!(" ✓ Found result ({} chars)", item.content.len());
@@ -145,7 +140,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
145140

146141
// 5. Stats
147142
println!("\n--- Stats ---");
148-
println!(" Documents indexed: {}", index_count.load(Ordering::SeqCst));
143+
println!(
144+
" Documents indexed: {}",
145+
index_count.load(Ordering::SeqCst)
146+
);
149147
println!(" Queries executed: {}", query_count.load(Ordering::SeqCst));
150148
println!(" Nodes visited: {}", nodes_visited.load(Ordering::SeqCst));
151149

rust/examples/flow.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ async fn main() -> vectorless::Result<()> {
6161

6262
// Build engine with LLM configuration from environment or defaults.
6363
// Adjust the defaults below to match your setup.
64-
let api_key = std::env::var("LLM_API_KEY")
65-
.unwrap_or_else(|_| "sk-...".to_string());
66-
let model = std::env::var("LLM_MODEL")
67-
.unwrap_or_else(|_| "gpt-4o".to_string());
68-
let endpoint = std::env::var("LLM_ENDPOINT")
69-
.unwrap_or_else(|_| "https://api".to_string());
64+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-...".to_string());
65+
let model = std::env::var("LLM_MODEL").unwrap_or_else(|_| "gpt-4o".to_string());
66+
let endpoint = std::env::var("LLM_ENDPOINT").unwrap_or_else(|_| "https://api".to_string());
7067

7168
// Step 1: Create a Vectorless client
7269
println!("Step 1: Creating Vectorless client...");

rust/examples/graph.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ async fn main() -> vectorless::Result<()> {
2929

3030
// Build engine with LLM configuration from environment or defaults.
3131
// Adjust the defaults below to match your setup.
32-
let api_key = std::env::var("LLM_API_KEY")
33-
.unwrap_or_else(|_| "sk-...".to_string());
34-
let model = std::env::var("LLM_MODEL")
35-
.unwrap_or_else(|_| "gpt-4o".to_string());
32+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-...".to_string());
33+
let model = std::env::var("LLM_MODEL").unwrap_or_else(|_| "gpt-4o".to_string());
3634

3735
// 1. Create engine
3836
let engine = EngineBuilder::new()
@@ -106,4 +104,4 @@ async fn main() -> vectorless::Result<()> {
106104

107105
println!("\n=== Done ===");
108106
Ok(())
109-
}
107+
}

rust/examples/index_incremental.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ async fn main() -> vectorless::Result<()> {
2121

2222
// Build engine with LLM configuration from environment or defaults.
2323
// Adjust the defaults below to match your setup.
24-
let api_key = std::env::var("LLM_API_KEY")
25-
.unwrap_or_else(|_| "sk-or-v1-...".to_string());
26-
let model = std::env::var("LLM_MODEL")
27-
.unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
24+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-or-v1-...".to_string());
25+
let model =
26+
std::env::var("LLM_MODEL").unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
2827
let endpoint = std::env::var("LLM_ENDPOINT")
2928
.unwrap_or_else(|_| "http://localhost:4000/api/v1".to_string());
3029

@@ -66,12 +65,19 @@ Deletes a user by their unique identifier.
6665
// 1. Initial full index
6766
println!("--- Initial index ---");
6867
let result = engine
69-
.index(IndexContext::from_content(content_v1, DocumentFormat::Markdown))
68+
.index(IndexContext::from_content(
69+
content_v1,
70+
DocumentFormat::Markdown,
71+
))
7072
.await?;
7173

7274
let doc_id = result.items[0].doc_id.clone();
7375
if let Some(m) = &result.items[0].metrics {
74-
println!("indexed in {}ms, {} nodes", m.total_time_ms(), m.nodes_processed);
76+
println!(
77+
"indexed in {}ms, {} nodes",
78+
m.total_time_ms(),
79+
m.nodes_processed
80+
);
7581
}
7682

7783
// 2. Re-index unchanged content (incremental) — skips processing
@@ -98,7 +104,11 @@ Deletes a user by their unique identifier.
98104

99105
for item in &result.items {
100106
if let Some(m) = &item.metrics {
101-
println!("updated in {}ms, {} nodes", m.total_time_ms(), m.nodes_processed);
107+
println!(
108+
"updated in {}ms, {} nodes",
109+
m.total_time_ms(),
110+
m.nodes_processed
111+
);
102112
}
103113
}
104114

@@ -110,4 +120,4 @@ Deletes a user by their unique identifier.
110120
}
111121

112122
Ok(())
113-
}
123+
}

rust/examples/index_pdf.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ async fn main() -> vectorless::Result<()> {
4949
std::process::exit(1);
5050
}
5151
};
52-
let model = std::env::var("LLM_MODEL")
53-
.unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
52+
let model =
53+
std::env::var("LLM_MODEL").unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
5454
let endpoint = std::env::var("LLM_ENDPOINT")
5555
.unwrap_or_else(|_| "http://localhost:4000/api/v1".to_string());
5656

@@ -70,9 +70,7 @@ async fn main() -> vectorless::Result<()> {
7070
.await
7171
.map_err(|e| vectorless::Error::Config(e.to_string()))?;
7272

73-
let result = engine
74-
.index(IndexContext::from_path(pdf_path))
75-
.await?;
73+
let result = engine.index(IndexContext::from_path(pdf_path)).await?;
7674

7775
println!(
7876
"Indexed: {}, Failed: {}",

rust/examples/index_single.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ async fn main() -> vectorless::Result<()> {
2121

2222
// Build engine with LLM configuration from environment or defaults.
2323
// Adjust the defaults below to match your setup.
24-
let api_key = std::env::var("LLM_API_KEY")
25-
.unwrap_or_else(|_| "sk-or-v1-...".to_string());
26-
let model = std::env::var("LLM_MODEL")
27-
.unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
24+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-or-v1-...".to_string());
25+
let model =
26+
std::env::var("LLM_MODEL").unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
2827
let endpoint = std::env::var("LLM_ENDPOINT")
2928
.unwrap_or_else(|_| "http://localhost:4000/api/v1".to_string());
3029

@@ -78,7 +77,10 @@ Monitoring is implemented using a Prometheus and Grafana stack, with custom metr
7877

7978
// Index from content string
8079
let result = engine
81-
.index(IndexContext::from_content(content, DocumentFormat::Markdown))
80+
.index(IndexContext::from_content(
81+
content,
82+
DocumentFormat::Markdown,
83+
))
8284
.await?;
8385

8486
for item in &result.items {
@@ -99,4 +101,4 @@ Monitoring is implemented using a Prometheus and Grafana stack, with custom metr
99101
}
100102

101103
Ok(())
102-
}
104+
}

rust/examples/indexing.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ async fn main() -> vectorless::Result<()> {
2121

2222
// Build engine with LLM configuration from environment or defaults.
2323
// Adjust the defaults below to match your setup.
24-
let api_key = std::env::var("LLM_API_KEY")
25-
.unwrap_or_else(|_| "sk-or-v1-...".to_string());
26-
let model = std::env::var("LLM_MODEL")
27-
.unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
24+
let api_key = std::env::var("LLM_API_KEY").unwrap_or_else(|_| "sk-or-v1-...".to_string());
25+
let model =
26+
std::env::var("LLM_MODEL").unwrap_or_else(|_| "google/gemini-3-flash-preview".to_string());
2827
let endpoint = std::env::var("LLM_ENDPOINT")
2928
.unwrap_or_else(|_| "http://localhost:4000/api/v1".to_string());
3029

@@ -40,8 +39,7 @@ async fn main() -> vectorless::Result<()> {
4039
// Index multiple documents in a single call.
4140
// Paths are resolved relative to the workspace directory.
4241
let result = engine
43-
.index(
44-
IndexContext::from_paths(&["../README.md", "../CLAUDE.md"]))
42+
.index(IndexContext::from_paths(&["../README.md", "../CLAUDE.md"]))
4543
.await?;
4644

4745
println!("Indexed {} document(s)", result.items.len());
@@ -59,4 +57,4 @@ async fn main() -> vectorless::Result<()> {
5957
}
6058

6159
Ok(())
62-
}
60+
}

rust/src/client/engine.rs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ impl Engine {
166166
return Err(Error::Config(format!(
167167
"All {} source(s) failed to index: {}",
168168
failed.len(),
169-
failed.iter().map(|f| format!("{} ({})", f.source, f.error)).collect::<Vec<_>>().join("; ")
169+
failed
170+
.iter()
171+
.map(|f| format!("{} ({})", f.source, f.error))
172+
.collect::<Vec<_>>()
173+
.join("; ")
170174
)));
171175
}
172176
if !items.is_empty() {
@@ -184,20 +188,21 @@ impl Engine {
184188
.max_concurrent_requests
185189
.min(ctx.sources.len());
186190

187-
let results: Vec<(Vec<IndexItem>, Vec<FailedItem>)> = futures::stream::iter(ctx.sources.iter().cloned())
188-
.map(|source| {
189-
let options = ctx.options.clone();
190-
let name = ctx.name.clone();
191-
let engine = self.clone();
192-
async move {
193-
engine
194-
.process_source(&source, &options, name.as_deref())
195-
.await
196-
}
197-
})
198-
.buffer_unordered(concurrency)
199-
.collect()
200-
.await;
191+
let results: Vec<(Vec<IndexItem>, Vec<FailedItem>)> =
192+
futures::stream::iter(ctx.sources.iter().cloned())
193+
.map(|source| {
194+
let options = ctx.options.clone();
195+
let name = ctx.name.clone();
196+
let engine = self.clone();
197+
async move {
198+
engine
199+
.process_source(&source, &options, name.as_deref())
200+
.await
201+
}
202+
})
203+
.buffer_unordered(concurrency)
204+
.collect()
205+
.await;
201206

202207
let mut items = Vec::new();
203208
let mut failed = Vec::new();
@@ -210,7 +215,11 @@ impl Engine {
210215
return Err(Error::Config(format!(
211216
"All {} source(s) failed to index: {}",
212217
failed.len(),
213-
failed.iter().map(|f| format!("{} ({})", f.source, f.error)).collect::<Vec<_>>().join("; ")
218+
failed
219+
.iter()
220+
.map(|f| format!("{} ({})", f.source, f.error))
221+
.collect::<Vec<_>>()
222+
.join("; ")
214223
)));
215224
}
216225

@@ -416,7 +425,11 @@ impl Engine {
416425
}
417426
};
418427

419-
match self.retriever.query_with_reasoning_index(&tree, &ctx.query, &options, reasoning_index).await {
428+
match self
429+
.retriever
430+
.query_with_reasoning_index(&tree, &ctx.query, &options, reasoning_index)
431+
.await
432+
{
420433
Ok(mut result) => {
421434
result.doc_id = doc_id;
422435
items.push(result);
@@ -433,7 +446,11 @@ impl Engine {
433446
return Err(Error::Config(format!(
434447
"Query failed for all {} document(s): {}",
435448
failed.len(),
436-
failed.iter().map(|f| format!("{} ({})", f.source, f.error)).collect::<Vec<_>>().join("; ")
449+
failed
450+
.iter()
451+
.map(|f| format!("{} ({})", f.source, f.error))
452+
.collect::<Vec<_>>()
453+
.join("; ")
437454
)));
438455
}
439456

@@ -531,7 +548,10 @@ impl Engine {
531548
// ============================================================
532549

533550
/// Get document structure (tree) and optional reasoning index. Internal use only.
534-
pub(crate) async fn get_structure(&self, doc_id: &str) -> Result<(DocumentTree, Option<crate::document::ReasoningIndex>)> {
551+
pub(crate) async fn get_structure(
552+
&self,
553+
doc_id: &str,
554+
) -> Result<(DocumentTree, Option<crate::document::ReasoningIndex>)> {
535555
let workspace = self
536556
.workspace
537557
.as_ref()

rust/src/client/indexer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ impl IndexerClient {
447447
}
448448

449449
persisted.reasoning_index = doc.reasoning_index;
450-
persisted.meta.update_processing_stats(node_count, summary_tokens, duration_ms);
450+
persisted
451+
.meta
452+
.update_processing_stats(node_count, summary_tokens, duration_ms);
451453

452454
persisted
453455
}

0 commit comments

Comments
 (0)