# PolygMirror-py **Repository Path**: codergit.com/polyg-mirror-py ## Basic Information - **Project Name**: PolygMirror-py - **Description**: PolygMirror对应的python工程 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-16 - **Last Updated**: 2026-06-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PolygMirror-py 将网页 URL 转换为 PDF,提取 PDF 文本和图片 OCR 内容,分块后使用 Ollama Embedding 写入 Chroma 向量库。 ## 核心流程 ```text URL -> PDF -> 文本分块 -> Ollama Embedding -> Chroma 向量库 ``` ## 环境要求 - Python >= 3.14 - 本地 Ollama 服务:`http://localhost:11434` - Ollama embedding 模型:`bge-m3` - Playwright Chromium 浏览器 安装依赖后,需要安装 Playwright 浏览器: ```bash playwright install chromium ``` ## 使用方式 推荐使用脚本入口: ```bash python rag-url-skill/scripts/run.py "https://example.com/article" --output-dir ./pdfs ``` 输出 JSON: ```bash python rag-url-skill/scripts/run.py "https://example.com/article" --output-dir ./pdfs --json ``` 作为库调用: ```python from rag_skill import process_url result = process_url("https://example.com/article", output_dir="./pdfs") print(result) ``` 分步调用: ```python from rag_skill import chunks_to_vectordb, pdf_to_chunks, url_to_pdf pdf_path = url_to_pdf("https://example.com/article", output_dir="./pdfs") chunks = pdf_to_chunks(pdf_path) chunks_to_vectordb(chunks) ``` 查询 Chroma: ```python from rag_skill import query_chroma results = query_chroma("JDK17 和 ZGC 的实践有哪些?", k=3) ``` ## 配置 默认配置在 `rag-url-skill/resources/config.yaml`: ```yaml persist_directory: /Users/coderman/profiles/chroma/data/interview ollama_url: http://localhost:11434 embedding_model: bge-m3 chunk_size: 500 chunk_overlap: 50 ``` 也可以通过环境变量指定其他配置文件: ```bash RAG_SKILL_CONFIG=/path/to/config.yaml python rag-url-skill/scripts/run.py "https://example.com" ``` ## 目录说明 - `rag_skill/`:库代码,包含 URL 转 PDF、PDF 分块、写入和查询 Chroma 的核心 API。 - `rag-url-skill/`:Agent Skill 风格封装,包含说明文档、配置和脚本入口。 - `langchain_rag_pdf.py`:完整 RAG 流程 demo,调用 `rag_skill` 库 API。 - `playwrightdemo.py`:仅演示 URL 转 PDF。 - `pdf_parse.py`:仅演示 PDF 分块和 OCR 解析。 - `fectch_url_demo.py`:直接抓网页文本的对照 demo,不走 PDF 流程。 - `csdn_parse_pdf.py`:CSDN 特化的 PDF 生成逻辑。 - `OllamaImageBlobParser.py`:Ollama 多模态图片解析实验代码,当前为注释示例。 ## 注意事项 - `process_url` 会捕获异常并返回 `status: failed`,CLI 会根据结果返回退出码。 - CSDN URL 默认会使用 `csdn_parse_pdf.py` 中的特化转换逻辑;也可以通过 `--csdn` 或 `--no-csdn` 强制指定。 - `fectch_url_demo.py` 是对照实验,适合纯文本网页抓取;如果需要保留页面图片或 OCR 图片文字,优先使用 PDF 流程。