Skip to content

arthurmgraf/graphmind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GraphMind

Autonomous Knowledge Agent Platform -- Agentic RAG powered by Knowledge Graphs, dual-engine orchestration, and self-evaluating retrieval pipelines.

Python 3.11+ Tests License: MIT


Architecture

GraphMind runs two orchestration engines over a shared hybrid retrieval layer. Queries enter through the API, select an engine, and pass through self-evaluation before returning an answer.

                          +------------------+
                          |   FastAPI / MCP   |
                          |   Streamlit UI    |
                          +--------+---------+
                                   |
                          engine = ?
                     +-------------+-------------+
                     |                           |
          +----------v----------+     +----------v----------+
          |      LangGraph      |     |       CrewAI        |
          |   (state machine)   |     |  (role-based crew)  |
          |                     |     |                     |
          |  Planner            |     |  Research Agent     |
          |    |                |     |  Analysis Agent     |
          |  Retriever Agent    |     |  Synthesis Agent    |
          |    |                |     |  QA Agent           |
          |  Synthesizer        |     |                     |
          |    |                |     |  Sequential process |
          |  Evaluator          |     |  with shared tools  |
          |    |                |     |                     |
          |  score < 0.7 ?      |     +----------+----------+
          |   yes -> retry (x2) |                |
          |   no  -> done       |                |
          +----------+----------+     +----------+
                     |                           |
                     +-------------+-------------+
                                   |
                    +--------------v--------------+
                    |    Hybrid Retrieval Layer    |
                    |                             |
                    |  +--------+   +---------+   |
                    |  | Qdrant |   |  Neo4j  |   |
                    |  | Vector |   |  Graph  |   |
                    |  +---+----+   +----+----+   |
                    |      |             |        |
                    |      +------+------+        |
                    |             |                |
                    |        RRF Fusion            |
                    +--------------+---------------+
                                   |
                    +--------------v--------------+
                    |       LLM Router            |
                    |  Groq -> Gemini -> Ollama   |
                    |    (cascading fallback)      |
                    +-----------------------------+

Key Features

  • Dual Orchestration Engines -- LangGraph state machine for deterministic pipelines; CrewAI role-based crew for collaborative multi-agent reasoning. Choose per query.
  • Hybrid Retrieval with RRF -- Combines Qdrant vector similarity search with Neo4j graph traversal, fused via Reciprocal Rank Fusion for higher recall and precision.
  • Self-Evaluation Loop -- The LangGraph evaluator scores every answer. Scores below 0.7 trigger an automatic rewrite and re-query cycle (max 2 retries).
  • Multi-Provider LLM Routing -- Cascading fallback across Groq, Google Gemini, and Ollama. If the primary provider is down or rate-limited, the next one picks up seamlessly.
  • Knowledge Graph Construction -- Automated entity and relation extraction from ingested documents, building a Neo4j graph that enriches retrieval context.
  • 7-Format Document Ingestion -- Markdown, PDF, TXT, HTML, DOCX, CSV, and JSON loaders with configurable chunking strategies.
  • NeMo Guardrails -- Input and output safety filtering via Colang flows to enforce content policies.
  • Full Observability -- Langfuse tracing, per-request cost tracking, and metrics collection across every pipeline stage.
  • Evaluation Suite -- DeepEval and RAGAS benchmarks measuring faithfulness, relevancy, and groundedness.
  • MCP Server -- Model Context Protocol integration for IDE tools (Claude Code, Cursor, VS Code).
  • Streamlit Dashboard -- Web UI for querying, document ingestion, knowledge graph statistics, and system health monitoring.
  • 85 Unit Tests passing across 10 test files.

Technology Stack

Component Technology Purpose
Orchestration LangGraph + CrewAI Dual-engine: state machine + role-based multi-agent crew
LLM Routing Groq / Gemini / Ollama Multi-provider with cascading fallback
Vector Store Qdrant Semantic similarity search
Graph Database Neo4j Entity-relationship traversal
Embeddings Ollama (nomic-embed-text) 768-dim local embeddings
Safety NeMo Guardrails Input/output filtering via Colang flows
Observability Langfuse Tracing, cost tracking, evaluation
Evaluation DeepEval + RAGAS Faithfulness, relevancy, groundedness metrics
API FastAPI REST endpoints for query, ingest, health
MCP Server Model Context Protocol IDE integration (Claude Code, Cursor, VS Code)
Dashboard Streamlit Web UI for queries, ingestion, and monitoring
Configuration Pydantic Settings Type-safe config with YAML overlay
Data Models Pydantic v2 13 shared models across the platform
Infrastructure Docker Compose Qdrant, Neo4j, PostgreSQL, Langfuse, Ollama

