Knowledge Graphs : Adding Relations To RAG


📘Introduction
This article is part of the Advance RAG Series, an article series where the various tenets and features of a RAG system are explained through diagrams and code. This blog explains how Knowledge Graphs help improve the response of the RAG system by enabling it to efficiently understand relationships between the entities present the data which is given as input to the RAG system.
🔍What are Knowledge Graphs?
Before clarifying and explaining how Knowledge Graphs help optimise RAG systems. Let’s first explain “What is a Knowledge Graph ?’’.
A knowledge graph is made up of two words : Knowledge & Graph. Knowledge simply refers to the data and graphs refers to storing/converting the data into graph format.
📊Graph Format Explained
Graphs represents real world entites/objects called nodes and one node is connected to another node via an edge. The direction of node and the type of relationship between the nodes is also mentioned in the connecting edge.
💾Ways To Store Graphs
Graph DBs like Neo4j, Dgraph etc are among the most popular and widely used Graph DBs out there in the industry. DB like Neo4j provide native Graph DB rather than a wrapper like in case of PostgreSQL or MongoDB etc
🤖Vector Embeddings vs Knowledge Graphs in RAG Systems
Now one doubt which is important and common must be addressed that “Why should Knowledge Graph (Graph DB) be used if Vector Embeddings are already used in RAG System?”
Retrieval-Augmented Generation (RAG) often relies on vector embeddings for semantic search. However, this approach has several limitations. Knowledge Graphs (KGs) can complement embeddings by offering structured understanding and reasoning.
❌ Shortcomings of Vector Embeddings in RAG
No Awareness of Explicit Relationships
Embeddings measure semantic similarity, not structured knowledge.
Example: “Green tea” and “matcha” might be close in vector space, but embeddings don’t reveal that matcha is a type of green tea.
Context Confusion
Documents may be retrieved based on shared words rather than true relevance.
Example: A query on “plant-based protein for toddlers” might retrieve fitness blogs due to the word “protein.”
Loss of Hierarchical Information
- Embeddings flatten knowledge—concept hierarchies like “lentils → legumes → plant-based foods” are lost.
Limited Explainability
It’s difficult to trace why a document was retrieved.
This reduces trust, especially in domains like healthcare, education, or law.
Static Knowledge
Once trained, embeddings become outdated unless retrained.
They lack dynamic adaptability to new facts or relationships.
✅ How Knowledge Graphs Fill These Gaps
Explicit Relationship Representation
- Knowledge Graphs define facts like:
→ “Chickpeas → is a → Legume”
→ “Legumes → rich in → Protein”
→ “Suitable for → Toddlers”
- Knowledge Graphs define facts like:
Graph-Based Reasoning
- Queries can be answered through reasoning chains:
Chickpeas → Legume → Protein → Nutritional Needs → Toddlers
- Queries can be answered through reasoning chains:
Contextual Expansion and Filtering
- Knowledge Graphs help expand queries with related entities or eliminate irrelevant paths.
Transparency and Trust
- Reasoning paths (chains of relationships) offer explainable answers, boosting confidence.
Dynamic and Incremental Updates
- New facts can be added without retraining entire models.
🧠 Analogy: Semantic Search vs Structured Search
Think of semantic search (embeddings) like asking a well-read friend,
and structured search (KG) like checking an encyclopedia.
🧑 Semantic Friend: Understands your intent, guesses answers from experience—but can't always explain why.
📚 Structured Encyclopedia: Follows clear categories and links—takes longer, but gives traceable and factual responses.
⚠️ Complexities of Using Knowledge Graphs
Graph Construction
Non-linear format is tough to model. Where do one begin? How do one handle isolated nodes?
Graph traversal methods (like BFS) help, but require careful design.
Graph Retrieval
One can’t load the whole Knowledge Graph into the LLM. It’s like trying to explain every relationship in your life at once—too much, too messy.
Efficient subgraph retrieval based on query intent is crucial.
💼Knowledge Graph Use Cases
Common and popular use cases of Knowledge Graphs include :
📚References
🔚Conclusion
Integrating Knowledge Graphs with vector embeddings significantly enhances Retrieval-Augmented Generation (RAG) systems by bridging the gap between structured relationships and semantic understanding. While vector embeddings offer semantic similarity, Knowledge Graphs provide explicit, contextual relationships between entities. This synergy results in responses that are not only more accurate, but also efficient and contextually precise. By grounding Large Language Models (LLMs) in structured knowledge through graphs, RAG systems gain a powerful edge—delivering intelligent, relevant, and trustworthy answers rooted in both meaning and relationships.
Subscribe to my newsletter
Read articles from Garv directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Garv
Garv
A person trying to learn and question things.