Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 1.44 KB

File metadata and controls

55 lines (37 loc) · 1.44 KB

GraphRAG Demo

This example demonstrates how to use the DSPy and TiDB Serverless to build a simple GraphRAG application. It crawled an example webpage and index the content to TiDB Serverless with Graph, then use the Graph and Vector to search the content and generate the answer with OpenAI.

Prerequisites

  • A running TiDB Serverless cluster
    • Vector search enabled
    • Run the init.sql in your cluster
  • Python 3.8 or later
  • OpenAI API key

Run the example

Clone this repo

git clone https://github.com/pingcap/tidb-vector-python.git

Create a virtual environment

cd tidb-vector-python/examples/graphrag-demo
python3 -m venv .venv
source .venv/bin/activate

Install dependencies

pip install -r requirements.txt

Set the environment variables

Get the TiDB connection string via TIDB_HOST, TIDB_USERNAME, and TIDB_PASSWORD from the TiDB Cloud console, as described in the Prerequisites section.

The TiDB connection string will look like:

mysql+pymysql://{TIDB_USER}:{TIDB_PASSWORD}@{TIDB_HOST}:{TIDB_PORT}/{TIDB_DB_NAME}?ssl_verify_cert=True&ssl_verify_identity=True

Get the OPENAI_API_KEY from OpenAI

Run this example

$ python3 graphrag-demo.py
Input your TIDB connection string:
Input your OpenAI API Key:
Enter your question: