Skip to content

Latest commit

 

History

History
321 lines (226 loc) · 14.1 KB

installation.md

File metadata and controls

321 lines (226 loc) · 14.1 KB
description Install Code-Graph-RAG and choose a graph backend for multi-language codebase analysis.

Installation

Prerequisites

  • Python 3.12+ (see Older system interpreters if your distribution ships an older Python)
  • ripgrep (rg) (required for shell command text searching)
  • Only for the optional Memgraph backend: Docker & Docker Compose, and cmake where no pymgclient wheel fits your platform
  • For cloud models: Google Gemini API key, OpenAI API key, or both
  • For local models: Ollama installed and running
  • uv package manager (recommended) or pip

Installing ripgrep (and cmake for Memgraph)

=== "macOS"

```bash
brew install cmake ripgrep
```

If `pymgclient` has no prebuilt wheel for your platform (for example older
macOS x86_64 setups) and pip falls back to building it from source, the
build also needs Homebrew's OpenSSL and, if CMake cannot find it,
`pkg-config`:

```bash
brew install pkg-config openssl
export OPENSSL_ROOT_DIR="$(brew --prefix openssl)"
export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$PKG_CONFIG_PATH"
```

Then run the `pip install` command from
[Install from PyPI](#install-from-pypi) below (or rerun the one that just
failed) in the same shell so the variables are picked up. See
[Troubleshooting](../advanced/troubleshooting.md) for the symptoms this
fixes.

=== "Ubuntu/Debian"

```bash
sudo apt-get update
sudo apt-get install cmake ripgrep
```

=== "CentOS/RHEL"

```bash
sudo yum install cmake
sudo dnf install ripgrep
```

ripgrep may need to be installed from EPEL or via `cargo install ripgrep`.

Older system interpreters

The wheel is pure Python (py3-none-any), but it requires cgr-graph-rs, the native extension that does the work behind it, which ships for CPython 3.12 or newer on Linux (x86_64, aarch64), macOS and Windows x64. cgr does not run without it, so it installs on those platforms only, and the interpreter floor is strict. Some distributions ship a Python below it: Debian Bookworm, and therefore Raspberry Pi OS Bookworm, ships Python 3.11. This is also why the piwheels Bookworm build shows as failed; it is the interpreter version, not a problem with the package.

Pin the interpreter explicitly on those systems. For a tool install, uv downloads Python 3.12 itself:

uv tool install --python 3.12 "code-graph-rag[treesitter-full,ast-grep,semantic]"

To work in a virtual environment instead, create it with the pinned interpreter so pip inside it actually uses 3.12:

uv venv --python 3.12 --seed && source .venv/bin/activate

Without uv, install CPython 3.12 yourself and call it directly:

python3.12 -m pip install "code-graph-rag[treesitter-full,ast-grep,semantic]"

Dependencies may still need platform wheels or build tools, such as cmake for pymgclient, which only the memgraph extra installs.

Install from PyPI

pip install code-graph-rag

uv venv --python 3.12 --seed, then pip install code-graph-rag and cgr --version in a fresh virtual environment

PyPI served 0.1.38 when this was recorded; it trails main (see Install from git).

Python, C, C++ and Lean 4 parse on the plain install: C and C++ with the patched grammars compiled into cgr-graph-rs, which keep the declarations the upstream grammars drop after a #define whose value contains a block comment, and Lean 4 with the grammar compiled in beside them, as it has no grammar package. With all Tree-sitter grammars (Python, JS, TS, Rust, Go, Java, Scala, C, C++, Lua, PHP, C#, Dart):

pip install 'code-graph-rag[treesitter-full]'

Ruby, Kotlin, Swift, Elixir, Haskell, Solidity, Bash and Nix are parsed by the ast-grep tier, which is its own ast-grep extra. Without it their files are indexed as bare File nodes, and a sync that meets them says so in a warning:

pip install 'code-graph-rag[treesitter-full,ast-grep]'

With semantic code search (UniXcoder embeddings):

pip install 'code-graph-rag[semantic]'

Its vectors go to a SQLite file beside the graph (~/.cgr/vectors.sqlite), so no server or Docker is needed. Set CGR_VECTOR_STORE_BACKEND=qdrant to use Qdrant instead; see Semantic Search.

With both full language support and semantic search:

pip install 'code-graph-rag[treesitter-full,ast-grep,semantic]'

With compiler-backed C/C++ facts:

pip install 'code-graph-rag[treesitter-full,cpp]'

The cpp extra installs libclang. Semantic C/C++ indexing also needs a compile_commands.json; see C/C++ Semantic Mode for frontend modes and setup commands.

uv tool install does not precompile bytecode by default, so the first cgr run after an install or upgrade compiles every module it imports and takes several seconds. Pass --compile-bytecode to do that work at install time instead:

uv tool install --compile-bytecode "code-graph-rag[treesitter-full,ast-grep,semantic]"

Install from git

PyPI and GitHub Releases only receive every 50th version, plus any security fix, breaking change or merge labelled release now, so they usually trail main by tens of versions. To run the newest code, install straight from the repository:

uv tool install "code-graph-rag[treesitter-full,ast-grep,semantic] @ git+https://github.com/vitali87/code-graph-rag@main"

Replace @main with a tag such as @v0.1.8 to pin an exact version.

Use uv here: it applies the project's [tool.uv.sources], which build the forks' Python packages of the C and C++ grammars, and that needs a C compiler on top of the prerequisites (the Xcode Command Line Tools on macOS). However it is installed, cgr parses C and C++ with the patched grammars compiled into cgr-graph-rs, which keep the declarations the upstream grammars drop after a #define whose value contains a block comment.

Install from Source

git clone https://github.com/vitali87/code-graph-rag.git
cd code-graph-rag

For basic Python support:

uv sync

For full multi-language support:

uv sync --extra treesitter-full --extra ast-grep

For full multi-language support with compiler-backed C/C++ facts:

uv sync --extra treesitter-full --extra ast-grep --extra cpp

For development (including tests and pre-commit hooks):

make dev

This installs all dependencies and sets up pre-commit hooks automatically.

Upgrade

cgr has no self-update command; upgrade it with the tool that installed it:

Installed with Upgrade with
uv tool install (PyPI or git) uv tool upgrade code-graph-rag
pipx install from PyPI pipx upgrade code-graph-rag
pipx install from git pipx reinstall code-graph-rag
pip install pip install --upgrade 'code-graph-rag[treesitter-full,ast-grep,semantic]'
Source checkout git pull, then rerun your uv sync command

The uv and pipx commands keep the extras you installed with; with pip, repeat them. An upgrade never adds an extra, so an install made without ast-grep gains it only by installing again with it, as under Install from PyPI. A uv git install moves to the newest commit on the branch it was installed from. For a git install, pipx upgrade skips any new commit that did not change the version number, so pipx reinstall is the reliable choice there. uv tool upgrade --all upgrades every tool uv manages in one go.

Check the result with:

cgr --version

cgr --version printing the installed code-graph-rag version

From Qdrant to the sqlite vector store

Semantic search keeps its vectors in a SQLite file, ~/.cgr/vectors.sqlite, by default; Qdrant was the default before. An install that never chose a backend switches on upgrade: each project's next sync embeds it again into the new file, even with nothing in the checkout changed, and the vectors in Qdrant are left where they are, no longer searched. Nothing starts Docker for them. To keep Qdrant, set CGR_VECTOR_STORE_BACKEND=qdrant; an install that sets QDRANT_URL or QDRANT_DB_PATH without it is told so once. A pip install gets the new store's sqlite-vec by repeating the semantic extra, as above.

Verify Release Artifacts

Each GitHub release ships prebuilt binaries together with Sigstore signatures (*.sigstore.json); releases from v0.0.484 onwards also carry a SLSA build provenance attestation (multiple.intoto.jsonl). Both are produced by the build-binaries.yml GitHub Actions workflow using keyless signing, so there is no maintainer-held key to obtain: verification checks that the artifact was built by this repository's release workflow.

To verify provenance with the GitHub CLI:

