-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds GraphDB Conversational Agent example
With help from the FalkorDB folks we added a GraphDB example to Burr. This uses Hamilton to ingest and push data to FalkorDB that you run locally in a docker container. Then you can run a Burr application to run the conversational agent. I decided to add to the conversational agent directory because that seems like the more logical place to curate conversational agent examples. So I moved the original example to simple_example and updated links accordingly. As long as we didn't link directly to the notebook but the repository example we should be good.
- Loading branch information
Showing
30 changed files
with
12,207 additions
and
1,696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
# Conversational RAG with memory | ||
# Conversational RAG examples | ||
Here we curate different examples of how to build a Conversational RAG agent using different approaches/backends. | ||
|
||
## [Simple Example](simple_example/) | ||
This example demonstrates how to build a conversational RAG agent with "memory". | ||
|
||
The "memory" here is stored in state, which Burr then can help you track, | ||
manage, and introspect. | ||
|
||
The set up of this example is that you have: | ||
|
||
1. Some initial "documents" i.e. knowledge. | ||
2. We bootstrap a vector store with these documents. | ||
3. We then have a pipeline that uses a vector store for a RAG query. This example uses a [pre-made conversational RAG pipeline](https://hub.dagworks.io/docs/DAGWorks/conversational_rag/); the prompt isn't hidden under layers of abstraction. | ||
4. We hook everything together with Burr that will manage the state | ||
of the conversation and asking for user inputs. | ||
|
||
To run this example, install Burr and the necessary dependencies: | ||
|
||
```bash | ||
pip install "burr[start]" -r requirements.txt | ||
``` | ||
|
||
Then run the server in the background: | ||
|
||
```bash | ||
burr | ||
``` | ||
|
||
Make sure you have an `OPENAI_API_KEY` set in your environment. | ||
|
||
Then run | ||
```bash | ||
python application.py | ||
``` | ||
|
||
You'll then have a text terminal where you can interact. Type exit to stop. | ||
|
||
# Application That's Defined: | ||
![Application Image](statemachine.png) | ||
|
||
# Video Walkthrough via Notebook | ||
Open the notebook <a target="_blank" href="https://colab.research.google.com/github/dagworks-inc/burr/blob/main/examples/conversational-rag/notebook.ipynb"> | ||
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | ||
</a> | ||
|
||
Watch the video walkthrough with the notebook (1.5x+ speed recommended): | ||
|
||
|
||
<a href="http://www.youtube.com/watch?feature=player_embedded&v=t54DCiOH270" target="_blank"> | ||
<img src="http://img.youtube.com/vi/t54DCiOH270/hqdefault.jpg" alt="Watch the video" border="10" /> | ||
</a> | ||
## [Graph DB Example](graph_db_example/) | ||
This demo illustrates how to build a RAG Q&A AI agent over the [UFC stats dataset](https://www.kaggle.com/datasets/rajeevw/ufcdata). | ||
This one uses a Knowledge Graph that is stored in [FalkorDB](https://www.falkordb.com/) to query for | ||
information about UFC fighters and fights. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Conversational agent over UFC Knowledge graph | ||
|
||
## Introduction | ||
This demo illustrates how to build a RAG Q&A AI agent over the [UFC stats dataset](https://www.kaggle.com/datasets/rajeevw/ufcdata) | ||
This one uses a Knowledge Graph that is stored in [FalkorDB](https://www.falkordb.com/) to query | ||
for information about UFC fighters and fights. | ||
|
||
Thanks to the folks at [FalkorDB](https://www.falkordb.com/) for helping set up this example. | ||
|
||
## Data | ||
The [UFC](http://ufc.com) publicly offers statistics for each fight it held in addition to individual fighter's | ||
personal statistics on [UFC stats](http://ufcstats.com/statistics/events/completed) | ||
|
||
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 either into a Knowledge Graph, 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 | ||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Run FalkorDB | ||
```sh | ||
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**: | ||
|
||
```sh | ||
python hamilton_ingest.py | ||
``` | ||
This will run the following two pipelines: | ||
|
||
![ingest fighters](ingest_fighters.png) | ||
![ingest fights](ingest_fights.png) | ||
|
||
**Note:** [Hamilton](https://github.com/dagworks-inc/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: | ||
|
||
```sh | ||
pip install jupyter | ||
jupyter notebook | ||
# select ingest_notebook.ipynb and follow the instructions there | ||
``` | ||
|
||
## Run the QA agent via the notebook: | ||
```sh | ||
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: | ||
```sh | ||
export OPENAI_API_KEY="YOUR_OPENAI_KEY" | ||
python application.py | ||
``` | ||
|
||
Knowledge Graph generated: | ||
|
||
![knowledge graph](UFC_Graph.png) | ||
|
||
Application Graph generated: | ||
![application graph](statemachine.png) | ||
|
||
## See the trace of the QA agent with the Burr UI | ||
In a terminal run: | ||
```sh | ||
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.