The structure of this code is based on nano-graphrag.
Install from source (recommend)
# clone this repo first
cd HypergraphRAG
pip install -e .Tip
Please set OpenAI API key in environment: export OPENAI_API_KEY="sk-...".
download a copy of A Christmas Carol by Charles Dickens:
curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txtUse the below python snippet:
from nano_hypergraphrag import HypergraphRAG, QueryParam
hypergraph_func = HypergraphRAG(working_dir="./dickens")
with open("./book.txt") as f:
hypergraph_func.insert(f.read())
# Perform global graphrag search
print(hypergraph_func.query("What are the top themes in this story?"))
# Perform local graphrag search (I think is better and more scalable one)
print(hypergraph_func.query("What are the top themes in this story?", param=QueryParam(mode="local")))Next time you initialize a HypergraphRAG from the same working_dir, it will reload all the contexts automatically.