# How to Start the Memgraph Daemon for Code-Graph-RAG: A Complete Guide

> Learn to start the Memgraph daemon for Code-Graph-RAG easily. Run the cgr daemon up command for a seamless setup with Memgraph and Qdrant containers.

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

---

**To start the Memgraph daemon for Code-Graph-RAG, run the `cgr daemon up` command, which automatically verifies Docker, renders the compose file, and launches both Memgraph and Qdrant containers with built-in health checks.**

Code-Graph-RAG stores parsed code graphs in a Memgraph database that runs inside a Docker-Compose stack. According to the `vitali87/code-graph-rag` source code, the recommended way to initialize this infrastructure is through the CLI utility `cgr`, which handles container orchestration, port configuration, and service health verification automatically.

## Prerequisites: Docker Installation

Before starting the Memgraph daemon, ensure Docker Engine is installed and running on your system. The `daemon_up` function in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py) performs a pre-flight check to verify Docker availability before attempting to start the stack.

Run this quick verification command:

```bash
docker info

```

If this returns container runtime details without error, your Docker daemon is ready for the Code-Graph-RAG stack.

## Starting the Memgraph Daemon with cgr daemon up

The primary method to start the Memgraph daemon uses the Code-Graph-RAG CLI. This approach renders the packaged [`docker-compose.yml`](https://github.com/vitali87/code-graph-rag/blob/main/docker-compose.yml) and manages the full lifecycle of the dependency stack.

### Step-by-Step Execution Flow

When you execute `cgr daemon up`, the system performs four critical operations as defined in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py):

1. **Docker Verification** – Confirms the Docker daemon is accessible and running.
2. **Compose File Rendering** – Copies the packaged compose file from [`codebase_rag/stack/constants.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/constants.py) (referenced via `cs.PACKAGE_COMPOSE_RELATIVE`) to `~/.cgr/compose.yml` if it doesn't exist.
3. **Stack Initialization** – Executes `docker compose -p cgr -f ~/.cgr/compose.yml up -d`, bringing up both **Memgraph** (port 7687) and the **Qdrant** vector store.
4. **Health Verification** – Runs `wait_for_memgraph` and `wait_for_qdrant` to ensure both services respond on their respective ports before returning control.

If the stack is already running, the command detects the existing state and skips redundant restarts.

Execute the daemon startup with:

```bash
cgr daemon up

```

### Verifying the Stack Status

After startup, confirm Memgraph is reachable using the built-in status command:

```bash
cgr daemon status

```

This displays the current stack state and reachable endpoints. To stream container logs for debugging:

```bash
cgr daemon logs memgraph

```

## Alternative: Manual Docker Start

For ad-hoc usage or development scenarios, you can start Memgraph directly without the full Code-Graph-RAG stack:

```bash
docker run -p 7687:7687 -p 7444:7444 memgraph/memgraph-platform

```

**Important:** Ensure these ports match the values configured in `settings.MEMGRAPH_HOST` and `settings.MEMGRAPH_PORT` (default `localhost:7687`) located in [`codebase_rag/config.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/config.py).

## Configuration and Default Ports

The Memgraph daemon configuration is centralized in [`codebase_rag/config.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/config.py). Key parameters include:

- **Port 7687** – Bolt protocol port for graph database connections
- **Port 7444** – HTTP API port for web interface and REST endpoints
- **Host** – Configurable via `settings.MEMGRAPH_HOST` (defaults to `localhost`)

These values must align with your Docker port mappings whether using `cgr daemon up` or manual Docker commands.

## Programmatic Stack Management

You can also start the Memgraph daemon programmatically using the Python SDK. This method is useful when integrating Code-Graph-RAG into larger applications or automation scripts:

```python
from codebase_rag.stack.manager import daemon_up

# Starts the stack and returns a StackStatus object

status = daemon_up()
print(f"Memgraph reachable at {status.memgraph_endpoint}")

```

The `daemon_up` function returns a `StackStatus` object containing connection endpoints and health status for both Memgraph and Qdrant services.

## Summary

- **Use `cgr daemon up`** to automatically start the full Docker-Compose stack including Memgraph and Qdrant with health checks.
- **Core implementation** resides in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py), specifically the `daemon_up`, `daemon_down`, `daemon_status`, and `daemon_logs` functions.
- **Default ports** are 7687 for Bolt protocol and 7444 for HTTP API, configurable in [`codebase_rag/config.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/config.py).
- **Health verification** commands include `cgr daemon status` for endpoint checking and `cgr daemon logs memgraph` for troubleshooting.
- **Manual alternative** uses `docker run` with `memgraph/memgraph-platform` image for standalone deployments.

## Frequently Asked Questions

### What should I do if `cgr daemon up` fails to start the containers?

First verify Docker is running with `docker info`. Then check `cgr daemon logs memgraph` to identify specific container errors. Common issues include port conflicts (7687 or 7444 already in use) or insufficient Docker permissions. Ensure no other Memgraph instances are binding to the default ports defined in [`codebase_rag/config.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/config.py).

### Can I run Memgraph without Qdrant for Code-Graph-RAG?

The `cgr daemon up` command is designed to start both services together as defined in the compose file referenced in [`codebase_rag/stack/constants.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/constants.py). While you can start Memgraph manually via Docker for isolated testing, the full Code-Graph-RAG functionality requires both the graph database (Memgraph) and the vector store (Qdrant) to be available.

### How do I stop the Memgraph daemon safely?

Use `cgr daemon down` to gracefully stop and remove the Docker-Compose stack. This command is implemented in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py) as the `daemon_down` function, which ensures proper container shutdown and cleanup of the stack named `cgr`.

### Where is the Docker-Compose file stored when using `cgr daemon up`?

The compose file is rendered to `~/.cgr/compose.yml` on first run, copied from the packaged template defined in [`codebase_rag/stack/constants.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/constants.py) under the constant `PACKAGE_COMPOSE_RELATIVE`. This local copy allows for user modifications while maintaining the original template in the package installation.