A Python package for MinerU document processing and RAG knowledge base construction
Project description
MinerU RAG
A Python package for MinerU document processing and RAG (Retrieval-Augmented Generation) knowledge base construction.
Features
- 📄 MinerU Integration: Support both online MinerU API and local vLLM backend
- 🤖 RAG Knowledge Base: Easy-to-use RAG system for building knowledge bases
- 🔗 LLM Connection: Seamless integration with LLM APIs
- 🚀 Simple API: Clean and intuitive Python API
Installation
pip install mineru-rag
For RAG functionality, install with extras:
pip install mineru-rag[rag]
📖 详细使用文档请查看 USER_GUIDE.md
Quick Start
1. Process Documents with MinerU
Using Online API
from mineru_rag import MinerUClient
# Initialize client with API token
client = MinerUClient(api_token="your-mineru-api-token")
# Process a single file
result = client.process_file(
input_path="document.pdf",
output_path="./output"
)
# Process multiple files
results = client.process_files_batch(
file_paths=["doc1.pdf", "doc2.pdf"],
output_dir="./output"
)
Using Local vLLM Backend
from mineru_rag import MinerUClient
# Initialize client for local mode
# Make sure MinerU vLLM backend is running at http://127.0.0.1:30000
client = MinerUClient(use_local=True, local_url="http://127.0.0.1:30000")
# Process files (same API as online mode)
result = client.process_file(
input_path="document.pdf",
output_path="./output"
)
2. Build RAG Knowledge Base
from mineru_rag import RAGBuilder
from pathlib import Path
# Initialize RAG builder
rag = RAGBuilder()
# Build from processed markdown files
markdown_files = [
Path("./output/doc1/full.md"),
Path("./output/doc2/full.md")
]
rag.build_from_files(
file_paths=markdown_files,
library_id="my_library"
)
# Or load existing vector store
rag.load_vector_store(library_id="my_library")
3. Query with LLM
from mineru_rag import LLMClient, RAGBuilder
# Initialize LLM client
llm = LLMClient(
api_key="your-openai-api-key",
base_url="http://your-api-server/v1/",
model="gpt-3.5-turbo"
)
# Initialize RAG builder
rag = RAGBuilder()
rag.load_vector_store(library_id="my_library")
# Query
rag_result = rag.query("What is the main contribution of this paper?", k=4)
answer = llm.query_with_rag(rag_result)
print(answer['answer'])
4. Complete Workflow
from mineru_rag import MinerUClient, RAGBuilder, LLMClient
from pathlib import Path
# 1. Process documents
client = MinerUClient(api_token="your-mineru-api-token")
result = client.process_file("paper.pdf", "./output")
# 2. Build RAG knowledge base
rag = RAGBuilder()
md_file = Path(result['md_file'])
rag.build_from_files([md_file], library_id="papers")
# 3. Query
llm = LLMClient(
api_key="your-api-key",
base_url="http://your-api-server/v1/"
)
rag.load_vector_store("papers")
rag_result = rag.query("What are the key findings?", k=4)
answer = llm.query_with_rag(rag_result)
print(answer['answer'])
Configuration
Environment Variables
MinerU Online API
export MINERU_API_TOKEN="your-mineru-api-token"
LLM API
export OPENAI_API_KEY="your-openai-api-key"
export OPENAI_BASE_URL="http://your-api-server/v1/"
export OPENAI_MODEL="gpt-3.5-turbo"
export OPENAI_TEMPERATURE="0.7"
Local MinerU vLLM Backend
To use local MinerU vLLM backend:
- Install MinerU and start vLLM backend:
# Install MinerU (follow MinerU documentation)
# Start vLLM backend on port 30000
- Use local mode:
client = MinerUClient(use_local=True, local_url="http://127.0.0.1:30000")
Command Line Usage
Process Documents
# Online mode
mineru-rag process document.pdf -o ./output --api-token your-token
# Local mode
mineru-rag process document.pdf -o ./output --local --local-url http://127.0.0.1:30000
Build RAG Knowledge Base
mineru-rag build doc1.md doc2.md -l my_library
Query RAG
mineru-rag query "What is the main contribution?" -l my_library -k 4
API Reference
MinerUClient
process_file(input_path, output_path, ...): Process a single fileprocess_files_batch(file_paths, output_dir, ...): Process multiple files
RAGBuilder
build_from_files(file_paths, library_id, ...): Build vector database from filesload_vector_store(library_id): Load existing vector databasequery(question, k, file_id): Query the knowledge base
LLMClient
query(question, context): Query LLM with contextquery_with_rag(rag_result): Query LLM with RAG result
📚 文档
- USER_GUIDE.md - 完整用户使用文档(推荐阅读)
- QUICKSTART.md - 快速开始指南
- examples/ - 使用示例代码
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mineru_rag-0.1.1.tar.gz.
File metadata
- Download URL: mineru_rag-0.1.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e84451951acb363a651ab3416bf9bed5bbe6ca90e974d673d320b5bc0d65b333
|
|
| MD5 |
1b917353c5fdefe2e18b4c79d9e07ec9
|
|
| BLAKE2b-256 |
f85f3ee25b9cbdaf0a3684cb2316c51fd0ac219aa1d66a99086d58c0b3a007ec
|
File details
Details for the file mineru_rag-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mineru_rag-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53e88a7a77c7a7912e991b2c9e0b9f9324d9a83d142a021e9d82088534082e90
|
|
| MD5 |
5142f596c877873b4bbc999753081216
|
|
| BLAKE2b-256 |
7fa4ddce940780abad595ee6bd77c660094a4102aa4ff9356da27c849a769a37
|