类功能
功能描述
继承实现langchain_core.document_loaders.base.BaseLoader类和mx_rag.document.loader.BaseLoader类,执行Markdown解析功能,支持.md,.markdown格式的文件(文件大小不能超过100MB),可解析文档中的图片信息和表格信息,传入视觉大模型对象可支持图片解析总结。MarkdownLoader首次使用时需要联网下载NLTK分词模型,出于安全考虑,默认不自动下载,如果报错可自行下载NLTK分词模型文件至nltk.data.path变量指定的路径下。
函数原型
from mx_rag.document.loader import MarkdownLoader MarkdownLoader(file_path, vlm, process_images_separately)
参数说明
参数名 |
数据类型 |
可选/必选 |
说明 |
|---|---|---|---|
file_path |
str |
必选 |
Markdown文件路径,路径长度取值范围为[1,1024]。文档路径不能为软链接且不允许存在"..",文档大小≤100MB。 |
vlm |
Img2TextLLM |
可选 |
视觉大模型对象,可解析文档中的图片信息生成图片总结,具体可参见Img2TextLLM |
process_images_separately |
bool |
可选 |
图片信息是否单独解析,若值为True,会将图片信息单独解析生成一个Document对象,默认为False,即将图片信息与其他Markdown内容合并解析生成一个Document对象。 |
调用示例
from mx_rag.document.loader import MarkdownLoader
from mx_rag.llm import Img2TextLLM, LLMParameterConfig
from mx_rag.utils import ClientParam
vlm = Img2TextLLM(base_url="https://{ip}:{port}/openai/v1/chat/completions",
model_name="Qwen2.5-VL-7B-Instruct",
llm_config=LLMParameterConfig(max_tokens=512),
client_param=ClientParam(ca_file="/path/to/ca.crt")
)
loader = MarkdownLoader("/path/to/document.md", vlm=vlm, process_images_separately=False)
docs = loader.lazy_load()
print(list(docs))
父主题: MarkdownLoader