Building A Smarter RAG - Implementing Graph-Based RAG With Neo4j - by Vinay Jain - Nov, 2024 - Medium
Building A Smarter RAG - Implementing Graph-Based RAG With Neo4j - by Vinay Jain - Nov, 2024 - Medium
Open in app
44
Search
Get unlimited access to the best of Medium for less than $1/week. Become a member
Flowchart of Graph-RAG
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 1/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Prerequisites
Before we dive in, make sure you have:
Python 3.10+
import os
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["NEO4J_URI"] = "your-neo4j-uri"
os.environ["NEO4J_USERNAME"] = "neo4j"
os.environ["NEO4J_PASSWORD"] = "your-password"
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 2/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
We’ll use Wikipedia data about Microsoft as our example. Here’s how to load and
split the data:
llm = ChatOpenAI(temperature=0)
llm_transformer = LLMGraphTransformer(llm=llm)
# Add to Neo4j
graph.add_graph_documents(
graph_documents,
baseEntityLabel=True,
include_source=True
)
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 3/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
vector_index = Neo4jVector.from_existing_graph(
OpenAIEmbeddings(),
search_type="hybrid",
node_label="Document",
text_node_properties=["text"],
embedding_node_property="embedding"
)
This retriever:
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 4/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
1. Higher Complexity
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 5/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
2. Performance Overhead
Next Steps
You can enhance this system by:
Conclusion
Graph-based RAG combines the best of both worlds: the semantic understanding of
vector search and the explicit relationships of graph databases. This makes your
RAG system not just able to find information, but also understand how different
pieces of information connect to each other.
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 6/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Follow
Vinay Jain
4d ago
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 7/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Vinay Jain
Aug 7, 2022
Vinay Jain
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 8/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Jun 25 3
Samar Singh
Oct 26 38
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 9/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
5d ago 4
Lists
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 10/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
2d ago 364 3
Pankaj
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 11/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Oct 31 58
JingleMind.Dev
Jul 30 30
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 12/13
2024/11/7 晚上10:59 Building a Smarter RAG: Implementing Graph-based RAG with Neo4j | by Vinay Jain | Nov, 2024 | Medium
Ignacio de Gregorio
5d ago 694 7
https://medium.com/@vinayjain449/building-a-smarter-rag-implementing-graph-based-rag-with-neo4j-570e105e2d4a 13/13