Quick Start

Prerequisites

  • Python 3.11+
  • Docker and Docker Compose
  • Groq API key (free at console.groq.com)

1. Clone and install

git clone https://github.com/arthurmgraf/graphmind.git
cd graphmind
pip install -e ".[dev,eval]"

2. Start infrastructure

docker compose up -d

This launches Qdrant, Neo4j, PostgreSQL, Langfuse, and Ollama.

3. Pull the embedding model

make pull-models

4. Configure environment variables

export GROQ_API_KEY="your-key-here"
# Optional:
export GEMINI_API_KEY="your-key-here"
export NEO4J_PASSWORD="your-password"

5. Run

# FastAPI server
make run
# or: graphmind

# Streamlit dashboard
make dashboard
# or: graphmind-dashboard

# MCP server (for IDE integration)
make mcp
# or: graphmind-mcp

6. Ingest documents

# Via CLI
graphmind-ingest path/to/document.md --type md

# Via API
curl -X POST http://localhost:8000/api/v1/ingest \
  -H "Content-Type: application/json" \
  -d '{"content": "# My Doc\n\nContent here.", "filename": "doc.md", "doc_type": "md"}'

7. Query

# LangGraph engine (default)
curl -X POST http://localhost:8000/api/v1/query \
  -H "Content-Type: application/json" \
  -d '{"question": "What is LangGraph?", "top_k": 10, "engine": "langgraph"}'

# CrewAI engine
curl -X POST http://localhost:8000/api/v1/query \
  -H "Content-Type: application/json" \
  -d '{"question": "Compare CrewAI and LangGraph", "engine": "crewai"}'

Project Structure

