Member-only story

Neo4j+LangChain: How to Build the Strongest RAG System Based on Knowledge Graph?

Beck Moulton
9 min readNov 13, 2024

--

Source: Suman Gautam

Compilation: Active Water Intelligence

Since Neo4j announced its integration with LangChain, we have seen many use cases surrounding the construction of Retrieval Enhanced Generative (RAG) systems using Neo4j and Large Language Models (LLM). This has led to a rapid increase in the use of knowledge graphs in RAG in recent years. The performance of knowledge graph based RAG systems in handling hallucinations seems to be superior to traditional RAG systems. We also noticed that using proxy based systems can further enhance RAG applications. For this purpose, the LangGraph framework has been added to the LangChain ecosystem to add loops and persistence to LLM applications.

I will demonstrate how to create a GraphRAG workflow for Neo4j using LangChain and LangGraph. We will develop a fairly complex workflow that utilizes LLM in multiple stages and employs dynamic prompt word query decomposition techniques. We will also use a routing technique to split queries between vector semantic search and graph QA chains. Using LangGraph’s GraphState, we will enrich our prompt templates by extracting context from early steps.

The high-level example of our workflow is roughly shown in the following figure.

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet