GPT Graph: A Simple Tool for Knowledge Graph Exploration
Tags: ai, gpt3, chatgpt, javascript
Published: 2023-04-30 09:28:18


![GPT Graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91no8t4va7lfhv816ewo.png)

As a developer, exploring and organizing information is a crucial part of the job. That's why I wanted to share with you an open-source tool that I developed called "GPT Graph" It is a knowledge graph explorer that utilizes the powerful GPT 3.5 turbo model to help users explore information in an organized and intuitive manner.

I believe graphs are an excellent way to leverage LLMs in a variety of use cases, including brainstorming, studying, and reasoning about topics and how they relate to each other.

## What is a Knowledge Graph

A knowledge graph is a type of database that is used to store and represent knowledge in a machine-readable format. It uses a graph-based model, consisting of nodes (entities) and edges (relationships), to represent information and the connections between them. Knowledge graphs are often used to represent complex information in a structured and intuitive way, making it easier for machines to understand and analyze. They can be used in various domains, such as natural language processing, search engines, recommendation systems, and data analytics.

## Why GPT Graph?

It's a unique way to explore information in an organized and intuitive manner. With GPT Graph, you can easily navigate through different topics, discover new relationships between them, and generate creative ideas.

It leverages the power of GPT-3 to generate relevant and high-quality content. Unlike traditional keyword-based searches, GPT Graph takes a more semantic approach to explore the topics and generate the graph. It helps to uncover hidden relationships between different topics and provides a comprehensive view of the entire knowledge domain.

Moreover, GPT Graph provides a user-friendly interface that allows users to interact with the graph easily. Users can ask questions, generate prompts, and add their own ideas to the graph. It's a powerful tool that enables users to collaborate, brainstorm, and generate new insights in a very efficient way.

## Demo
{% embed https://youtu.be/E4xKhRbNQig %}

## Features

- The ability to describe a specific query and generate a graph of related topics.
- Auto-generated prompts for generated nodes to discover more about the topic.
- Custom prompts support, asking questions and getting answers, along with generated prompts to branch from your own ideas.
- Markdown formatted descriptions.

**Example**

Adding the following prompt as a starting point for the graph:
```
Solve 5x^2 + 6x + 1 = 0
```

Will solve the equation and provide these helpful prompts to expand your knowledge about Quadratic Equation:
- What is a quadratic equation?
- How do you derive the quadratic formula?
- What are some methods to solve quadratic equations?

These auto-generated prompts may vary from time to time, based on used temperature parameter value.

## Project Details

This project uses the following technologies and frameworks:
- OpenAI GPT 3.5 turbo model
- Typescript
- [Vue.js](https://vuejs.org/) 3.0 JavaScript Framework
- [Ant Design Vue](https://antdv.com/) UI Framework
- [G6](https://g6.antv.antgroup.com/en/) Graph Visualization Engine

### Usage

```
npm install
npm run dev
```

### Content Parsing

Most of the time GPT 3 returns a consistent JSON object, but unfortunately this is not always the case, so additional layer added to extract actual JSON or transform it to the valid format through [jsonrepair](https://www.npmjs.com/package/jsonrepair) library

### Content Rendering

G6 library is used for canvas rendering and graph arrangement, with custom nodes and edges.
Two tree graph layouts used
- dendrogram for vertical layout
- mindmap for horizontal layout

### Model Parameters

`temprature: 0.7` is used to get different and more creative responses every time, you may play around with different values and check the output

### API Key

An OpenAI API key is required to run the tool, You can add your own key to .env file with the key `VITE_OPENAI_KEY`, Check `.env.example` file.

### GitHub Repository

https://github.com/m-elbably/gpt-graph

## Future Enhancements

While this is just a limited technical example, I think there are many ways to improve it. Here are some of the potential enhancements:

- Use GPT message context with the path the user took to discover specific topics, allowing the user to control the divergence of the information and get creative ideas through auto-generated prompts or questions.
- Use GPT inference capabilities to label topics and automatically connect or group related nodes.
- Infer topics relations and add to edges
- Store the result in a NoSQL database labeled with the primary input and retrieve it later to draw the graph and search instead of querying GPT again.
- Allow users to add and delete custom nodes, enabling them to use the tool as a powerful mind-mapping tool with AI behind the scenes to provide creative ideas or discuss user-created ones.
- Use a normal graph structure instead of a tree graph (DAG), will allow developers and architects to design systems, by adding different components and the flow of data, then get GPT to generate mermaid diagram code for built graphs, which opens up many possibilities.

## Potential Uses for GPT Graph
GPT Graph can be used in various domains where knowledge exploration is required. Here are a few examples of how GPT Graph can be used:

- Research: GPT Graph can be used by researchers to explore new topics, discover new relationships between them, and generate new insights. It can help researchers to get a comprehensive view of the entire knowledge domain and generate creative ideas.
- Education: GPT Graph can be used by students to study different topics, discover new relationships between them, and generate new insights. It can help students to get a better understanding of the subject matter and generate creative ideas.
- Architecture and System Design: GPT Graph can be used by architects and designers to explore new solutions, discover new relationships between different components, and generate new ideas. It can help them to generate creative and innovative designs.
- Business: GPT Graph can be used by businesses to explore new opportunities, discover new relationships between different markets and products, and generate new ideas. It can help businesses to innovate and stay ahead of the competition.

Overall, the idea of using graphs with GPT can lead to building powerful tools that can be used in various domains where knowledge exploration is required. It’s a unique way to explore information, generate new insights, and collaborate with others in an efficient way.

> GPT Graph is a limited technical example that demonstrates the concept. However, it can also serve as an excellent example of how to build GPT 3 applications and use prompts as a developer to get results in a specific format and schema.

##Conclusion

I hope that this small project serves as an example for you and other developers on how to build GPT 3 applications, or better yet, inspires you to create innovative tools that can be of assistance to others.

Feel free to check out the [GitHub Repository](https://github.com/m-elbably/gpt-graph) and give it a try, Or play with the [online demo](https://m-elbably.github.io/gpt-graph/) if you have an OpenAI API Key.

> The Original Article Published on [Medium](https://medium.com/@m-elbably/gpt-graph-a-simple-tool-for-knowledge-graph-exploration-70e0e3861716)