graphmind/
β”œβ”€β”€ config/                          # YAML configuration files
β”œβ”€β”€ diagrams/
β”‚   └── generated/                   # Exported diagrams (architecture, agents, data-flow)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ adrs/                        # Architecture Decision Records (5 ADRs)
β”‚   β”œβ”€β”€ getting-started.md
β”‚   β”œβ”€β”€ running.md
β”‚   β”œβ”€β”€ querying.md
β”‚   β”œβ”€β”€ ingestion.md
β”‚   β”œβ”€β”€ testing.md
β”‚   β”œβ”€β”€ deployment.md
β”‚   └── BUILD_REPORT.md
β”œβ”€β”€ eval/                            # Benchmark datasets and reports
β”œβ”€β”€ src/graphmind/
β”‚   β”œβ”€β”€ agents/                      # LangGraph nodes + orchestrator
β”‚   β”‚   β”œβ”€β”€ planner.py               #   Query planning and decomposition
β”‚   β”‚   β”œβ”€β”€ retriever_agent.py       #   Hybrid retrieval execution
β”‚   β”‚   β”œβ”€β”€ synthesizer.py           #   Answer generation
β”‚   β”‚   β”œβ”€β”€ evaluator.py             #   Self-evaluation with retry logic
β”‚   β”‚   β”œβ”€β”€ orchestrator.py          #   LangGraph state machine wiring
β”‚   β”‚   └── states.py                #   TypedDict state definitions
β”‚   β”œβ”€β”€ crew/                        # CrewAI multi-agent crew
β”‚   β”‚   β”œβ”€β”€ agents.py                #   Role definitions (Research, Analysis, Synthesis, QA)
β”‚   β”‚   β”œβ”€β”€ tasks.py                 #   Task specifications
β”‚   β”‚   β”œβ”€β”€ tools.py                 #   Shared tool wrappers
β”‚   β”‚   └── crew.py                  #   Crew assembly and kickoff
β”‚   β”œβ”€β”€ api/                         # FastAPI application
β”‚   β”‚   β”œβ”€β”€ main.py                  #   App factory and middleware
β”‚   β”‚   └── routes/                  #   query, ingest, health endpoints
β”‚   β”œβ”€β”€ dashboard/                   # Streamlit web UI
β”‚   β”‚   └── app.py                   #   Query, ingest, graph stats, system health
β”‚   β”œβ”€β”€ ingestion/                   # Document processing pipeline
β”‚   β”‚   β”œβ”€β”€ loaders.py               #   7 format loaders (MD, PDF, TXT, HTML, DOCX, CSV, JSON)
β”‚   β”‚   β”œβ”€β”€ chunker.py               #   Configurable text chunking
β”‚   β”‚   └── pipeline.py              #   End-to-end ingestion orchestration
β”‚   β”œβ”€β”€ knowledge/                   # Knowledge graph construction
β”‚   β”‚   β”œβ”€β”€ entity_extractor.py      #   LLM-based entity extraction
β”‚   β”‚   β”œβ”€β”€ relation_extractor.py    #   LLM-based relation extraction
β”‚   β”‚   β”œβ”€β”€ graph_builder.py         #   Neo4j graph population
β”‚   β”‚   └── graph_schema.cypher      #   Graph schema definition
β”‚   β”œβ”€β”€ retrieval/                   # Hybrid retrieval layer
β”‚   β”‚   β”œβ”€β”€ embedder.py              #   Ollama embedding client
β”‚   β”‚   β”œβ”€β”€ vector_retriever.py      #   Qdrant vector search
β”‚   β”‚   β”œβ”€β”€ graph_retriever.py       #   Neo4j graph traversal
β”‚   β”‚   └── hybrid_retriever.py      #   RRF fusion of vector + graph results
β”‚   β”œβ”€β”€ safety/                      # NeMo Guardrails
β”‚   β”‚   β”œβ”€β”€ guardrails.py            #   Guardrails integration
β”‚   β”‚   β”œβ”€β”€ config.py                #   Safety configuration
β”‚   β”‚   β”œβ”€β”€ config.yml               #   NeMo config file
β”‚   β”‚   └── rails.co                 #   Colang flow definitions
β”‚   β”œβ”€β”€ observability/               # Monitoring and tracing
β”‚   β”‚   β”œβ”€β”€ langfuse_client.py       #   Langfuse integration
β”‚   β”‚   β”œβ”€β”€ cost_tracker.py          #   Per-request cost tracking
β”‚   β”‚   └── metrics.py               #   Metrics collection
β”‚   β”œβ”€β”€ evaluation/                  # Evaluation framework
β”‚   β”‚   β”œβ”€β”€ deepeval_suite.py        #   DeepEval test suite
β”‚   β”‚   β”œβ”€β”€ ragas_eval.py            #   RAGAS evaluation metrics
β”‚   β”‚   β”œβ”€β”€ eval_models.py           #   Evaluation data models
β”‚   β”‚   └── benchmark.py             #   Benchmark runner
β”‚   β”œβ”€β”€ mcp/                         # Model Context Protocol server
β”‚   β”‚   └── server.py                #   MCP tool definitions
β”‚   β”œβ”€β”€ config.py                    # Pydantic Settings with YAML overlay
β”‚   β”œβ”€β”€ llm_router.py               # Multi-provider LLM routing with fallback
β”‚   └── schemas.py                   # 13 shared Pydantic models
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/                        # 85 unit tests across 10 files
β”‚   β”‚   β”œβ”€β”€ test_agents.py
β”‚   β”‚   β”œβ”€β”€ test_chunker.py
β”‚   β”‚   β”œβ”€β”€ test_config.py
β”‚   β”‚   β”œβ”€β”€ test_cost_tracker.py
β”‚   β”‚   β”œβ”€β”€ test_crew.py
β”‚   β”‚   β”œβ”€β”€ test_deepeval_suite.py
β”‚   β”‚   β”œβ”€β”€ test_hybrid_retriever.py
β”‚   β”‚   β”œβ”€β”€ test_loaders.py
β”‚   β”‚   β”œβ”€β”€ test_metrics.py
β”‚   β”‚   └── test_schemas.py
β”‚   β”œβ”€β”€ integration/                 # Integration tests
β”‚   └── conftest.py                  # Shared fixtures
β”œβ”€β”€ docker-compose.yml               # Qdrant, Neo4j, PostgreSQL, Langfuse, Ollama
β”œβ”€β”€ Makefile                         # Common commands
└── pyproject.toml                   # Project metadata and dependencies

