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.
Metadata
Release files for mineru-rag 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mineru_rag-0.1.1.tar.gz | 14.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mineru_rag-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.9 kB
Release files / mineru_rag-0.1.1.tar.gz
| Download URL | mineru_rag-0.1.1.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e84451951acb363a651ab3416bf9bed5bbe6ca90e974d673d320b5bc0d65b333
|
|
BLAKE2b-256 checksum How to use checksums |
f85f3ee25b9cbdaf0a3684cb2316c51fd0ac219aa1d66a99086d58c0b3a007ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / mineru_rag-0.1.1-py3-none-any.whl
| Download URL | mineru_rag-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53e88a7a77c7a7912e991b2c9e0b9f9324d9a83d142a021e9d82088534082e90
|
|
BLAKE2b-256 checksum How to use checksums |
7fa4ddce940780abad595ee6bd77c660094a4102aa4ff9356da27c849a769a37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for mineru-rag 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.