一个提供全面检索增强生成(RAG)能力的MCP(模型上下文协议)服务器,用于处理和查询使用raganything库支持多模态的文档目录。
process_directory处理目录中的所有文件,进行全面的RAG索引,支持多模态。
必需参数:
directory_path:包含要处理文件的目录路径api_key:用于LLM和嵌入功能的OpenAI API密钥可选参数:
working_dir:自定义RAG存储的工作目录base_url:OpenAI API基础URL(用于自定义端点)file_extensions:要处理的文件扩展名列表(默认:['.pdf', '.docx', '.pptx', '.txt', '.md'])recursive:处理子目录(默认:True)enable_image_processing:启用图像分析(默认:True)enable_table_processing:启用表格提取(默认:True)enable_equation_processing:启用公式处理(默认:True)max_workers:并发处理工作者数量(默认:4)process_single_document处理单个文档,进行全面的多模态分析。
必需参数:
file_path:要处理的文档路径api_key:OpenAI API密钥可选参数:
working_dir:自定义RAG存储的工作目录base_url:OpenAI API基础URLoutput_dir:解析内容的输出目录parse_method:文档解析方法(默认:"auto")enable_image_processing:启用图像分析(默认:True)enable_table_processing:启用表格提取(默认:True)enable_equation_processing:启用公式处理(默认:True)query_directory使用LightRAG对已处理文档进行纯文本查询。
参数:
directory_path:已处理目录的路径query:关于文档的问题mode:查询模式 - "混合"、"本地"、"全局"、"简单"、"混合"或"绕过"(默认:"混合")query_with_multimodal_content带有额外多模态内容(表格、公式等)的增强查询。
参数:
directory_path:已处理目录的路径query:要问的问题multimodal_content:多模态内容字典列表mode:查询模式(默认:"混合")示例多模态内容:
[
{
"type": "table",
"table_data": "Method,Accuracy\\nRAGAnything,95.2%\\nBaseline,87.3%",
"table_caption": "性能比较"
},
{
"type": "equation",
"latex": "P(d|q) = \\frac{P(q|d) \\cdot P(d)}{P(q)}",
"equation_caption": "文档相关性概率"
}
]
list_processed_directories列出所有已处理且可用于查询的目录。
get_rag_info获取目录的RAG配置和状态的详细信息。
process_directory(
directory_path="/path/to/documents",
api_key="your-openai-api-key"
)
process_directory(
directory_path="/path/to/research_papers",
api_key="your-openai-api-key",
file_extensions=[".pdf", ".docx"],
enable_image_processing=true,
enable_table_processing=true,
max_workers=6
)
query_directory(
directory_path="/path/to/documents",
query="这些研究论文的主要发现是什么?",
mode="混合"
)
query_with_multimodal_content(
directory_path="/path/to/documents",
query="将这些结果与文档中的发现进行比较",
multimodal_content=[{
"type": "table",
"table_data": "Method,Accuracy,Speed\\nRAGAnything,95.2%,120ms\\nBaseline,87.3%,180ms",
"table_caption": "性能比较"
}],
mode="混合"
)
process_single_document(
file_path="/path/to/important_paper.pdf",
api_key="your-openai-api-key",
enable_image_processing=true
)
export OPENAI_API_KEY="your-openai-api-key-here"
uv sync
python main.py
该服务器支持处理和查询以下内容:
服务器默认使用OpenAI的API:
您可以自定义base_url参数来使用:
支持的文件格式包括:
max_workers控制并行文档处理