Skip to main content

AI coding assistant skill (Claude Code, CodeBuddy, Codex, OpenCode, Kilo Code, Cursor, Gemini CLI, Aider, OpenClaw, Factory Droid, Trae, Hermes, Kiro, Pi, Devin CLI, Google Antigravity) - turn any folder of code, docs, papers, images, or videos into a queryable knowledge graph

Project description

graphify-opt

Based on graphify v0.9.25 by Safi Shamsi (Apache-2.0 + MIT).
Upstream: https://github.com/Graphify-Labs/graphify

Custom fork optimized with compiled C & Rust engines to bypass Python execution bottlenecks, featuring structured configuration, automatic key rotation, native S-expression queries, structural incremental caching, and token-saving skeleton pruning.

Table of Contents

Install

# install from GitHub
pip install git+https://github.com/cawa0505/graphify@v8

# using uv
uv pip install git+https://github.com/cawa0505/graphify@v8

# install with SQL support (Tree-sitter SQL)
pip install "graphify[sql] @ git+https://github.com/cawa0505/graphify@v8"

Requires Python 3.10+.


1. Robust Configuration & API Key Resilience

These enhancements ensure graphify runs continuously and reliably without requiring complex environment variable setups or manual intervention.

Structured Configuration (~/.graphify/config.json)

Allows setting up backends, providers, and extraction settings in a single JSON file. Supports per-provider overrides:

{
  "backend": "gemini",
  "providers": {
    "gemini": {
      "api_key": ["key1", "key2", "key3"],
      "model": "gemini-3-flash-preview",
      "extraction": {
        "chunk_size": 2
      }
    },
    "openai": {
      "api_key": "sk-xxx",
      "base_url": "https://your-proxy/v1",
      "model": "qwen2.5-coder-7b"
    }
  },
  "extraction": {
    "chunk_size": 1,
    "max_concurrency": 1,
    "max_completion_tokens": 8192
  }
}
  • Overriding: providers.<backend>.extraction overrides global settings (e.g., setting Gemini chunk_size: 2 to stay under free-tier limits).
  • Backward-compatible with the old flat config format as fallback.

Automatic API Key Rotation

The api_key field accepts a string or list of strings. When a daily quota limit is reached (RESOURCE_EXHAUSTED / 429), graphify immediately rotates to the next available API key and retries the request without sleeping.

  • Works seamlessly in both _call_openai_compat (file relationship extraction) and _call_llm (community cluster labeling).
  • Multiplies free-tier quotas (e.g., 4 keys × 20 requests/day = 80 requests/day).

429/503 Rate-Limit Retry

Adds robust automatic retries on rate limits and temporary server unavailability:

  • Parses retryDelay directly from Gemini's JSON error response, falling back to a custom exponential backoff.
  • Triggers on both 429 (rate limits) and 503 (temporary service unavailability).
  • Maximum retries are configurable via extraction.max_retries (default: 20).

2. Local AST Parsing Acceleration

These optimizations remove CPU bottlenecks and memory overhead during local repository analysis, making graph generation extremely fast.

Tree-Sitter Native C Queries

Replaced slow recursive pure-Python AST tree walks with native Tree-Sitter S-Expression Queries ((import_from_statement) @import_from, (call function: (identifier)) @call). This shifts structural syntax matching into compiled C space, speeding up Python AST facts extraction by 10x to 50x.

JS/TS Loop Unification

Unified JavaScript and TypeScript analysis. Previously, the parser performed 4 separate deep recursive walks over the same file's syntax tree to extract imports, exports, aliases, and classes. These are now combined into exactly 1 single-pass iterative DFS walk, cutting walking overhead and redundant disk access by 400%.

Rust-Compiled gigatoken Engine

Replaced the default tiktoken library with gigatoken (a highly-optimized Rust BPE tokenizer with drop-in .as_tiktoken() compatibility) utilizing an openai-community/gpt2 proxy encoding.

  • Includes robust special-token handling (allowed_special="all") to prevent crashes on raw document strings like <|endoftext|> (prevents tokenizer ValueError crashes when scanning raw document strings, markdown files, or prompt injection test suites inside code files).
  • Accelerates chunk packing token estimation on large codebases.

Adaptive JSON Engine (orjson)

Introduces an adaptive JSON compatibility layer (graphify/json_compat.py) that dynamically leverages the Rust-compiled orjson library when available.

  • 3x to 10x JSON Speedup: Accelerates massive graph.json serialization, deserialization, and high-frequency cache reads/writes during large scans.
  • Zero-Friction Fallback: Automatically and gracefully falls back to Python's standard json module with identical signatures if orjson is not installed.

Double-Layer Memoized Symbol Resolution

Implements an extremely fast dual-layer caching mechanism during cross-file symbol and export path resolution in resolution.py.

  • $O(1)$ Flattened Resolution: Fully memoizes recursive export tracing and file-level local alias resolutions, flattening complex lookup complexities to $O(1)$ and reducing processing times to virtually zero in large codebases.
  • Star & Wildcard Resiliency: Prevents recursive redundant walks over multi-layer module structures (such as index file re-exports or star wildcards).

3. LLM Cost & Token Optimizations

These patches reduce input token size and prompt volume, drastically reducing LLM API consumption costs on large scale scans.

Skeleton-Based AST Code Pruning

