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

相关推荐
带刺的坐椅3 小时前
Solon AI 开发学习 - 1导引
java·ai·openai·solon·mcp
哥布林学者9 小时前
吴恩达深度学习课程二: 改善深层神经网络 第三周:超参数调整,批量标准化和编程框架(三)多值预测与多分类
深度学习·ai
许泽宇的技术分享10 小时前
从 Semantic Kernel 到 Agent Framework:微软 AI 开发框架的进化之路
人工智能·microsoft
慢慢向上的蜗牛10 小时前
微软vcpkg包管理工具如何使用?
c++·microsoft·vcpkg·跨平台编译
天草二十六_简村人10 小时前
dify中级入门示例--使用知识库搭建智能客服机器人
后端·ai·云原生·ai编程
SEO_juper12 小时前
谷歌搜索全面AI化:SGE如何重构我们的搜索体验与营销格局
人工智能·ai·重构·数字营销
iFlow_AI1 天前
iFlow CLI Hooks 「从入门到实战」应用指南
开发语言·前端·javascript·人工智能·ai·iflow·iflow cli
q***71081 天前
【Golang】——Gin 框架中的表单处理与数据绑定
microsoft·golang·gin
CS创新实验室1 天前
练习项目:基于 LangGraph 和 MCP 服务器的本地语音助手
运维·服务器·ai·aigc·tts·mcp
私人珍藏库1 天前
Microsoft 远程桌面app,支持挂机宝,云主机服务器
运维·服务器·microsoft