gh attestation verify code-graph-rag-linux-amd64 \
  --repo vitali87/code-graph-rag \
  --signer-workflow vitali87/code-graph-rag/.github/workflows/build-binaries.yml

The --signer-workflow flag pins the attestation to the release workflow itself; --repo alone accepts an attestation signed by any workflow in the repository.

To verify a signature with cosign:

cosign verify-blob \
  --bundle code-graph-rag-linux-amd64.sigstore.json \
  --certificate-identity-regexp 'https://github\.com/vitali87/code-graph-rag/\.github/workflows/build-binaries\.yml@.*' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  code-graph-rag-linux-amd64

Substitute the binary name for your platform.

Each binary also ships with a CycloneDX software bill of materials, code-graph-rag-<platform>-<arch>.cdx.json, listing the Python packages that platform's binary is built from with their versions and declared licences. It is signed and covered by the provenance attestation like the binary, so the commands above verify it too. The Docker image on ghcr.io carries an SPDX SBOM attestation for each platform:

docker buildx imagetools inspect ghcr.io/vitali87/code-graph-rag:latest \
  --format '{{ json .SBOM }}'

Packages installed from PyPI are protected differently: pip and uv verify package hashes, which proves integrity in transit, and releases after v0.0.187 additionally carry a PEP 740 attestation. That is a publish attestation — proof that the file was uploaded by this project's trusted publisher — rather than build provenance, and it can be queried through PyPI's Integrity API.

Choose a Graph Backend

Nothing to start by default: the graph is an embedded SQLite file, ~/.cgr/graph.sqlite (SQLITE_GRAPH_PATH moves it), written and queried in process through the same Cypher the other backends run. How it works, and how it compares with Memgraph, is in Graph Backends.

Memgraph (optional)

Install the driver with the memgraph extra (for example uv tool install "code-graph-rag[treesitter-full,memgraph]"), set GRAPH_BACKEND=memgraph, and start the packaged stack:

cgr daemon up

cgr daemon up reporting the Memgraph and Qdrant stack as running and reachable

Recorded with the stack already running, so it returns at once.

This starts the packaged Memgraph + Qdrant stack and waits until it is healthy. It works the same whether you installed from PyPI or from source, since the compose file ships inside the package. Memgraph listens on port 7687 and Memgraph Lab on port 3000. The services are reachable only from this machine and run without authentication by default; to require credentials, see Turning on authentication.

Set Up Environment Variables

cp .env.example .env
# Edit .env with your configuration

See the Configuration guide for all available options.

Verify Your Setup

cgr doctor

cgr doctor checking Docker, Memgraph, the configured models and ripgrep

No Ollama or API key is configured on the recording machine, so the two model checks fail.

This checks that all required dependencies and services are available.

Key Dependencies

  • loguru: Python logging made (stupidly) simple
  • mcp: Model Context Protocol SDK
  • opentelemetry-api: OpenTelemetry Python API
  • jsonschema: An implementation of JSON Schema validation for Python
  • pydantic-ai-slim: AI Agent Framework, the Pydantic way, slim package
  • pydantic-settings: Settings management using Pydantic
  • python-dotenv: Read key-value pairs from a .env file and set them as environment variables
  • tiktoken: tiktoken is a fast BPE tokeniser for use with OpenAI's models
  • tree-sitter-python: Python grammar for tree-sitter
  • tree-sitter: Python bindings to the Tree-sitter parsing library
  • watchdog: Filesystem events monitoring
  • typer: Typer, build great CLIs. Easy to code. Based on Python type hints.
  • rich: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
  • prompt-toolkit: Library for building powerful interactive command lines in Python
  • diff-match-patch: Repackaging of Google's Diff Match and Patch libraries.
  • click: Composable command line interface toolkit
  • protobuf
  • pyyaml: YAML parser and emitter for Python
  • pathspec: Utility library for gitignore style pattern matching of file paths.
  • pygments: Pygments is a syntax highlighting package written in Python.
  • httpx: The next generation HTTP client.
  • certifi: Python package for providing Mozilla's CA Bundle.
  • regex: Alternative regular expression module, to replace re.
  • cgr-graph-rs: Native acceleration for code-graph-rag's embedded graph