一、graphrag安装
conda create -n graphrag python=3.11
pip install graphrag
pip install marker-pdf
pip install ocrmypdf
pip install bs4
pip install re
pip install markdown
二、xinference安装及模型导入
1.xinference安装
conda create -n xinference python=3.11
pip install "xinference[all]" -i https://pypi.tuna.tsinghua.edu.cn/simple
# 启动命令
xinference-local
2.模型导入
进入前端页面,将本地模型转化为xinference可调用的embedding模型
三、ollama模型导入
ollama show --modelfile qwen2 > Modelfile
将导出后的Modelfile加上上述一行,增强模型的上下文能力
ollama create -f Modelfile qwen2:ctx32k
四、graphrag调用
1.测试示例
mkdir -p ./ragtest/input
curl https://www.gutenberg.org/cache/epub/24022/pg24022.txt > ./ragtest/input/book.txt
python -m graphrag.index --init --root ./ragtest
进行到此处之后ragtest文件夹下会生成output文件夹,更改其中settings.yaml中的模型配置
python -m graphrag.index --root ./ragtest
# 问答代码
python -m graphrag.query \
--root ./ragtest \
--method local \
"Who is Scrooge, and what are his main relationships?"
2.使用自己的文件
export HF_ENDPOINT=https://hf-mirror.com
#pdf转md
marker_single ./test.pdf ./pdf_txt --batch_multiplier 2 --max_pages 60 --langs English
#md转text
python markdown_to_text.py pdf_txt/test/test.md test.txt
mkdir -p ./ragpdf/input
cp test.txt ./ragpdf/input
python -m graphrag.index --init --root ./ragpdf
python -m graphrag.index --root ./ragpdf
五、离线化pdf转md服务
1.下载下图中模型对环境中在线模型路径进行离线化
2.对环境中对于的在线模型路径进行修改