Skip to content

Commit 32d81bb

Browse files
committed
refactor(index-context): consolidate directory indexing methods into single function
BREAKING CHANGE: The IndexContext::from_dir_recursive method has been removed and replaced with a boolean parameter in the from_dir method. - Replace separate from_dir and from_dir_recursive methods with unified from_dir(path, recursive) method - Update Python binding to use the new unified method signature - Update documentation examples to reflect the new API - Rename test function to match new naming convention
1 parent df2557a commit 32d81bb

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

python/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@ impl PyIndexContext {
226226
#[staticmethod]
227227
#[pyo3(signature = (path, recursive=false))]
228228
fn from_dir(path: String, recursive: bool) -> Self {
229-
let inner = if recursive {
230-
IndexContext::from_dir_recursive(&path)
231-
} else {
232-
IndexContext::from_dir(&path)
233-
};
229+
let inner = IndexContext::from_dir(&path, recursive);
234230
Self { inner }
235231
}
236232

rust/examples/index_directory.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ async fn main() -> vectorless::Result<()> {
4646
.map_err(|e| vectorless::Error::Config(e.to_string()))?;
4747

4848
// Index directory
49-
let ctx = if recursive {
50-
println!("Recursively indexing: {}", dir);
51-
IndexContext::from_dir_recursive(dir)
52-
} else {
53-
println!("Indexing top-level files in: {}", dir);
54-
IndexContext::from_dir(dir)
55-
};
49+
println!("{}indexing: {}", if recursive { "Recursively " } else { "" }, dir);
50+
let ctx = IndexContext::from_dir(dir, recursive);
5651

5752
if ctx.is_empty() {
5853
println!("No supported files found in: {}", dir);

rust/src/client/index_context.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
//! use vectorless::client::IndexContext;
3131
//!
3232
//! // Non-recursive (top-level only)
33-
//! let ctx = IndexContext::from_dir("./documents");
33+
//! let ctx = IndexContext::from_dir("./documents", false);
3434
//!
3535
//! // Recursive (includes subdirectories)
36-
//! let ctx = IndexContext::from_dir_recursive("./documents");
36+
//! let ctx = IndexContext::from_dir("./documents", true);
3737
//! ```
3838
3939
use std::path::PathBuf;
@@ -93,7 +93,7 @@ pub(crate) enum IndexSource {
9393
/// ).await?;
9494
///
9595
/// // Entire directory
96-
/// let result = engine.index(IndexContext::from_dir("./docs")).await?;
96+
/// let result = engine.index(IndexContext::from_dir("./docs", false)).await?;
9797
/// # Ok(())
9898
/// # }
9999
/// ```
@@ -135,18 +135,12 @@ impl IndexContext {
135135

136136
/// Create from a directory path.
137137
///
138-
/// Indexes all supported files in the directory (non-recursive).
138+
/// Indexes all supported files in the directory.
139139
/// Supported extensions: `.md`, `.pdf`.
140-
pub fn from_dir(dir: impl Into<PathBuf>) -> Self {
141-
Self::scan_dir(dir, false)
142-
}
143-
144-
/// Create from a directory path with recursive scanning.
145140
///
146-
/// Recursively indexes all supported files in the directory and its
147-
/// subdirectories. Supported extensions: `.md`, `.pdf`.
148-
pub fn from_dir_recursive(dir: impl Into<PathBuf>) -> Self {
149-
Self::scan_dir(dir, true)
141+
/// Set `recursive` to `true` to include subdirectories.
142+
pub fn from_dir(dir: impl Into<PathBuf>, recursive: bool) -> Self {
143+
Self::scan_dir(dir, recursive)
150144
}
151145

152146
/// Internal: scan a directory for supported document files.
@@ -340,7 +334,7 @@ mod tests {
340334
}
341335

342336
#[test]
343-
fn test_from_dir_recursive() {
337+
fn test_from_dir_with_recursive() {
344338
// Create a temp directory structure:
345339
// tmp/
346340
// a.md
@@ -357,11 +351,11 @@ mod tests {
357351
std::fs::write(tmp.join("sub/deep/ignore.dat"), b"xxx").unwrap();
358352

359353
// Non-recursive: only top-level
360-
let ctx = IndexContext::from_dir(&tmp);
354+
let ctx = IndexContext::from_dir(&tmp, false);
361355
assert_eq!(ctx.len(), 1); // only a.md
362356

363357
// Recursive: all levels
364-
let ctx = IndexContext::from_dir_recursive(&tmp);
358+
let ctx = IndexContext::from_dir(&tmp, true);
365359
assert_eq!(ctx.len(), 3); // a.md, b.md, c.pdf
366360

367361
let _ = std::fs::remove_dir_all(&tmp);

rust/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,5 @@ pub use graph::DocumentGraph;
7777
// Event types
7878
pub use events::{EventEmitter, IndexEvent, QueryEvent, WorkspaceEvent};
7979

80-
// Index metrics
81-
pub use metrics::IndexMetrics;
82-
8380
// Runtime metrics reports
84-
pub use metrics::{LlmMetricsReport, MetricsReport, PilotMetricsReport, RetrievalMetricsReport};
81+
pub use metrics::{IndexMetrics, LlmMetricsReport, MetricsReport, PilotMetricsReport, RetrievalMetricsReport};

0 commit comments

Comments
 (0)