微软最新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

相关推荐
极客先躯1 小时前
智能体开发高级面试每日一题|2026-05-31|什么是 AI 编排(Orchestration)?编排层负责什么?
人工智能·ai·agent·每日一题·高级面试·智能体开发·ai编排
七夜zippoe4 小时前
Agent 故障排查手册:50个常见故障的诊断流程与解决方案
ai·agent·解决方案·故障排查·诊断流程
心流剑5 小时前
从零打造带降级路由的 Agentic RAG 校园智能体(附前端终端UI实战)
python·ai·rag
zhengfei6116 小时前
AI 渗透项目深度研究:从工具自动化到自主攻击系统,下一代 AI 渗透平台应该如何构建?
运维·人工智能·ai·开源·自动化·ai编程·ai-native
LMYH11238 小时前
企业数字化实战Day4:从角色权限管理到系统集成测试与流程治理
ai·企业数字化·飞书多维表格·fde
极客先躯12 小时前
智能体开发高级面试每日一题|2026-06-05|什么是 Agentic AI 与传统 RPA 的区别?
人工智能·ai·代理模式·rpa·每日一题·高级面试·智能体开发
七夜zippoe12 小时前
国产库性能调优:索引/执行计划实战(四步处理顺序与四类慢的归因)
java·ai·信创
极客先躯12 小时前
智能体开发高级面试每日一题|2026-06-03|如何判断一个业务需求适合用 Agent 解决还是用传统程序解决?
ai·架构·agent·每日一题·高级面试题·智能体开发·传统业务
开发者导航13 小时前
Cursor plugins 插件仓库上手:结构解析与安装使用教程
android·linux·ubuntu·ai·typescript·cursor·插件开发
万里侯13 小时前
生产环境故障自愈的审计溯源:构建基于区块链或不可篡改日志的自愈证据链
人工智能·微服务·ai·容器·k8s