Skip to content

Commit 1316b11

Browse files
committed
feat: Enhance CodeGraph MCP with edge derivation and server capabilities
- Integrated edge derivation using ParserGraphIntegrator in ProjectIndexer. - Added support for new node types: Struct and Trait in indexing statistics. - Introduced a new server module for handling HTTP and STDIO transports. - Implemented various RPC methods for graph operations, code reading, patching, and test execution. - Added documentation for MCP tools and repository knowledge system to guide usage. - Improved text truncation logic in embedding generation to respect character boundaries.
1 parent fc13e06 commit 1316b11

File tree

14 files changed

+1219
-33
lines changed

14 files changed

+1219
-33
lines changed

.codegraph/index.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@ CLAUDE.md
168168
AGENTS.md
169169
CRUSH.md
170170
OUROBOROS.md
171-
.codegraph/index.json
171+
.codegraph/

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,98 @@ sudo dnf install cmake clang openssl-devel
162162
- **CUDA** (for GPU-accelerated embeddings)
163163
- **Git** (for repository integration)
164164

165+
## 🚀 Performance Benchmarks
166+
167+
Run repeatable, end-to-end benchmarks that measure indexing speed (with local embeddings + FAISS), vector search latency, and graph traversal throughput.
168+
169+
### Build with performance features
170+
171+
Pick one of the local embedding backends and enable FAISS:
172+
173+
```bash
174+
# Option A: ONNX Runtime (CoreML on macOS, CPU otherwise)
175+
cargo install --path crates/codegraph-mcp --features "embeddings,codegraph-vector/onnx,faiss"
176+
177+
# Option B: Local HF + Candle (CPU/Metal/CUDA)
178+
cargo install --path crates/codegraph-mcp --features "embeddings-local,faiss"
179+
```
180+
181+
### Configure local embedding backend
182+
183+
ONNX (CoreML/CPU):
184+
185+
```bash
186+
export CODEGRAPH_EMBEDDING_PROVIDER=onnx
187+
# macOS: use CoreML
188+
export CODEGRAPH_ONNX_EP=coreml # or cpu
189+
export CODEGRAPH_LOCAL_MODEL=/path/to/model.onnx
190+
```
191+
192+
Local HF + Candle (CPU/Metal/CUDA):
193+
194+
```bash
195+
export CODEGRAPH_EMBEDDING_PROVIDER=local
196+
# device: cpu | metal | cuda:<id>
197+
export CODEGRAPH_LOCAL_MODEL=sentence-transformers/all-MiniLM-L6-v2
198+
```
199+
200+
### Run the benchmark
201+
202+
```bash
203+
# Cold run (cleans .codegraph), warmup queries + timed trials
204+
codegraph perf . \
205+
--langs rust,ts,go \
206+
--warmup 3 --trials 20 \
207+
--batch-size 128 --device metal \
208+
--clean --format json
209+
```
210+
211+
What it measures
212+
213+
- Indexing: total time to parse -> embed -> build FAISS (global + shards)
214+
- Embedding throughput: embeddings per second
215+
- Vector search: latency (avg/p50/p95) across repeated queries
216+
- Graph traversal: BFS depth=2 micro-benchmark
217+
218+
Sample output (numbers will vary by machine and codebase)
219+
220+
```json
221+
{
222+
"env": {
223+
"embedding_provider": "local",
224+
"device": "metal",
225+
"features": { "faiss": true, "embeddings": true }
226+
},
227+
"dataset": {
228+
"path": "/repo/large-project",
229+
"languages": ["rust","ts","go"],
230+
"files": 18234,
231+
"lines": 2583190
232+
},
233+
"indexing": {
234+
"total_seconds": 186.4,
235+
"embeddings": 53421,
236+
"throughput_embeddings_per_sec": 286.6
237+
},
238+
"vector_search": {
239+
"queries": 100,
240+
"latency_ms": { "avg": 18.7, "p50": 12.3, "p95": 32.9 }
241+
},
242+
"graph": {
243+
"bfs_depth": 2,
244+
"visited_nodes": 1000,
245+
"elapsed_ms": 41.8
246+
}
247+
}
248+
```
249+
250+
Tips for reproducibility
251+
252+
- Use `--clean` for cold start numbers, and run a second time for warm cache numbers.
253+
- Close background processes that may compete for CPU/GPU.
254+
- Pin versions: `rustc --version`, FAISS build, and the embedding model.
255+
- Record the host: CPU/GPU, RAM, storage, OS version.
256+
165257
## 🚀 Installation
166258

167259
### Method 1: Install from Source

crates/codegraph-core/src/integration/parser_graph.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ where
241241
meta.insert("kind".into(), "call".into());
242242
meta.insert("file".into(), file.to_string_lossy().to_string());
243243
edges.push((*from_id, *to_id, EdgeType::Calls, meta));
244+
} else if content.as_str().contains(other_name.as_str()) {
245+
// Reference without obvious call signature
246+
let mut meta = HashMap::new();
247+
meta.insert("kind".into(), "reference".into());
248+
meta.insert("file".into(), file.to_string_lossy().to_string());
249+
edges.push((*from_id, *to_id, EdgeType::References, meta));
250+
}
251+
}
252+
// Implements (rough heuristic for Rust/Java): "impl <Trait> for <Type>" or "implements <Iface>"
253+
let lc = content.to_lowercase();
254+
if lc.contains(" implements ") {
255+
for (other_name, to_id, _ctx2) in names_in_file.iter() {
256+
if lc.contains(&other_name.to_lowercase()) {
257+
let mut meta = HashMap::new();
258+
meta.insert("kind".into(), "implements".into());
259+
meta.insert("file".into(), file.to_string_lossy().to_string());
260+
edges.push((*from_id, *to_id, EdgeType::Implements, meta));
261+
}
244262
}
245263
}
246264
}

crates/codegraph-mcp/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ faiss = { workspace = true, optional = true }
4444
# codegraph-api not used directly here; avoid pulling heavy deps
4545
## core-rag-mcp-server intentionally not linked to keep binary lean
4646

47+
axum = { workspace = true, optional = true }
48+
hyper = { workspace = true, optional = true }
49+
4750
[dev-dependencies]
4851
tokio-test = { workspace = true }
4952
tempfile = { workspace = true }
@@ -58,3 +61,4 @@ faiss = ["dep:faiss"]
5861
embeddings = ["dep:codegraph-vector"]
5962
embeddings-local = ["embeddings", "codegraph-vector/local-embeddings"]
6063
embeddings-openai = ["embeddings", "codegraph-vector/openai"]
64+
server-http = ["dep:axum", "dep:hyper"]

0 commit comments

Comments
 (0)