# Knowledge Graph

> Open-source Python notebook project that uses a local LLM to convert a text corpus into a visualized graph of concepts.

Knowledge Graph is an open-source project by rahulnyk that turns a body of text, such as a PDF document, into a graph of concepts and relationships. It runs locally using Mistral 7B OpenOrca served through Ollama, so graph generation does not require calls to GPT. The output is an interactive graph visualization built with Pyvis.

## What It Is

The project is a Jupyter notebook (extract_graph.ipynb) that implements a text-to-knowledge-graph pipeline. The README states it can be used for Graph Augmented Generation or knowledge-graph-based question answering. Its author chooses concepts rather than named entities as graph nodes, saying that in his experience concepts make more meaningful graphs.

## How the Pipeline Works

1. The text is split into chunks, each with a chunk_id.
2. An LLM extracts concepts and their semantic relationships from every chunk, and each relation is given a weight (W1).
3. Concepts that occur in the same chunk are treated as related by contextual proximity and given a second weight (W2).
4. Duplicate pairs are grouped, their weights summed, and their relations concatenated, leaving one edge per distinct concept pair.
5. Node degree is calculated to size nodes, and communities are calculated to color them.

Pandas dataframes hold the graph schema, NetworkX handles graph operations, and Pyvis renders the web-hostable JavaScript visualization.

## Setup Path

The recommended install is via Docker: clone the repository, build the image, and run it exposing port 8888. Ollama must also be installed locally to host the model. The README also lists planned improvements, including embedding-based deduplication of similar concepts, filtering of redundant concepts, and a better frontend for exploring the graph.

## Features
- Converts a text corpus or PDF into a concept graph
- Local LLM concept and relation extraction with Mistral 7B OpenOrca via Ollama
- Text chunking with chunk IDs
- Weighted edges combining semantic relations and contextual proximity
- Node degree sizing and community coloring
- Interactive Pyvis graph visualization hostable on the web
- Docker-based local setup

## Integrations
Ollama, Mistral 7B OpenOrca, Pandas, NetworkX, Pyvis, Docker

## Platforms
WINDOWS, MACOS, LINUX, API

## Pricing
Open Source

## Links
- Website: https://github.com/rahulnyk/knowledge_graph
- Repository: https://github.com/rahulnyk/knowledge_graph
- EveryDev.ai: https://www.everydev.ai/tools/knowledge-graph
