# How to Integrate Code-Graph-RAG with CI/CD Pipelines

> Learn how to integrate Code-Graph-RAG with CI/CD pipelines. Orchestrate its parser and Memgraph backend using CLI commands to build knowledge graphs and validate code structure.

- Repository: [Vitali Avagyan/code-graph-rag](https://github.com/vitali87/code-graph-rag)
- Tags: how-to-guide
- Published: 2026-08-19

---

**Integrating Code-Graph-RAG into continuous integration workflows requires orchestrating its Tree-sitter parser and Memgraph backend via CLI commands that install dependencies, build the knowledge graph, and validate code structure against automated tests.**

The `vitali87/code-graph-rag` open-source project separates its functionality into two CI-friendly components: a multi-language parser that extracts symbols and relationships into a Memgraph graph database, and a RAG interface providing CLI and MCP server capabilities. Understanding how to integrate Code-Graph-RAG with CI/CD pipelines allows development teams to automate semantic code analysis, dead-code detection, and vector search validation on every pull request.

## Core CI/CD Architecture

The repository's architecture splits into distinct layers that map cleanly to pipeline stages. According to the source code structure, **the Multi-language Parser**—driven by Tree-sitter—walks codebases to extract symbols and optional runtime call edges, writing data into Memgraph. **The RAG Layer** provides a command-line interface (`cgr`) and an MCP server that translates natural-language queries into Cypher and executes semantic search.

Both layers expose deterministic CLI commands suitable for automation. The `cgr` tool manages Docker lifecycle operations, repository parsing, and validation gates, making it ideal for CI environments.

## Step-by-Step CI/CD Integration

### Install Build Dependencies

Begin by installing the Python package with full language support and semantic search capabilities. The [`README.md`](https://github.com/vitali87/code-graph-rag/blob/main/README.md) specifies using `uv` or `pipx` to install the `[treesitter-full]` and `[semantic]` extras, which compile Tree-sitter grammars and include the Qdrant vector store client.

```bash
uv tool install "code-graph-rag[treesitter-full,semantic]"

```

Ensure Docker, `cmake`, and `ripgrep` are available in the runner image, as these support native builds and file discovery operations used by the parser.

### Orchestrate the Graph Stack

Start the required services using the built-in daemon command. The `cgr daemon up` command launches Memgraph and Qdrant containers via Docker Compose, creating an isolated graph stack for the pipeline execution. This command is idempotent and safe to run in ephemeral CI environments.

```bash
cgr daemon up

```

### Parse and Index the Repository

Execute the parser against the checked-out codebase. The `cgr start` command with `--repo-path` and `--update-graph` flags triggers a full walk of the repository structure, populating Memgraph with nodes and edges representing functions, classes, and their relationships. Add the `--clean` flag for fresh graph initialization between runs.

```bash
cgr start --repo-path . --update-graph

```

### Execute Automated Tests

Run the project's test suite to validate graph integrity and RAG functionality. The `codebase_rag/tests/` directory contains integration tests that assert against graph state, including dead-code detection scenarios.

```bash
pytest -q

```

### Run Static Analysis and Linting

Execute pre-commit hooks via the `Makefile` to enforce code quality. The `make pre-commit` target runs `ruff` for formatting and linting, `ty` for type checking, and `bandit` for security analysis, mirroring the local development workflow documented in [`docs/contributing.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/contributing.md).

```bash
make pre-commit

```

### Cleanup and Teardown

Stop the Docker containers to prevent resource leakage between pipeline runs. The `cgr daemon down` command terminates Memgraph and Qdrant services.

```bash
cgr daemon down

```

## Complete GitHub Actions Workflow

The [`.github/workflows/ci.yml`](https://github.com/vitali87/code-graph-rag/blob/main/.github/workflows/ci.yml) file implements the complete integration pattern. This configuration checks out the repository, installs the tool with Astral's `uv-action`, orchestrates the graph stack, and executes the validation pipeline.

```yaml
name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python & uv
        uses: astral-software/uv-action@v1
        with:
          python-version: "3.12"
          
      - name: Install Code-Graph-RAG
        run: |
          uv tool install "code-graph-rag[treesitter-full,semantic]"
          
      - name: Start Memgraph & Qdrant
        run: cgr daemon up
        
      - name: Parse repository
        run: |
          cgr start --repo-path . --update-graph
          
      - name: Run tests
        run: |
          pytest -q
          
      - name: Lint with pre-commit
        run: make pre-commit
        
      - name: Stop services
        if: always()
        run: cgr daemon down

```

## Advanced CI/CD Patterns

### Dead Code Detection Gates

Implement quality gates using the dead-code detector to fail builds when unreachable functions are detected. The [`codebase_rag/tests/test_dead_code.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/tests/test_dead_code.py) demonstrates how to invoke this check with the `--fail-on-found` flag, treating dead code as a build failure.

```yaml
- name: Detect dead code
  run: |
    cgr dead-code --fail-on-found

```

### Python SDK Assertions

For custom validation logic, use the `GraphLoader` class from `codebase_rag.graph_loader` within test scripts to assert that specific graph nodes exist after parsing.

```python
from codebase_rag.graph_loader import GraphLoader

loader = GraphLoader(uri="bolt://localhost:7687")
nodes = loader.run_cypher(
    "MATCH (f:Function {name: 'main'}) RETURN f LIMIT 1"
)
assert nodes, "Function `main` should exist after parsing"

```

### Dependency Caching Strategies

Optimize pipeline performance by caching Docker layers for the Memgraph and Qdrant images between runs. Additionally, cache the `uv` tool installation directory to avoid recompiling Tree-sitter language bindings on every execution.

## Summary

- **Code-Graph-RAG** splits into a Tree-sitter parser and RAG layer, both accessible via the `cgr` CLI for automation.
- **Installation** requires the `[treesitter-full]` and `[semantic]` extras to enable multi-language parsing and vector search.
- **Service orchestration** uses `cgr daemon up` to launch Memgraph and Qdrant containers required for graph operations.
- **Repository indexing** executes via `cgr start --repo-path . --update-graph`, populating the knowledge graph from the CI checkout.
- **Quality gates** combine `pytest`, `make pre-commit`, and optional `cgr dead-code --fail-on-found` to enforce code standards.
- **Cleanup** ensures resources are released using `cgr daemon down` in workflow teardown steps.

## Frequently Asked Questions

### What container services does Code-Graph-RAG require in CI?

Code-Graph-RAG requires **Memgraph** for the knowledge graph database and **Qdrant** for vector storage when using semantic search features. The `cgr daemon up` command automatically configures and launches these containers via Docker Compose, binding to standard ports (Memgraph on 7687, Qdrant on 6333) for the duration of the pipeline.

### How do I cache Code-Graph-RAG dependencies for faster CI runs?

Cache the Docker images for `memgraph/memgraph` and `qdrant/qdrant` using your CI platform's cache action. For the Python toolchain, cache the `uv` tool directory and the installed package metadata. Since Tree-sitter grammars compile during installation, preserving the compiled artifacts between runs significantly reduces pipeline startup time.

### Can I integrate Code-Graph-RAG with GitLab CI or Azure Pipelines?

Yes, the `cgr` CLI commands are platform-agnostic. Configure GitLab CI or Azure Pipelines to use a Docker-enabled runner, install `uv`, execute `cgr daemon up` in a background or service step, run the parsing and test commands in script blocks, and ensure `cgr daemon down` runs in an after_script or cleanup phase. The MCP server documented in [`docs/guide/mcp-server.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/guide/mcp-server.md) can also be deployed as a long-running service in these environments.

### How do I securely handle API keys for the RAG LLM components?

Store API keys (such as OpenAI tokens) as encrypted secrets in your CI platform's secret management system. Expose them to the pipeline steps via environment variables (e.g., `OPENAI_API_KEY`), which the Code-Graph-RAG CLI and Python SDK read automatically. Never commit credentials to the repository; the `vitali87/code-graph-rag` codebase contains no hardcoded secrets and expects all sensitive configuration via environment variables.