Development

Testing

# Run all unit tests (85 tests across 10 files)
make test

# Run with coverage report
make test-all

# Run a specific test file
pytest tests/unit/test_agents.py -v

Linting and Formatting

make lint
make format

Evaluation Benchmark

# Run DeepEval + RAGAS evaluation suite
make eval

Orchestration Engines

GraphMind provides two orchestration engines. Choose per query via the engine parameter.

LangGraph -- State Machine Pipeline

A deterministic, graph-based pipeline where each node performs a single step. The evaluator node implements a self-correction loop: if the answer scores below 0.7, it rewrites the query and retries (up to 2 times).

Node Responsibility
Planner Decomposes the query into sub-questions and a retrieval strategy
Retriever Agent Executes hybrid retrieval (vector + graph + RRF)
Synthesizer Generates a grounded answer from retrieved context
Evaluator Scores the answer; triggers retry loop if quality is insufficient

CrewAI -- Role-Based Multi-Agent Crew

A collaborative crew of specialized agents that execute tasks sequentially, delegating and sharing context through CrewAI's built-in mechanisms.

Agent Role
Research Agent Retrieves and ranks relevant information
Analysis Agent Identifies patterns, contradictions, and gaps
Synthesis Agent Composes a coherent, well-structured answer
QA Agent Validates accuracy and completeness

When to Use Which

Criteria LangGraph CrewAI
Deterministic flow Yes No
Self-evaluation retry Built-in Via QA agent
Multi-perspective analysis Single pipeline Multiple agents collaborate
Best for Factual Q&A, precise retrieval Complex analysis, comparison tasks

MCP Integration

GraphMind exposes an MCP (Model Context Protocol) server for integration with AI-powered IDEs and tools.

Configuration

Add the following to your MCP client settings (Claude Code, Cursor, VS Code, etc.):

{
  "mcpServers": {
    "graphmind": {
      "command": "graphmind-mcp",
      "args": []
    }
  }
}

Available Tools

Tool Description
query Ask a question against the knowledge base
ingest Ingest a document into the system
graph_stats Retrieve knowledge graph statistics (entities, relations, counts)
health Check system health status of all components

Documentation

Document Description
Getting Started Installation and initial setup guide
Running How to run the API, dashboard, and MCP server
Querying Query API reference and engine selection
Ingestion Document ingestion formats and pipeline details
Testing Test suite structure, running tests, writing new tests
Deployment Production deployment guide
Build Report Full project build report

Architecture Decision Records

ADR Decision
ADR-001 Multi-Provider LLM Routing with cascading fallback
ADR-002 Hybrid Retrieval with Reciprocal Rank Fusion
ADR-003 LangGraph Agentic RAG pipeline design
ADR-004 MCP Server Integration for IDE tooling
ADR-005 Dual Engine architecture (LangGraph + CrewAI)

Diagrams

Architecture and data-flow diagrams are maintained as Excalidraw source files and exported to the diagrams/generated/ directory, organized into three categories:

diagrams/generated/
β”œβ”€β”€ agents/          # Agent interaction and delegation flows
β”œβ”€β”€ architecture/    # High-level system architecture
└── data-flow/       # Data ingestion and retrieval pipelines

Configuration

All settings are managed via config/settings.yaml with environment variable overrides. Configuration is loaded through Pydantic Settings, providing type safety and validation.

Variable Required Default Description
GROQ_API_KEY Yes -- Groq API key (primary LLM provider)
GEMINI_API_KEY No -- Google Gemini API key (fallback LLM)
NEO4J_PASSWORD Yes -- Neo4j database password
LANGFUSE_PUBLIC_KEY No -- Langfuse public key for observability
LANGFUSE_SECRET_KEY No -- Langfuse secret key for observability
QDRANT_URL No http://localhost:6333 Qdrant vector store URL
NEO4J_URI No bolt://localhost:7687 Neo4j connection URI
OLLAMA_BASE_URL No http://localhost:11434 Ollama API base URL

License

This project is licensed under the MIT License.


Author

Arthur Maia Graf -- arthurmgraf@hotmail.com

GitHub: github.com/arthurmgraf/graphmind

About

Autonomous Knowledge Agent Platform - Agentic RAG with Knowledge Graphs, hybrid retrieval, LangGraph agents, and MCP server

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages