Skip to main content

基于微软GraphRAG,支持使用百度千帆、阿里通义、Ollama等模型

Project description

GraphRAG More

基于 微软GraphRAG ,支持使用百度千帆、阿里通义、Ollama本地模型。

可以先熟悉一下微软官方的demo教程:👉 微软官方文档

使用步骤如下:

要求 Python 3.10-3.12,建议使用 pyenv 来管理多个python版本

1. 安装 graphrag-more

pip install graphrag-more

如需二次开发或者调试的话,也可以直接使用源码的方式,步骤如下:

下载 graphrag-more 代码库

git clone https://github.com/guoyao/graphrag-more.git

安装依赖包 这里使用 poetry 来管理python虚拟环境

# 安装 poetry 参考:https://python-poetry.org/docs/#installation

cd graphrag-more
poetry install

2. 准备demo数据

# 创建demo目录
mkdir -p ./ragtest/input

# 下载微软官方demo数据
# 微软官方提供的demo数据 https://www.gutenberg.org/cache/epub/24022/pg24022.txt 有点大,会消耗不少token,这里改用精简后的数据
curl https://raw.githubusercontent.com/guoyao/graphrag-more/refs/heads/main/examples/resources/pg24022.txt > ./ragtest/input/book.txt

3. 初始化demo目录

graphrag init --root ./ragtest

4. 移动和修改 settings.yaml 文件

根据选用的模型(千帆、通义、Ollama)和使用的graphrag-more版本(不同版本settings.yaml可能不一样), 将 example_settings 文件夹(比如:0.5.0.1 版本的example_settings )对应模型的 settings.yaml 文件复制到 ragtest 目录,覆盖初始化过程生成的 settings.yaml 文件。

# 千帆
cp ./example_settings/qianfan/settings.yaml ./ragtest

# or 通义
cp ./example_settings/tongyi/settings.yaml ./ragtest

# or ollama
cp ./example_settings/ollama/settings.yaml ./ragtest

每个settings.yaml里面都设置了默认的 llm 和 embeddings 模型,根据选用的模型修改 settings.yaml 文件的 model 配置

  • 千帆默认使用 qianfan.ERNIE-3.5-128K 和 qianfan.bge-large-zh ,注意:必须带上 qianfan. 前缀 !!!
  • 通义默认使用 tongyi.qwen-plus 和 tongyi.text-embedding-v2 ,注意:必须带上 tongyi. 前缀 !!!
  • Ollama默认使用 ollama.mistral:latest 和 ollama.quentinz/bge-large-zh-v1.5:latest ,注意:<=0.3.0版本时,其llm模型不用带前缀,>=0.3.1版本时,其llm模型必须带上 ollama. 前缀,embeddings模型必须带 ollama. 前缀 !!!

5. 构建前的准备

根据选用的模型,配置对应的环境变量,若使用Ollama需要安装并下载对应模型

6. 构建索引

graphrag index --root ./ragtest

构建过程可能会触发 rate limit (限速)导致构建失败,重复执行几次,或者尝试调小 settings.yaml 中 的 requests_per_minute 和 concurrent_requests 配置,然后重试

7. 执行查询

# global query
graphrag query \
--root ./ragtest \
--method global \
--query "What are the top themes in this story?"

# local query
graphrag query \
--root ./ragtest \
--method local \
--query "Who is Scrooge, and what are his main relationships?"

查询过程可能会出现json解析报错问题,原因是某些模型没按要求输出json格式,可以重复执行几次,或者修改 settings.yaml 的 llm.model 改用其他模型

除了使用cli命令之外,也可以使用API方式来查询,以便集成到自己的项目中,API使用方式请参考: examples/api_usage(注意:不同graphrag-more版本API用法可能不一样,参考所使用版本下的文件)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphrag_more-0.5.0.1.tar.gz (233.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphrag_more-0.5.0.1-py3-none-any.whl (412.0 kB view details)

Uploaded Python 3

File details

Details for the file graphrag_more-0.5.0.1.tar.gz.

File metadata

  • Download URL: graphrag_more-0.5.0.1.tar.gz
  • Upload date:
  • Size: 233.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/22.6.0

File hashes

Hashes for graphrag_more-0.5.0.1.tar.gz
Algorithm Hash digest
SHA256 65b9a21b05efdf4e8c094f8c2691cc9448661365bd98707095a738426446991a
MD5 e72bc632a6823847f9718d6db4c4ecba
BLAKE2b-256 dc5bbf5755fa5a34734990b4a23a3ded142a9d5365a18126cf9205838c8db02c

See more details on using hashes here.

File details

Details for the file graphrag_more-0.5.0.1-py3-none-any.whl.

File metadata

  • Download URL: graphrag_more-0.5.0.1-py3-none-any.whl
  • Upload date:
  • Size: 412.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Darwin/22.6.0

File hashes

Hashes for graphrag_more-0.5.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a262ef994611c090bccf3aad852b327770dfd860de04079054c6c68f3ec652be
MD5 6ee459af9bdbc873844d36f1530f10c0
BLAKE2b-256 bcc1591d20b0254f5077d018e385ae0dd4ce072395008a0ad8d450c3a2852419

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page