HtmlRAG uses HTML's native structure to make RAG systems smarter and more accurate
Finds HTML beats plain text for knowledge retrieval in RAG systems
https://arxiv.org/abs/2411.02959
Original Problem π€:
Traditional RAG systems convert HTML to plain text, losing valuable structural and semantic information like headings and table layouts. Raw HTML documents are extremely long (80K+ tokens) and contain lots of noise like CSS/JavaScript, making them unsuitable for direct use in RAG systems.
-----
Solution in this Paper π οΈ:
β HtmlRAG preserves HTML structure instead of converting to plain text, keeping semantic information intact through three key components
β An HTML Cleaning module removes irrelevant content like CSS/JavaScript and compresses redundant structures while preserving semantic information, reducing document size to 6% of original
β A Block Tree Construction builds an optimized tree structure from the DOM tree that can be adjusted for different pruning requirements
β A Two-Step HTML Pruning first uses embedding models to prune less relevant blocks at a coarse level, then uses a generative model for finer-grained pruning of remaining blocks
-----
Key Insights π‘:
β LLMs already have HTML understanding capabilities from pre-training, making HTML a natural format for knowledge representation
β HTML can effectively represent other document formats (PDF, Word etc.) with minimal information loss
β A block-tree structure enables more efficient HTML processing than working directly with DOM trees
β Two-stage pruning combining embedding and generative models provides better results than single-stage approaches
-----
Results π:
β Tested on 6 QA datasets including ambiguous QA, natural QA, multi-hop QA, and long-form QA
β Outperformed baseline methods using plain text, with improvements in metrics like Exact Match and Hit@1
β HTML cleaning reduced document size to 6% of original while preserving key information










