Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Knowledge Graph Generator

πŸ•ΈοΈ Knowledge Graph Generator from Text

Transform unstructured text into an interactive knowledge graph using Large Language Models.


Overview

Knowledge Graph Generator is an AI-powered application that automatically extracts entities and relationships from natural language and visualizes them as an interactive graph.

Instead of manually creating graphs, users simply provide text. The application leverages LangChain's LLMGraphTransformer together with Groq's Llama 3.3 70B model to understand the document and generate a structured knowledge graph that can be explored visually.

The generated graph is fully interactive, allowing users to inspect nodes, relationships, filter entities, and understand the semantic structure hidden inside the text.


Demo

Replace assets/demo.gif with your own recording.


Features

  • Convert plain text into a knowledge graph
  • Upload .txt documents
  • Manual text input
  • Automatic entity extraction
  • Automatic relationship extraction
  • Interactive graph visualization
  • Relationship filtering
  • Node highlighting
  • Dark mode visualization
  • Powered by Llama 3.3 70B
  • Built with Streamlit
  • Interactive PyVis network

Architecture

                    User Input
                         β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                             β”‚
      Upload TXT                  Paste Text
          β”‚                             β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                   Streamlit App
                         β”‚
                         β–Ό
               LLMGraphTransformer
                         β”‚
                         β–Ό
            Groq (Llama 3.3 70B)
                         β”‚
                         β–Ό
         Entity & Relationship Extraction
                         β”‚
                         β–Ό
                GraphDocument Objects
                         β”‚
                         β–Ό
                    PyVis Network
                         β”‚
                         β–Ό
            Interactive Knowledge Graph

Tech Stack

Category Technology
Language Python
Frontend Streamlit
LLM Llama 3.3 70B Versatile
API Groq
Framework LangChain
Graph Extraction LLMGraphTransformer
Visualization PyVis
Environment python-dotenv

Project Structure

knowledge_graph_generator/
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ generate_knowledge_graph.py
β”œβ”€β”€ knowledge_graph.html
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env
β”‚
└── README.md

How it Works

1. User provides text

The application accepts either:

  • Uploaded .txt document
  • Manual text input

↓

2. Document Processing

The text is converted into a LangChain Document.

↓

3. LLM Graph Extraction

The document is sent to

LLMGraphTransformer

which asks

Llama 3.3 70B

to identify

  • People
  • Places
  • Organizations
  • Concepts
  • Events

and the relationships connecting them.

↓

4. Graph Construction

The extracted nodes and edges are converted into

GraphDocument

objects.

↓

5. Visualization

PyVis generates an interactive HTML graph with

  • zoom
  • drag
  • filters
  • node selection
  • relationship labels
  • physics simulation

Installation

Clone the repository

git clone https://github.com/meddadaek/knowledge_graph-rag.git

Go inside

cd knowledge_graph-rag

Install dependencies

pip install -r requirements.txt

Environment Variables

Create

.env

Add

GROQ_API_KEY=your_api_key

Run

streamlit run app.py

The application will open automatically in your browser.


Example Input

Elon Musk founded SpaceX in 2002.

SpaceX develops reusable rockets.

NASA awarded SpaceX multiple contracts.

Elon Musk is also the CEO of Tesla.

Example Output

Elon Musk
    β”‚
 founded
    β”‚
 SpaceX
    β”‚
 develops
    β”‚
Reusable Rockets

NASA
   β”‚
awarded
   β”‚
SpaceX

Elon Musk
     β”‚
 CEO
     β”‚
 Tesla

Graph Visualization

Core Components

Streamlit

Provides the interactive user interface for document upload and visualization.


LLMGraphTransformer

Converts natural language into graph structures consisting of entities and relationships.


Groq

Executes the Llama 3.3 70B model with low latency.


PyVis

Generates an interactive HTML network where users can

  • zoom
  • drag
  • inspect nodes
  • inspect edges
  • filter graph components

Future Improvements

  • PDF support
  • DOCX support
  • Neo4j integration
  • GraphRAG pipeline
  • Multi-document graphs
  • Export GraphML
  • Export JSON
  • Export Neo4j Cypher
  • Search entities
  • Chat with generated graph
  • Multiple LLM providers
  • Better node styling
  • Automatic clustering

Dependencies

streamlit
langchain
langchain-experimental
langchain-core
langchain-groq
pyvis
python-dotenv

Author

Abdelkader Meddad (AEK)

Machine Learning Engineer & AI Developer

GitHub

https://github.com/meddadaek

LinkedIn

https://linkedin.com/in/aek-meddad-4967a43b4

License

This project is licensed under the MIT License.


⭐ If you found this project useful, consider giving it a star.

About

Knowledge Graph Generator is an AI-powered application that automatically extracts entities and relationships from natural language and visualizes them as an interactive graph.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages