How to Start the Memgraph Daemon for Code-Graph-RAG: A Complete Guide
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 performs a pre-flight check to verify Docker availability before attempting to start the stack.
Run this quick verification command:
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 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:
- Docker Verification – Confirms the Docker daemon is accessible and running.
- Compose File Rendering – Copies the packaged compose file from
codebase_rag/stack/constants.py(referenced viacs.PACKAGE_COMPOSE_RELATIVE) to~/.cgr/compose.ymlif it doesn't exist. - Stack Initialization – Executes
docker compose -p cgr -f ~/.cgr/compose.yml up -d, bringing up both Memgraph (port 7687) and the Qdrant vector store. - Health Verification – Runs
wait_for_memgraphandwait_for_qdrantto 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:
cgr daemon up
Verifying the Stack Status
After startup, confirm Memgraph is reachable using the built-in status command:
cgr daemon status
This displays the current stack state and reachable endpoints. To stream container logs for debugging:
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:
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.
Configuration and Default Ports
The Memgraph daemon configuration is centralized in 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 tolocalhost)
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:
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 upto automatically start the full Docker-Compose stack including Memgraph and Qdrant with health checks. - Core implementation resides in
codebase_rag/stack/manager.py, specifically thedaemon_up,daemon_down,daemon_status, anddaemon_logsfunctions. - Default ports are 7687 for Bolt protocol and 7444 for HTTP API, configurable in
codebase_rag/config.py. - Health verification commands include
cgr daemon statusfor endpoint checking andcgr daemon logs memgraphfor troubleshooting. - Manual alternative uses
docker runwithmemgraph/memgraph-platformimage 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.
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. 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 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 under the constant PACKAGE_COMPOSE_RELATIVE. This local copy allows for user modifications while maintaining the original template in the package installation.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →