Skip to content

v0.4.0: local embeddings via quantized Gemma 4 (no API cost) #7

Open

Description

@safishamsi

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

  • --embeddings flag triggers embedding pass after graph build
  • Edges added as semantically_similar_to, confidence INFERRED, with confidence_score = cosine similarity value
  • Embedding cache works — re-run on unchanged corpus adds zero new embeddings
  • Works with both llama-cpp-python and ollama backends (auto-detected)
  • pip install graphifyy[embeddings] installs the right deps
  • Benchmark: show how many additional similarity edges embeddings find vs Claude-only extraction on the Karpathy corpus

Activity

  1. paulerbear commented on Apr 8, 2026

    @paulerbear

    Great addition! Local inference support is deeply appreciated.

  2. added 2 commits that reference this issue on May 6, 2026
  3. bcdiaconu commented on May 12, 2026

    @bcdiaconu

    from my perspective, the local term should be extended to local network, for the ones using an embedding LLM on a local network PC with an OpenAPI compatible API at either IP address of FQDN. eg: http://192.168.10.10:8043/v1 or http://inference.local:8043/v1

  4. FolatheDuckofDuckingburg commented on May 27, 2026

    @FolatheDuckofDuckingburg
    Contributor

    How should we handle model downloads? Should graphify manage that or assume the user has ollama/llama.cpp already set up?

  5. TPAteeq commented on Jun 2, 2026

    @TPAteeq
    Contributor

    Would it be better to swap out Ollama for ONNX Runtime here, and pull Gemma 4 from Hugging Face instead.
    If it sounds good and you'd want to go this route, I'm happy to start working on the PR.

    @safishamsi

  6. FolatheDuckofDuckingburg commented on Jun 2, 2026

    @FolatheDuckofDuckingburg
    Contributor

    We should pull Gemma 4 from Hugging Face so we should work on the PR.
    @TPAteeq

  7. added a commit that references this issue on Jun 19, 2026
  8. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions