微软最新AI:GraphRAG+Chainlit实现跨文档智能检索分析打造私人AI助手

文章目录


前言

本月初,微软发布最强 RAG 知识库开源方案 GraphRAG,项目上线即爆火,现在星标量已经达到 10.9 k。

https://github.com/microsoft/graphrag


一、GraphRAG安装

1.创建一个新项目

建议使用Python3.11环境

2.安装GraphRAG

python 复制代码
pip install graphrag

3.初始化

python 复制代码
mkdir -p ./ragtest/input
curl https://raw.githubusercontent.com/win4r/mytest/main/book.txt > ./ragtest/input/book.txt
python3 -m graphrag.index --init --root ./ragtest

4.配置相关文件

将API_KEY改成chatgpt4的api

5.执行并构建索引

python 复制代码
python3 -m graphrag.index --root ./ragtest

二、Chainlit安装

1.安装Chainlit包

python 复制代码
pip3 install chainlit

2.创建app.py

python 复制代码
import chainlit as cl
import subprocess
import shlex


@cl.on_chat_start
def start():
    cl.user_session.set("history", [])


@cl.on_message
async def main(message: cl.Message):
    history = cl.user_session.get("history")

    # 从 Message 对象中提取文本内容
    query = message.content

    # 构建命令
    cmd = [
        "python3", "-m", "graphrag.query",
        "--root", "./ragtest",
        "--method", "local",
    ]

    # 安全地添加查询到命令中
    cmd.append(shlex.quote(query))

    # 运行命令并捕获输出
    try:
        result = subprocess.run(cmd, capture_output=True, text=True, check=True)
        output = result.stdout

        # 提取 "SUCCESS: Local Search Response:" 之后的内容
        response = output.split("SUCCESS: Local Search Response:", 1)[-1].strip()

        history.append((query, response))
        cl.user_session.set("history", history)

        await cl.Message(content=response).send()
    except subprocess.CalledProcessError as e:
        error_message = f"An error occurred: {e.stderr}"
        await cl.Message(content=error_message).send()


if __name__ == "__main__":
    cl.run()

3.运行

python 复制代码
chainlit run app.py

学习资料

http://t.csdnimg.cn/Wy8UJ

https://www.bilibili.com/video/BV1EE4m1R7wn?vd_source=a19eed2fa1f675b1a40c1824b67c7141

https://blog.stoeng.site/20240704.html

https://docs.dbgpt.site/docs/latest/cookbook/rag/graph_rag_app_develop/?spm=ata.21736010.0.0.635d79f3pT08lx

相关推荐
ciku5 小时前
Spring Ai Advisors
人工智能·spring·microsoft
智能汽车人12 小时前
行业分析---领跑汽车2025第二季度财报
人工智能·microsoft
tkdsy00716 小时前
AI全产业链工作岗位分析:技术与非技术岗位全景图
人工智能·ai·ai产业链·ai工程师·ai岗位
zhayujie1 天前
RAG优化实战 - LinkAI智能体平台的知识库升级之路
ai·大模型·agent·知识库·rag
造梦师阿鹏1 天前
004.从 API 裸调到 LangChain
经验分享·ai·大模型·ai技术·大模型应用开发
即兴小索奇1 天前
AI应用商业化加速落地 2025智能体爆发与端侧创新成增长引擎
人工智能·搜索引擎·ai·商业·ai商业洞察·即兴小索奇
AIGC安琪1 天前
Transformer中的编码器和解码器是什么?
人工智能·深度学习·ai·语言模型·大模型·transformer·ai大模型
即兴小索奇1 天前
2025商业热点全景扫描:新质生产力引领变革 新零售与县域消费双线爆发
ai·商业·ai商业洞察·即兴小索奇
m0_603888711 天前
Infusing fine-grained visual knowledge to Vision-Language Models
人工智能·ai·语言模型·自然语言处理·论文速览
Leinwin2 天前
微软行业案例:英格兰足球超级联赛(Premier League)
microsoft