Summary
Add an optional local embedding pass using a quantized model — leading candidate is Gemma 4 (Q4/Q8 via llama.cpp or ollama) — to generate semantically_similar_to edges across all nodes without any API calls.
Motivation
Currently, semantic similarity edges come from Claude's judgment during extraction — one pass per file, subjective, and costs API tokens. A local embedding pass would:
- Generate embeddings for every node (label + docstring) after the AST and semantic passes
- Add cosine-similarity edges above a configurable threshold, marked
INFERRED
- Make cross-file concept linking exhaustive rather than sampled
- Work fully offline, cached per-node alongside the existing SHA256 file cache
- Cost zero API tokens after the initial model download
The two approaches complement rather than replace each other — Claude finds the interesting cross-cutting edges, local embeddings find the exhaustive ones. Both end up in the same graph.
Design
Model: Gemma 4 Q4 or Q8 via llama.cpp or ollama. Produces strong semantic embeddings for code + text at ~2-4GB RAM, no GPU required.
Pipeline position: after Part C (build + cluster), before export. Reads all node labels + docstrings, generates embeddings in batch, computes pairwise cosine similarity, adds edges above threshold.
Threshold: configurable, default ~0.82. Exposed as --embed-threshold 0.82.
Backend: support both llama-cpp-python and ollama client, auto-detect which is available.
Caching: store embedding vectors in graphify-out/cache/embeddings.json keyed by node ID + content hash. Re-embedding only runs for new or changed nodes.
Skill flag: /graphify ./raw --embeddings to enable the pass. Off by default.
Install
pip install graphifyy[embeddings] # pulls llama-cpp-python
# or: ollama pull gemma4 && /graphify ./raw --embeddings
Acceptance criteria
Summary
Add an optional local embedding pass using a quantized model — leading candidate is Gemma 4 (Q4/Q8 via
llama.cpporollama) — to generatesemantically_similar_toedges across all nodes without any API calls.Motivation
Currently, semantic similarity edges come from Claude's judgment during extraction — one pass per file, subjective, and costs API tokens. A local embedding pass would:
INFERREDThe two approaches complement rather than replace each other — Claude finds the interesting cross-cutting edges, local embeddings find the exhaustive ones. Both end up in the same graph.
Design
Model: Gemma 4 Q4 or Q8 via
llama.cpporollama. Produces strong semantic embeddings for code + text at ~2-4GB RAM, no GPU required.Pipeline position: after Part C (build + cluster), before export. Reads all node labels + docstrings, generates embeddings in batch, computes pairwise cosine similarity, adds edges above threshold.
Threshold: configurable, default ~0.82. Exposed as
--embed-threshold 0.82.Backend: support both
llama-cpp-pythonandollamaclient, auto-detect which is available.Caching: store embedding vectors in
graphify-out/cache/embeddings.jsonkeyed by node ID + content hash. Re-embedding only runs for new or changed nodes.Skill flag:
/graphify ./raw --embeddingsto enable the pass. Off by default.Install
Acceptance criteria
--embeddingsflag triggers embedding pass after graph buildsemantically_similar_to, confidenceINFERRED, withconfidence_score= cosine similarity valuepip install graphifyy[embeddings]installs the right deps