Introduction
"Convert any text to a graph of knowledge. Graph Retrieval Augmented Generation (GRAG) — a new and improved version of RAG."
This is Part 61 of the "One Open Source Project a Day" series. Today's project is knowledge_graph (GitHub).
Want to turn documents and PDFs into queryable, visualizable knowledge graphs? knowledge_graph uses an LLM to extract concepts (not entities), build nodes and edges, and supports GRAG (Graph Retrieval Augmented Generation), centrality analysis, and community detection. No-GPT approach: local Mistral 7B + Ollama, zero API cost, Docker one-click run.
What You'll Learn
- Knowledge graph construction pipeline
- Concepts vs entities
- Dual weights: W1 (semantic) and W2 (contextual proximity)
- GRAG vs RAG
- Local Ollama + Docker quick start
Prerequisites
- Basic understanding of RAG and knowledge graphs
- Docker or local Ollama (optional)
Project Background
Project Overview
knowledge_graph is rahulnyk's open-source text-to-knowledge-graph project. From PDFs and other text corpora, it uses an LLM to extract concepts (not entities): e.g., "Bangalore" is an entity, "Pleasant weather in Bangalore" is a concept. Concepts co-occurring in the same text chunk are treated as related. The resulting graph supports GRAG, centrality, community clustering, and more.
Author
- Author: rahulnyk
- Philosophy: Concepts are more meaningful than entities; local LLM = zero cost; extensible to graph databases
Project Data
- ⭐ GitHub Stars: 3.1k+
- 🍴 Forks: 491+
- 📄 License: MIT
- 🌐 Sample graph: rahulnyk.github.io/knowledge_graph
- 📝 Method details: Medium article
Core Features
Pipeline
- Chunking: Split text into chunks, assign chunk_id
- Extract concepts & relations: LLM extracts concepts and semantic relations per chunk, weight W1
- Contextual proximity: Concepts in the same chunk are related, weight W2
- Merge edges: Merge weights and concatenate relations for same concept pairs
- Degree & communities: Node degree (sizing), communities (coloring)
Concepts vs Entities
| Type | Example | Description |
|---|---|---|
| Entity | Bangalore, doctor | Concrete objects, names, places |
| Concept | Pleasant weather in Bangalore, doctor–patient relationship | Situations, relations, abstractions |
| This project | Extracts concepts | Author: concepts yield more meaningful KG |
Use Cases
- GRAG: Use graph as retriever for deeper document Q&A
- Centrality: Identify most important concepts in text
- Community detection: Cluster concepts, analyze topic structure
- Visualization: Pyvis for web-hostable interactive graphs
Quick Start
Docker (recommended):
git clone https://github.com/rahulnyk/knowledge_graph.git
cd knowledge_graph
docker build -t knowledge-graph .
docker run -p 8888:8888 knowledge-graphAccess Jupyter on port 8888.
Local Ollama:
- Install Ollama
- Run
ollama run zephyr(or Mistral 7B OpenOrca) - Edit
extract_graph.ipynbwith your text/PDF path and run
Core notebook: extract_graph.ipynb
Tech Stack
| Component | Description |
|---|---|
| Mistral 7B OpenOrca | LLM for concept extraction, via Ollama |
| Ollama | Local model hosting, zero API cost |
| Pandas | Graph schema dataframes (can switch to graph DB later) |
| NetworkX | Graph structure and algorithms |
| Pyvis | Web-hostable JS graph visualization |
Project Advantages
| Comparison | knowledge_graph | Traditional NER + RE | Pure vector RAG |
|---|---|---|---|
| Extraction | Concepts | Entities | No explicit structure |
| Relations | Semantic + contextual | Predefined types | None |
| Cost | Local LLM, zero API | Varies | Embedding cost |
| Retrieval | Graph (GRAG) | Graph query | Vector similarity |
| Interpretability | High, traceable edges | Medium | Low |
Deep Dive
Dual Weight Design
- W1: Semantic relations from LLM; multiple relations per concept pair
- W2: Contextual proximity (same chunk)
- Merge: Same concept pair → sum weights, concatenate relations
Suggested Improvements (community)
Backend:
- Embeddings to deduplicate similar concepts ("doctor" vs "doctors")
- Filter redundant/outlier concepts
- Better contextual proximity to avoid overweighting frequent concepts
Frontend:
- Expand by interest/topic
- More useful graph browsing and navigation
Directory Structure
knowledge_graph/
├── extract_graph.ipynb # Core extraction notebook
├── ner.ipynb # NER related
├── data_input/ # Input
├── data_output/ # Output
├── helpers/ # Helpers
├── ollama/ # Ollama
├── dockerfile
└── pyproject.tomlProject Links and Resources
Official Resources
- 🌟 GitHub: https://github.com/rahulnyk/knowledge_graph
- 🌐 Sample graph: rahulnyk.github.io/knowledge_graph
- 📝 Medium: How to convert any text into a graph of concepts
- 🐛 Issues: GitHub Issues
Target Audience
- Developers building knowledge graphs from documents
- Teams exploring GRAG and graph retrieval
- Users wanting zero-API-cost, local RAG/GRAG
- Researchers interested in concept extraction and graph visualization
Visit my homepage for more useful knowledge and interesting products