跳到主内容
@wquguru
精选86r/Rag(Reddit)产品发布/更新

LlamaIndex发布CleanWeb Reader:高效清洗网页噪声

[Release] CleanWeb Reader for LlamaIndex: Stop drowning your Vector Index in web boilerplate (87% Token Compression & Alt-Text Preservation)

原文
发到 X
推荐理由

RAG工程痛点清晰,给出具体代码示例与参数配置,能直接落地优化向量索引质量,值得开发者收藏压测。

Hey r/LlamaIndex community! 👋

嘿,r/LlamaIndex 社区的伙伴们!👋

If you’ve ever built a web-grounded RAG pipeline using standard web loaders, you know the frustration: scraping a 20-page documentation site or news feed dumps tens of thousands of tokens of navigation menus, cookie banners, tracking scripts, and footer links straight into your document chunks.

如果你曾使用标准的网页加载器构建过基于网页的 RAG(检索增强生成)管道,你就会知道其中的挫败感:抓取一个包含 20 页的文档站点或新闻源时,导航菜单、Cookie 横幅、跟踪脚本和页脚链接等成千上万个 token 会被直接注入到你的文档块中。

This severely degrades vector embedding retrieval quality, pollutes chunk similarity scores, and inflates embedding/inference costs.

这会严重降低向量嵌入检索的质量,污染块相似度评分,并增加嵌入/推理的成本。

To solve this, we built and published \*\*\`llama-index-readers-x402-cleanweb\`\*\* to PyPI!

为了解决这个问题,我们构建并发布了一个名为 **`llama-index-readers-x402-cleanweb`** 的库到 PyPI!

\---

\### ⚡ What it does for your RAG Pipeline:

### ⚡ 它为你的 RAG 管道带来的好处:

  • \*\*87% Token Compression Before Ingestion\*\*:
  • \- Strips ads, navigation bars, cookie popups, and boilerplate DOM containers, returning clean, semantically structured Markdown ready for chunking.
  • \*\*Zero Ingestion Contamination (Indirect Prompt Injection Defense)\*\*:
  • \- Automatically sanitizes hidden CSS text (\`display:none\`, \`font-size:0px\`), zero-width Unicode steganography, and tracking pixels before documents hit your index.
  • \*\*Multimodal Alt-Text Preservation\*\*:
  • \- Preserves meaningful image captions (\`!\[architecture diagram\](url)\`) for visual LLMs/multimodal indexes while neutralizing 1x1 tracking beacons.
  • \*\*Zero-Overhead SPA Hydration Parsing\*\*:
  • \- Extracts pre-rendered state from Next.js (\`\_\_NEXT\_DATA\_\_\`) and Nuxt.js (\`\_\_NUXT\_DATA\_\_\`) directly in pure Python without spinning up heavy headless browsers.
  • \*\*Native LlamaIndex Compatibility\*\*:
  • \- Subclasses \`BaseReader\`, returning standard \`List\[Document\]\` with rich metadata (\`source\`, \`title\`, \`content\_hash\`, \`token\_reduction\_percent\`).
  • **摄入前 Token 压缩率达 87%**:
  • - 剥离广告、导航栏、Cookie 弹窗和样板 DOM 容器,返回干净且语义结构化的 Markdown,准备好进行分块处理。
  • **零摄入污染(间接提示注入防御)**:
  • - 在文档进入索引之前,自动清理隐藏的 CSS 文本(`display:none`、`font-size:0px`)、零宽度 Unicode 隐写术以及跟踪像素。
  • **多模态替代文本保留**:
  • - 为视觉 LLM/多模态索引保留有意义的图片标题(`![architecture diagram](url)`),同时中和 1x1 跟踪信标。
  • **零开销 SPA 水合解析**:
  • - 直接从纯 Python 中提取 Next.js(`__NEXT_DATA__`)和 Nuxt.js(`__NUXT_DATA__`)的预渲染状态,无需启动沉重的无头浏览器。
  • **原生 LlamaIndex 兼容性**:
  • - 继承自 `BaseReader`,返回带有丰富元数据(`source`、`title`、`content_hash`、`token_reduction_percent`)的标准 `List[Document]`。

\---

\### 📦 Quickstart

### 📦 快速开始

Install directly from PyPI:

直接从 PyPI 安装:

\`\`\`bash

代码 · 1 行
```bash

