Graphrag: Hello World !

这两天抽空玩了一把 Graphrag, 记录一下测试步骤。

  先决条件: 

     Python 3.10-3.12

   备注: 以下所有脚本都在 PowerShell环境下运行

1. 首先安装一下  graphrag python包 

pip install --trusted-host https://mirrors.huaweicloud.com -i https://mirrors.huaweicloud.com/repository/pypi/simple graphrag

 

2.  创建测试数据集目录

mkdir -p ./ragtest/input

  

3. 生成测试数据 (需要手动删除一下最后的空行)

echo "我叫小小高,我儿子叫高1,我女儿叫高3,我还有一个80岁的奶奶" > ./ragtest/input/hello_world.txt

 

4. 初始化 Graphrag 配置

python -m graphrag.index --init --root ./ragtest

 

5.  修改大模型配置

   

1. 编辑 ragtest目录下的 .env 文件

              GRAPHRAG_API_KEY=你的大模型 key,如 open ai sk-api,Azure open ai key


2. 编辑  ragtest目录下的 settings.yaml 文件

 我用的  azure open ai

   聊天模型类型改成 azure 的

     type: azure_openai_chat  (注释下面的model , azure的model用的  deployment_name 字段,这个不注释会报错,如果用azure的话)  

     # model: gpt-35-turbo-16k
    # model_supports_json: true  我的azure 模型不支持这个
    api_base: 用你的 azure endpoint
    api_version: 2024-02-15-preview
    deployment_name: gpt-35-turbo-16k (用你在azure部署的模型)

 

  向量模型改成 azure 的

    type: azure_openai_embedding # or azure_openai_embedding

    # model: text-embedding-3-small
     api_base: 用你的 azure endpoint
     api_version: 2024-02-15-preview
     deployment_name: text-embedding-3-small  (用你在azure部署的模型)

  

6. 生成索引

python -m graphrag.index --root ./ragtest

 

7. 查询

-- 问高级别问题, --method global
python -m graphrag.query --root ./ragtest --method global "总结一下"

 

-- 问细节 --method local
python -m graphrag.query --root ./ragtest --method local  "我的儿子叫啥名字"

 

talk is cheap

 

 

参考链接:

posted @ 2024-07-12 18:53  小小高  阅读(60)  评论(0编辑  收藏  举报