Skip to content

Commit 7fdb56a

Browse files
committed
Update notify dependency to version 8.2.0 and enhance file watcher implementation
1 parent 7e2c4e9 commit 7fdb56a

File tree

5 files changed

+79
-57
lines changed

5 files changed

+79
-57
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ How to use ONNX embeddings
104104
# CPU-only (default)
105105
export CODEGRAPH_EMBEDDING_PROVIDER=onnx
106106
export CODEGRAPH_ONNX_EP=cpu
107+
export CODEGRAPH_LOCAL_MODEL=sentence-transformers/all-MiniLM-L6-v2
107108

108109
# CoreML (requires CoreML-enabled ORT build)
109110
export CODEGRAPH_EMBEDDING_PROVIDER=onnx
110111
export CODEGRAPH_ONNX_EP=coreml
112+
export CODEGRAPH_LOCAL_MODEL=sentence-transformers/all-MiniLM-L6-v2
113+
114+
115+
# Install codegraph
116+
cargo install --path crates/codegraph-mcp --features "embeddings,codegraph-vector/onnx"
111117
```
112118

113119
Notes
@@ -253,6 +259,9 @@ codegraph index .
253259
# Index with specific languages
254260
codegraph index . --languages rust,python,typescript
255261

262+
# Or with more options in Osx
263+
RUST_LOG=info,codegraph_vector=debug codegraph index . --workers 10 --batch-size 256 --device metal --max-seq-len 512 --force
264+
256265
# Index with file watching
257266
codegraph index . --watch
258267
```

crates/codegraph-graph/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sha2 = { workspace = true }
2929
memmap2 = { workspace = true }
3030
num_cpus = "1.16"
3131
crossbeam-channel = "0.5"
32-
notify = "6.0"
32+
notify = { workspace = true }
3333

3434
[dev-dependencies]
3535
tokio-test = { workspace = true }

crates/codegraph-graph/src/file_watcher.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use codegraph_core::{traits::FileWatcher, ChangeEvent, Result};
22
use crossbeam_channel::Sender;
3-
use notify::{Error as NotifyError, RecommendedWatcher, RecursiveMode, Watcher};
3+
use notify::{recommended_watcher, Event, RecommendedWatcher, RecursiveMode, Watcher};
44
use std::path::Path;
55

66
pub struct FileWatcherImpl {
@@ -17,14 +17,16 @@ impl FileWatcherImpl {
1717

1818
impl FileWatcher for FileWatcherImpl {
1919
fn watch(&self, tx: Sender<ChangeEvent>) -> Result<()> {
20-
let (notify_tx, notify_rx) = std::sync::mpsc::channel();
20+
let (notify_tx, notify_rx) = std::sync::mpsc::channel::<notify::Result<Event>>();
2121

22-
let mut watcher: RecommendedWatcher = Watcher::new(notify_tx, notify::Config::default())
23-
.map_err(|e: NotifyError| codegraph_core::CodeGraphError::Notify(e))?;
22+
let mut watcher: RecommendedWatcher = recommended_watcher(move |res: notify::Result<Event>| {
23+
let _ = notify_tx.send(res);
24+
})
25+
.map_err(|e| codegraph_core::CodeGraphError::Notify(e))?;
2426

2527
watcher
2628
.watch(Path::new(&self.path), RecursiveMode::Recursive)
27-
.map_err(|e: NotifyError| codegraph_core::CodeGraphError::Notify(e))?;
29+
.map_err(|e| codegraph_core::CodeGraphError::Notify(e))?;
2830

2931
for res in notify_rx {
3032
match res {
@@ -48,7 +50,7 @@ impl FileWatcher for FileWatcherImpl {
4850
})?;
4951
}
5052
}
51-
Err(e) => return Err(codegraph_core::CodeGraphError::Notify(e.into())),
53+
Err(e) => return Err(codegraph_core::CodeGraphError::Notify(e)),
5254
}
5355
}
5456

crates/codegraph-mcp/src/indexer.rs

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -60,67 +60,78 @@ impl ProjectIndexer {
6060
let graph = CodeGraph::new()?;
6161
#[cfg(feature = "embeddings")]
6262
let embedder = {
63-
use codegraph_vector::embeddings::generator::{
64-
AdvancedEmbeddingGenerator, EmbeddingEngineConfig, LocalDeviceTypeCompat,
65-
LocalEmbeddingConfigCompat, LocalPoolingCompat,
66-
};
6763
use codegraph_vector::EmbeddingGenerator;
6864
// If local requested via env, override local config from CLI flags
6965
let provider = std::env::var("CODEGRAPH_EMBEDDING_PROVIDER")
7066
.unwrap_or_default()
7167
.to_lowercase();
7268
if provider == "local" {
73-
let mut cfg = EmbeddingEngineConfig::default();
74-
cfg.prefer_local_first = true;
75-
let device = match config
76-
.device
77-
.as_deref()
78-
.unwrap_or("")
79-
.to_lowercase()
80-
.as_str()
69+
#[cfg(feature = "embeddings-local")]
8170
{
82-
"metal" => LocalDeviceTypeCompat::Metal,
83-
d if d.starts_with("cuda:") => {
84-
let id = d.trim_start_matches("cuda:").parse::<usize>().unwrap_or(0);
85-
LocalDeviceTypeCompat::Cuda(id)
86-
}
87-
_ => LocalDeviceTypeCompat::Cpu,
88-
};
89-
let model_name = std::env::var("CODEGRAPH_LOCAL_MODEL")
90-
.unwrap_or_else(|_| "sentence-transformers/all-MiniLM-L6-v2".to_string());
91-
cfg.local = Some(LocalEmbeddingConfigCompat {
92-
model_name,
93-
device,
94-
cache_dir: None,
95-
max_sequence_length: config.max_seq_len.max(32),
96-
pooling_strategy: LocalPoolingCompat::Mean,
97-
});
98-
// Try to construct advanced engine; fall back to simple generator on error
99-
match AdvancedEmbeddingGenerator::new(cfg).await {
100-
Ok(engine) => {
101-
if !engine.has_provider() {
71+
use codegraph_vector::embeddings::generator::{
72+
AdvancedEmbeddingGenerator, EmbeddingEngineConfig, LocalDeviceTypeCompat,
73+
LocalEmbeddingConfigCompat, LocalPoolingCompat,
74+
};
75+
let mut cfg = EmbeddingEngineConfig::default();
76+
cfg.prefer_local_first = true;
77+
let device = match config
78+
.device
79+
.as_deref()
80+
.unwrap_or("")
81+
.to_lowercase()
82+
.as_str()
83+
{
84+
"metal" => LocalDeviceTypeCompat::Metal,
85+
d if d.starts_with("cuda:") => {
86+
let id = d.trim_start_matches("cuda:").parse::<usize>().unwrap_or(0);
87+
LocalDeviceTypeCompat::Cuda(id)
88+
}
89+
_ => LocalDeviceTypeCompat::Cpu,
90+
};
91+
let model_name = std::env::var("CODEGRAPH_LOCAL_MODEL")
92+
.unwrap_or_else(|_| "sentence-transformers/all-MiniLM-L6-v2".to_string());
93+
cfg.local = Some(LocalEmbeddingConfigCompat {
94+
model_name,
95+
device,
96+
cache_dir: None,
97+
max_sequence_length: config.max_seq_len.max(32),
98+
pooling_strategy: LocalPoolingCompat::Mean,
99+
});
100+
// Try to construct advanced engine; fall back to simple generator on error
101+
match AdvancedEmbeddingGenerator::new(cfg).await {
102+
Ok(engine) => {
103+
if !engine.has_provider() {
104+
return Err(anyhow::anyhow!(
105+
"Local embedding provider constructed without a backend. Ensure the model is BERT-compatible with safetensors and try --device metal or --device cpu"
106+
));
107+
}
108+
let mut g = EmbeddingGenerator::default();
109+
g.set_advanced_engine(std::sync::Arc::new(engine));
110+
tracing::info!(
111+
target: "codegraph_mcp::indexer",
112+
"Active embeddings: Local (device: {}, max_seq_len: {}, batch_size: {})",
113+
config.device.as_deref().unwrap_or("cpu"),
114+
config.max_seq_len,
115+
config.batch_size
116+
);
117+
g
118+
}
119+
Err(e) => {
102120
return Err(anyhow::anyhow!(
103-
"Local embedding provider constructed without a backend. Ensure the model is BERT-compatible with safetensors and try --device metal or --device cpu"
121+
"Failed to initialize local embedding provider: {}",
122+
e
104123
));
105124
}
106-
let mut g = EmbeddingGenerator::default();
107-
g.set_advanced_engine(std::sync::Arc::new(engine));
108-
tracing::info!(
109-
target: "codegraph_mcp::indexer",
110-
"Active embeddings: Local (device: {}, max_seq_len: {}, batch_size: {})",
111-
config.device.as_deref().unwrap_or("cpu"),
112-
config.max_seq_len,
113-
config.batch_size
114-
);
115-
g
116-
}
117-
Err(e) => {
118-
return Err(anyhow::anyhow!(
119-
"Failed to initialize local embedding provider: {}",
120-
e
121-
));
122125
}
123126
}
127+
#[cfg(not(feature = "embeddings-local"))]
128+
{
129+
tracing::warn!(
130+
target: "codegraph_mcp::indexer",
131+
"CODEGRAPH_EMBEDDING_PROVIDER=local requested but the 'embeddings-local' feature is not enabled; using auto provider"
132+
);
133+
EmbeddingGenerator::with_auto_from_env().await
134+
}
124135
} else {
125136
let g = EmbeddingGenerator::with_auto_from_env().await;
126137
tracing::info!(

0 commit comments

Comments
 (0)