Skip to content

Commit 29ee815

Browse files
authored
Merge PR #7: static (model2vec) embeddings + extra-languages gating (0.19.0)
feat(embed): static (model2vec) embeddings + extra-languages gating — v0.19.0
2 parents 5021c7c + 1391ebc commit 29ee815

34 files changed

Lines changed: 1845 additions & 149 deletions

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ members = [
6060
]
6161

6262
[workspace.package]
63-
version = "0.18.6"
63+
version = "0.19.0"
6464
edition = "2021"
6565
license = "Apache-2.0"
6666
repository = "https://github.com/codegraph-ai/codegraph"

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,29 @@ one tool and exits without the MCP stdio handshake — ideal for scripting.
7777
|------|---------|-------------|
7878
| `--workspace <path>` | current dir | Directories to index (repeatable for multi-project) |
7979
| `--exclude <dir>` || Directories to skip (repeatable) |
80-
| `--embedding-model <model>` | `bge-small` | `bge-small` (384d, fast), `jina-code-v2` (768d, 6× slower), or `granite-97m` (384d, 32K ctx, ~3× slower) |
80+
| `--embedding-model <model>` | `bge-small` | `bge-small` (384d, fast), `jina-code-v2` (768d, 6× slower), `granite-97m` (384d, 32K ctx, ~3× slower), or `static` (model2vec, 256d — ~100× faster indexing, no ONNX; needs a local model dir, see below) |
8181
| `--full-body-embedding` | `true` | Embed full function body (~50 lines) for better semantic search and duplicate detection |
8282
| `--max-files <n>` | 5000 | Maximum files to index |
8383
| `--profile <name>` | `all` | Filter the exposed MCP tool surface to a named subset (see below) |
8484
| `--graph-only` | off | Skip embedding generation — build the graph and serve structural tools only. No ONNX model load, 10-50× faster indexing. Semantic search unavailable. For CI / one-shot graph queries. |
8585
| `--run-tool <name>` || One-shot mode: index, run a single tool, print its result, exit. No MCP handshake. Pair with `--tool-args '<json>'`. |
8686

87+
#### `--embedding-model static` — model2vec fast indexing
88+
89+
Static (model2vec) embeddings replace the ONNX transformer with a token→vector
90+
lookup table: indexing is **~100× faster** (this repo's 5,873 symbols embed in
91+
~1 s vs ~3.4 min with BGE) and there's **no ONNX runtime or 1.5 GB RAM gate**.
92+
Retrieval stays **hybrid (BM25 + semantic)**, so end-to-end quality is **~90% of
93+
BGE**. The VS Code extension ships the model bundled, so `static` works there
94+
with no setup. For the CLI/MCP server it needs a local model directory
95+
(`config.json` + `tokenizer.json` + `model.safetensors`):
96+
97+
- Point at it with `CODEGRAPH_STATIC_MODEL=/path/to/model` (or the VS Code
98+
`codegraph.staticModelPath` setting to override the bundled model). Default:
99+
`~/.codegraph/static_models/jina-code-static-256`.
100+
- Distill one from any sentence-transformer (Apache-2.0 Jina-Code by default) in
101+
~30 s on CPU: `python scripts/distill_static_model.py`.
102+
87103
#### `--profile` — narrow the MCP tool surface
88104

89105
The full 32-tool surface is convenient but inflates the agent's prompt-context cost. A profile exposes only the slice you need (also settable via the `CODEGRAPH_TOOL_PROFILE` env var):
@@ -103,7 +119,8 @@ The full 32-tool surface is convenient but inflates the agent's prompt-context c
103119
"codegraph.indexOnStartup": true,
104120
"codegraph.indexPaths": ["/path/to/project-a", "/path/to/project-b"],
105121
"codegraph.excludePatterns": ["**/cmake-build-debug/**", "**/generated/**"],
106-
"codegraph.embeddingModel": "bge-small",
122+
"codegraph.embeddingModel": "bge-small", // or "static" for ~100× faster indexing
123+
"codegraph.staticModelPath": "", // model2vec model dir when embeddingModel is "static"
107124
"codegraph.maxFileSizeKB": 1024,
108125
"codegraph.debug": false
109126
}
@@ -313,6 +330,12 @@ Additional tools available in [CodeGraph Pro](https://codegraph.astudioplus.com/
313330

314331
HTTP handler detection: Python (FastAPI/Flask/Django), TypeScript (NestJS), Java (Spring/JAX-RS), Go (stdlib/Gin/Echo/Fiber), C# (ASP.NET), Ruby (Rails), PHP (Laravel/Symfony).
315332

333+
> **Community vs full builds:** COBOL, Fortran, Perl, Dart, Zig, and R are
334+
> compiled only with `--features extra-languages`. The default community binary
335+
> omits them — they had zero usage in telemetry and their tree-sitter grammars
336+
> add ~25 MB (COBOL's parse tables alone are 30 MB). The other 32 languages are
337+
> always available.
338+
316339
---
317340

318341
## Architecture

crates/codegraph-memory/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ anyhow = "1.0"
4646
# Logging
4747
log = "0.4"
4848

49+
# Static (lookup-table) embeddings: HuggingFace tokenizer + a safetensors
50+
# token->vector matrix, mean-pooled. No ONNX — the fast indexing path.
51+
tokenizers = "0.21"
52+
safetensors = "0.4"
53+
half = "2"
54+
4955
# Embeddings - fastembed with BGE-Small-EN-v1.5
5056
# macOS/Linux: static link ONNX Runtime (ort-download-binaries)
5157
# Windows: load onnxruntime DLL at runtime (ort-load-dynamic, avoids CRT /MT vs /MD mismatch)

0 commit comments

Comments
 (0)