微信扫码
添加专属顾问
 
                        我要投稿
港大多模态RAG神器来袭!突破传统文本局限,实现PDF、Office文档到图像的智能解析与检索。 核心内容: 1. 端到端多模态处理流水线,覆盖文本、图像、表格等复杂内容 2. 独创知识图谱索引技术,实现跨模态语义关联 3. 灵活架构设计,支持自定义内容类型与混合检索机制
 
                                
在AI驱动的信息检索领域,传统RAG(检索增强生成)系统通常局限于文本处理,难以应对包含文本、图像、表格和公式的复杂文档。
RAG-Anything 是由香港大学数据智能实验室开发的一款开源的多模态RAG系统,能够提供从文档摄取到智能查询的端到端解决方案。
与传统RAG不同,它通过多模态知识图谱、灵活的解析架构和混合检索机制,提供上下文感知的高精度查询结果,显著提升复杂文档处理能力。
文本、图像、表格、公式等多模态内容全覆盖,提供了真正端到端的一体化处理能力。
RAG-Anything采用分层架构,通过多阶段流水线扩展传统RAG,处理异构内容。其工作流程包括文档解析、内容分析、知识图谱构建和智能检索。
1、文档解析阶段
目标:从多种格式文档中提取和结构化多模态元素(文本、图像、表格、公式)。
核心组件:
2、多模态内容理解
目标:通过专用流水线并行处理异构内容,确保高效和完整性。
核心组件:
3、多模态分析引擎
目标:为不同模态内容部署专用处理器,确保精准解析。
核心组件:
4、多模态知识图谱索引
目标:将文档内容转化为结构化语义表示,提升检索效率。
核心功能:
5、模态感知检索
目标:实现精准、上下文感知的多模态检索。
核心机制:
RAG-Anything 的安装方式非常简单,支持从PyPI安装(推荐)或者源码部署。
1、从PyPI安装(推荐)
pip install raganything
2、从源码安装
git clone https://github.com/HKUDS/RAG-Anything.git
cd RAG-Anything
pip install -e .然后需要检查MinerU是否安装:
# 验证安装
mineru --version
# 检查是否正确配置
python -c "from raganything import RAGAnything; rag = RAGAnything(); print('✅ MinerU安装正常' if rag.check_mineru_installation() else '❌ MinerU安装有问题')"模型在首次使用时会自动下载。
Python使用示例
Demo01:端到端文档处理
import asyncio
from raganything import RAGAnything
from lightrag.llm.openai import openai_complete_if_cache, openai_embed
async def main():
    # 初始化RAGAnything
    rag = RAGAnything(
        working_dir="./rag_storage",
        llm_model_func=lambda prompt, system_prompt=None, history_messages=[], **kwargs: openai_complete_if_cache(
            "gpt-4o-mini",
            prompt,
            system_prompt=system_prompt,
            history_messages=history_messages,
            api_key="your-api-key",
            **kwargs,
        ),
        vision_model_func=lambda prompt, system_prompt=None, history_messages=[], image_data=None, **kwargs: openai_complete_if_cache(
            "gpt-4o",
            "",
            system_prompt=None,
            history_messages=[],
            messages=[
                {"role": "system", "content": system_prompt} if system_prompt else None,
                {"role": "user", "content": [
                    {"type": "text", "text": prompt},
                    {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}}
                ]} if image_data else {"role": "user", "content": prompt}
            ],
            api_key="your-api-key",
            **kwargs,
        ) if image_data else openai_complete_if_cache(
            "gpt-4o-mini",
            prompt,
            system_prompt=system_prompt,
            history_messages=history_messages,
            api_key="your-api-key",
            **kwargs,
        ),
        embedding_func=lambda texts: openai_embed(
            texts,
            model="text-embedding-3-large",
            api_key="your-api-key",
        ),
        embedding_dim=3072,
        max_token_size=8192
    )
    # 处理文档
    await rag.process_document_complete(
        file_path="path/to/your/document.pdf",
        output_dir="./output",
        parse_method="auto"
    )
    # 查询处理后的内容
    result = await rag.query_with_multimodal(
        "图表中显示的主要发现是什么?",
        mode="hybrid"
    )
    print(result)
if __name__ == "__main__":
    asyncio.run(main())Demo02:直接多模态内容处理
import asyncio
from lightrag import LightRAG
from raganything.modalprocessors import ImageModalProcessor, TableModalProcessor
async def process_multimodal_content():
    # 初始化LightRAG
    rag = LightRAG(
        working_dir="./rag_storage",
        # ... 你的LLM和嵌入配置
    )
    await rag.initialize_storages()
    # 处理图像
    image_processor = ImageModalProcessor(
        lightrag=rag,
        modal_caption_func=your_vision_model_func
    )
    image_content = {
        "img_path": "path/to/image.jpg",
        "img_caption": ["图1:实验结果"],
        "img_footnote": ["数据收集于2024年"]
    }
    description, entity_info = await image_processor.process_multimodal_content(
        modal_content=image_content,
        content_type="image",
        file_path="research_paper.pdf",
        entity_name="实验结果图表"
    )
    # 处理表格
    table_processor = TableModalProcessor(
        lightrag=rag,
        modal_caption_func=your_llm_model_func
    )
    table_content = {
        "table_body": """
        | 方法 | 准确率 | F1分数 |
        |------|--------|--------|
        | RAGAnything | 95.2% | 0.94 |
        | 基准方法 | 87.3% | 0.85 |
        """,
        "table_caption": ["性能对比"],
        "table_footnote": ["测试数据集结果"]
    }
    description, entity_info = await table_processor.process_multimodal_content(
        modal_content=table_content,
        content_type="table",
        file_path="research_paper.pdf",
        entity_name="性能结果表格"
    )
if __name__ == "__main__":
    asyncio.run(process_multimodal_content())Demo03:批量处理
# 处理多个文档
await rag.process_folder_complete(
    folder_path="./documents",
    output_dir="./output",
    file_extensions=[".pdf", ".docx", ".pptx"],
    recursive=True,
    max_workers=4
)Demo04:自定义多模态处理器
from raganything.modalprocessors import GenericModalProcessor
class CustomModalProcessor(GenericModalProcessor):
    async def process_multimodal_content(self, modal_content, content_type, file_path, entity_name):
        # 你的自定义处理逻辑
        enhanced_description = await self.analyze_custom_content(modal_content)
        entity_info = self.create_custom_entity(enhanced_description, entity_name)
        return await self._create_entity_and_chunk(enhanced_description, entity_info, file_path)Demo05:查询选项
# 不同的查询模式
result_hybrid = await rag.query_with_multimodal("你的问题", mode="hybrid")
result_local = await rag.query_with_multimodal("你的问题", mode="local")
result_global = await rag.query_with_multimodal("你的问题", mode="global")项目目录下也有相应的实际场景演示,examples/ 目录包含完整的使用示例:
raganything_example.py:基于MinerU的端到端文档处理
modalprocessors_example.py:直接多模态内容处理
office_document_test.py:Office文档解析测试(无需API密钥)
image_format_test.py:图像格式解析测试(无需API密钥)
text_format_test.py:文本格式解析测试(无需API密钥)在 RAG 系统百花齐放的今天,RAG-Anything 是少有的“真正做全”的开源RAG系统之一。
从结构化提取到多模态融合,从问答到检索,它不仅支持多种文档格式,而且能智能分析、构建知识图谱、并在上下文语义层面实现真正的信息理解与调用。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-31
有人问我会不会用 AI,我直接拿出这个 Ollama + FastGPT 项目给他看
2025-10-30
开源可信MCP,AICC机密计算新升级!
2025-10-30
OpenAI 开源了推理安全模型-gpt-oss-safeguard-120b 和 gpt-oss-safeguard-20b
2025-10-29
刚刚,OpenAI 再次开源!安全分类模型 gpt-oss-safeguard 准确率超越 GPT-5
2025-10-29
AI本地知识库+智能体系列:手把手教你本地部署 n8n,一键实现自动采集+智能处理!
2025-10-29
n8n如何调用最近爆火的deepseek OCR?
2025-10-29
OpenAI终于快要上市了,也直面了这23个灵魂拷问。
2025-10-29
保姆级教程:我用Coze干掉了最烦的周报
 
            2025-08-20
2025-09-07
2025-08-05
2025-08-20
2025-08-26
2025-08-22
2025-09-06
2025-08-06
2025-10-20
2025-08-22
2025-10-29
2025-10-28
2025-10-13
2025-09-29
2025-09-17
2025-09-09
2025-09-08
2025-09-07