Intro (one sentence) A hands-on guide by the channel creator showing how to add knowledge graphs to a RAG template in N8N using Graffiti MCP and Neo4j.
Core idea
- Knowledge graphs provide relational context that complements vector databases in RAG, enabling navigation across entities and relations (e.g., company β executives) that vectors alone struggle with. π
- Practical goal: run a self-hosted workflow that builds a knowledge graph in parallel with the vector store and use KG queries for relational questions, while keeping the original vector-based retrieval intact. π
What changes were made
- New components: Graffiti MCP server, Neo4j, self-hosted N8N. βοΈ
- Two new nodes in the template:
- One to insert into the knowledge graph (via Graffiti MCP).
- One to query/search the knowledge graph (via Graffiti MCP).
- Relationship to the existing vector DB workflow: data is stored both as vectors and as KG nodes/edges; KG enhances relational querying while vector DB handles general semantic search. π
How it works
- Data flow: data from sources is chunked, stored as vectors, and simultaneously used to populate the knowledge graph; both processes run in parallel. ποΈπ€
- When to search the KG vs the vector DB: use KG for relational/connected-entity questions; use vector DB for broad, standalone semantic lookups; the system prompt can steer which path to use. π§ π
- How the two MCP tools are used:
- Add memory to insert into the knowledge graph.
- Search memory to query the knowledge graph during the agentβs pipeline. π§©
Setup & prerequisites (high-level steps)
- Self-hosted environment (e.g., N8N on Digital Ocean); cloud versions arenβt covered. π₯οΈβοΈ
- Docker Compose to run Graffiti MCP and Neo4j; configure environment variables (OpenAI API key, model) and Neo4j credentials. βοΈπ³
- Networking tweaks: host.docker.in and lightweight firewall rules (via UFW) to securely connect N8N to the MCP server. π
- Installing the MCP node in N8N and testing the MCP connection (community MCP node in N8N) to verify tools are visible. π§°
Demos and results (summary)
- Example runs: overview of a company; Dr. Tanaka and Dr. Chen; and a test event that inserts content into the knowledge graph. π©π½βπΌπ¨π»βπΌ
- Performance note: knowledge graphs are slower and more expensive than pure vector pipelines; expect queuing and added overhead in KG workflows. β³π‘
Pros, cons, and caveats
- Pros: richer relational querying, complements vector DB, enables navigation through connected entities. ππ§
- Cons: slower setup, more complexity, best for relational data and richer queries. π’
- Caveats: assess use cases where KG offers clear advantages over a simple vector DB; consider security and data governance when exposing KG access. βοΈπ
Practical takeaways and next steps
- When to consider knowledge graphs in RAG: use KG for relational data, complex entity relationships, and queries that require navigating connections between nodes. πΊοΈ
- References to related content and next steps: explore related Graffiti KG guides and Python-based knowledge graphs content for broader context and future enhancements. π
Optional: quick-start checklist
- Set up a self-hosted N8N environment (e.g., on Digital Ocean). π§
- Run Docker Compose to launch Graffiti MCP and Neo4j; configure OpenAI API key and model. π
- Adjust networking and firewall (host.docker.in, restricted IP access). π§
- Install the N8N community MCP node and verify connection to Graffiti MCP. π§©
- Add two MCP tools to the workflow: add memory (insert KG) and search memory (query KG). βοΈ
- Run a test event to populate the KG and verify KG-based vs vector-based retrieval paths. π
- Monitor performance and decide if KG adds value for your data, then iterate.
Final takeaway Knowledge graphs add a relational dimension to RAG in N8N, enabling targeted, graph-aware queries when data relationships matterβand they sit alongside, not replace, the vector pipeline. βοΈπ§