切分文檔構建RAG庫過程中,langchain、llamaindex更期望處理latex、md類帶有顯式結構文檔。
langchain、llamaindex切分word,有可能將段落中間截斷,導致切分后的塊語義不完整。
所以,需要先將word轉化為md格式,然后再進行切分構建RAG知識庫。
目前效果較好的word轉md工具,要么是需要付費的商業版,要么借助于LLM轉化,而LLM調用同樣需要付費。
微軟的word轉md的開源工具markitdown,可以達到類似效果,適合文檔分析和內容索引場景。
這里示例markitdown的下載和使用過程。
1 markitdown安裝
1)python環境構建
conda create -n markitdown python=3.12
conda activate markitdown
2)markitdown安裝
如果git clone失敗,可以直接從如下鏈接下載,然后pip安裝。
https://github.com/microsoft/markitdown/archive/refs/tags/v0.1.2.zip
git clone git@github.com:microsoft/markitdown.git
cd markitdown
pip install -e 'packages/markitdown[all]'
2 markidwon 示例
word文件轉md文件
markitdown test.docx > document.md
pdf文件轉md文件
markitdown test.pdf > pdf.md
整體看word轉pdf后能較好的保持文檔結構,pdf轉md會丟失文檔結構。
reference
---
markdidown
https://github.com/microsoft/markitdown
RAG向量化文檔分塊方式探索
https://blog.csdn.net/liliang199/article/details/149798215
借助于llm將pdf轉化為md文本
https://blog.csdn.net/liliang199/article/details/149808465