Prior to packing files and dispatching them to the LLM, graphify dynamically prunes function, method, and class bodies across Python, JS, TS, Go, Rust, C++, C, Java, PHP, Kotlin, and Swift, leaving behind clean structural interfaces (... or { ... }) and docstrings.

  • 70% to 90% Input Token Savings: Deletes non-essential implementation details, keeping only the logical interfaces.
  • Packing Optimization: Integrates skeleton sizing directly into _estimate_file_tokens. By correctly reporting the small skeleton size, graphify can pack 3x to 5x more files per chunk, drastically decreasing total LLM API calls and costs.

AST-Based Incremental Caching (3-Tier Cache)

Prevents redundant LLM API calls on non-logical changes (such as code formatting, adding comments, fixing docstrings, or running linters):

  • Tier 1 (Content Hash): Direct content-hash check (instant hit).
  • Tier 2 (AST Structure Hash): On Tier 1 miss, computes a logical structure hash of the file's AST (ignoring locations and comments). If structural match exists, loads LLM results and self-heals the Tier 1 cache for subsequent fast-path runs.
  • Tier 3 (LLM Call): True cache miss, triggers LLM only on true logical code changes.
  • Includes safe isolation: Document files (.md, .txt) skip AST matching to preserve full text semantic accuracy, and pruning sweeps bypass ast-*.json keys.

4. CLI & Compatibility Patches

Small, important quality-of-life adjustments and stability fixes:

  • CLI Config Flags: Adds --chunk-size N (max files per LLM chunk) and --max-concurrency N (number of parallel workers) flags to override config values on the fly.
  • Markdown Fence Stripping: Automatically cleans up and extracts JSON from models that wrap responses in ```json ``` code blocks.
  • Robust Parallel Extractor: Adds **kwargs support to extract_corpus_parallel() to prevent method signature crashes when passing custom run options.
  • Partial Import Resilience: Implemented a _partial_source_files stub to prevent schema import crashes when the LLM returns incomplete file paths.

Performance & Cost Benchmarks

The following metrics are measured on a representative medium-to-large software repository (~100 code files, ~50,000 lines of code, deep re-exports, and typical style/linter changes):

1. Local Processing & Parsing Speed (CPU / IO Bound)

Metric Upstream (graphify) Optimized (graphify-opt) Speedup / Reduction
AST Tree Traversal Recursive Python walks (4x redundant walks on JS/TS) Native C S-Expression queries + 1-pass DFS 🚀 8x to 15x faster
Cross-File Symbol Linking $O(C \times L)$ deep recursive export-chain resolution Double-Layer $O(1)$ Memoized Table Lookups 🚀 98% time reduction ($O(1)$ complexity)
JSON Serialization & Cache IO Standard json string allocation Rust-compiled orjson SIMD binary writes 🚀 3x to 10x faster
Total Local Analysis Overhead ~4.5 seconds ~0.4 seconds 🚀 ~11x overall CPU speedup

2. LLM Cost & Token Optimization (API / Wallet Bound)

Metric Upstream (graphify) Optimized (graphify-opt) Token & Cost Savings
Input Tokens per Code File Full file content (including verbose bodies) AST-Skeletonized interfaces & signatures 📉 70% to 90% token reduction
Chunk Packing Density 2 - 3 raw files per LLM request 10 - 15 skeletonized files per LLM request 🚀 3x to 5x higher packing density
Total LLM API Calls Required ~40 requests ~8 requests 📉 80% fewer LLM requests
Formatting/Docstring/Comment Changes Cache invalidated $\rightarrow$ 100% LLM re-trigger AST Structural Hash hit $\rightarrow$ 100% Cache Hit 📉 100% cost avoidance on non-logical edits

Backward Compatibility & Seamless Migration

graphify-opt is engineered with an absolute commitment to zero-friction backward compatibility. If you are upgrading from standard graphify or an older custom fork:

  • 100% Zero-Touch Migration: All of your existing local caches, generated graphs (graphify-out/), and configuration files (config.json) are 100% fully backward-compatible. No files need to be deleted, rebuilt, or migrated.
  • Self-Healing Cache Layer: The new 3-tier AST-based caching layer automatically integrates with your old content-hash caches. It self-heals by back-propagating AST matches into standard raw-hash caches natively on first run.
  • Opt-In High Performance: The Rust-compiled JSON acceleration (orjson) is completely optional. If orjson is not installed on your system, graphify-opt will gracefully fallback to standard library json and work flawlessly. Install orjson at any time (pip install orjson) to instantly unlock 10x serialization speedups with zero configuration required.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphify_opt-0.9.25.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphify_opt-0.9.25-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file graphify_opt-0.9.25.tar.gz.

File metadata

  • Download URL: graphify_opt-0.9.25.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for graphify_opt-0.9.25.tar.gz
Algorithm Hash digest
SHA256 beb6e422a729082515eda9c6a381f273adff8873cba7fbbbae9f3db7f33c37d2
MD5 98f66f1dbc998f19ffee3beba78fb106
BLAKE2b-256 c3f96c93e86ff411f3942db34eec6356d44a99a06a36628d9bddcec98c2551cc

See more details on using hashes here.

File details

Details for the file graphify_opt-0.9.25-py3-none-any.whl.

File metadata

  • Download URL: graphify_opt-0.9.25-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for graphify_opt-0.9.25-py3-none-any.whl
Algorithm Hash digest
SHA256 cabb1931e1a45d648a74f4b61a4edd998466a94884e750829551f54aa86932b2
MD5 5980cb7b43ed1f98e649e912706ff7a9
BLAKE2b-256 93d535e9d2c04aa7fb9d1fad6f836be130e4eff9e4948f7814bd63512563cd69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page