tree: a61368790842a00e18e0dfe9fafc8b5d631d0dbb [path history] [tgz]
  1. data/
  2. application.py
  3. graph_schema.py
  4. hamilton_ingest.py
  5. ingest_fighters.png
  6. ingest_fighters.py
  7. ingest_fights.png
  8. ingest_fights.py
  9. ingest_notebook.ipynb
  10. notebook.ipynb
  11. README.md
  12. requirements.txt
  13. statemachine.png
  14. UFC_Graph.png
  15. utils.py
examples/LLM_Workflows/GraphRAG/README.md

Conversational agent over UFC Knowledge graph

Introduction

This demo illustrates how to build a RAG Q&A AI agent over the UFC stats dataset This one uses a Knowledge Graph that is stored in FalkorDB to query for information about UFC fighters and fights.

Thanks to the folks at FalkorDB for helping set up this example.

Data

The UFC publicly offers statistics for each fight it held in addition to individual fighter's personal statistics on UFC stats

This information includes among other details:

  • Where and when an event was held
  • Details and statistics of a fight
  • Who won a fight
  • How long a fight lasted
  • Fighter's reach

We have pulled some data and stored it in the /data folder.

Querying the AI agent

Once the data is loaded into the Knowledge Graph DB, users can start asking the AI agent questions. For example:

Which fighter holds the fastest win?

The fighter who holds the fastest win is Jorge Masvidal, with a win in just 5 second

Who did he win against ?

Jorge Masvidal won against Ben Askren in the fight where he secured the fastest win.

List fighters who had a trilogy match

The only fighters specifically identified in the data having a trilogy (i.e., three matches against the same opponent) are:

- Frankie Edgar and BJ Penn
- Randy Couture and Vitor Belfort
- BJ Penn and Frankie Edgar
- Cain Velasquez and Junior Dos Santos
...

Who has a 50% win percentage?

Yes, there are fighters with a 50% win percentage in the dataset. Here are a few of them:

- Joe Slick: 1 win out of 2 fights (50%)
- Ken Stone: 2 wins out of 4 fights (50%)
- Tim Boetsch: 12 wins out of 24 fights (50%)
- Jordan Wright: 1 win out of 2 fights (50%)
- Travis Fulton: 1 win out of 2 fights (50%)

Running the demo

Prerequisites

Install Python modules

pip install -r requirements.txt

Run FalkorDB

docker run -p 6379:6379 -p 3000:3000 -it --rm falkordb/falkordb:edge

Note: at the time of writing this image did not persist data.

Ingest data

We first need to create the Knowledge Graph.

Ingest data using the command line:

python hamilton_ingest.py

This will run the following two pipelines:

ingest fighters ingest fights

Note: Hamilton also comes with a UI that you can use to visualize the pipeline and track execution information about it. See hamilton_ingest.py or ingest_notebook.ipynb for more information.

Ingest data using a notebook:

pip install jupyter
jupyter notebook
# select ingest_notebook.ipynb and follow the instructions there

Run the QA agent via the notebook:

export OPENAI_API_KEY="YOUR_OPENAI_KEY"
pip install jupyter
jupyter notebook
# select notebook.ipynb and follow the instructions there

Run the QA agent via the command line:

export OPENAI_API_KEY="YOUR_OPENAI_KEY"
python application.py

Knowledge Graph generated:

knowledge graph

Application Graph generated: application graph

See the trace of the QA agent with the Burr UI

In a terminal run:

burr

Then open a browser and go to http://localhost:7241 to see the Burr UI.

You can then navigate to the ufc-falkor project and see the trace of the QA agent.