pip install llama-index-readers-x402-cleanweb

\`\`\`

Ingest clean web documents into your VectorStoreIndex:

将干净的网页文档摄入到你的 VectorStoreIndex 中:

\`\`\`python

代码 · 1 行
```python

from llama\_index.readers.x402\_cleanweb import X402CleanWebReader

from llama_index.readers.x402_cleanweb import X402CleanWebReader

from llama\_index.core import VectorStoreIndex

from llama_index.core import VectorStoreIndex

\# 1. Initialize reader (includes 5 free sandbox calls per session)

# 1. 初始化阅读器(每个会话包含 5 次免费沙盒调用)

reader = X402CleanWebReader

\# 2. Ingest clean, noise-free web documents

# 2. 摄取干净、无噪声的网页文档

documents = reader.load\_data(

documents = reader.load_data(

urls=\["https://en.wikipedia.org/wiki/Retrieval-augmented\\\_generation"\\\],

urls=["https://en.wikipedia.org/wiki/Retrieval-augmented_generation"],

preserve\_alt\_text=True

preserve_alt_text=True

)

print(f"Loaded {len(documents)} document(s). Metadata: {documents\[0\].metadata}")

print(f"Loaded {len(documents)} document(s). Metadata: {documents[0].metadata}")

\# 3. Build Vector Store Index directly with clean chunks

# 3. 直接使用干净的块构建向量存储索引

index = VectorStoreIndex.from\_documents(documents)

index = VectorStoreIndex.from_documents(documents)

query\_engine = index.as\_query\_engine

query_engine = index.as_query_engine

response = query\_engine.query("What are the key benefits of RAG?")

response = query_engine.query("What are the key benefits of RAG?")

print(response)

\`\`\`

\---

\### 🆓 Free Tier & M2M Micropayments

### 🆓 免费层级与机器对机器(M2M)微支付

Every session nonce comes with \*\*5 free zero-configuration trial calls\*\* out of the box (no API keys, credit cards, or wallet setup needed). For autonomous production agent pipelines, native USDC machine-to-machine micropayments ($0.001 per page) over Base, Polygon, Arbitrum, and Solana are supported.

每个会话 nonce 默认附带 **5 次免费的零配置试用调用**(无需 API 密钥、信用卡或钱包设置)。对于自主生产代理管道,支持在 Base、Polygon、Arbitrum 和 Solana 上进行的原生 USDC 机器对机器微支付(每页 $0.001)。

\* \*\*PyPI\*\*: [https://pypi.org/project/llama-index-readers-x402-cleanweb/0.1.0/\](https://pypi.org/project/llama-index-readers-x402-cleanweb/0.1.0/)

* **PyPI**: [https://pypi.org/project/llama-index-readers-x402-cleanweb/0.1.0/](https://pypi.org/project/llama-index-readers-x402-cleanweb/0.1.0/)

\* \*\*GitHub\*\*: [https://github.com/nohosa001-pixel/x402-cleanweb-agent\](https://github.com/nohosa001-pixel/x402-cleanweb-agent)

* **GitHub**: [https://github.com/nohosa001-pixel/x402-cleanweb-agent](https://github.com/nohosa001-pixel/x402-cleanweb-agent)

Would love to hear how you currently clean web content before chunking and what loaders you're using in production! 🚀

很想知道你们目前在分块前如何清理网页内容,以及在生产中使用了哪些加载器!🚀

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件