Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalDocument loadersDocument transformersText splittersHTMLHeaderTextSplitterSplit by characterSplit codeMarkdownHeaderTextSplitterRecursively split by characterSplit by tokensPost retrievalText embedding modelsVector storesRetrieversIndexingChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesRetrievalDocument transformersText splittersHTMLHeaderTextSplitterOn this pageHTMLHeaderTextSplitterDescription and motivation‚ÄãSimilar in concept to the MarkdownHeaderTextSplitter, the HTMLHeaderTextSplitter is a "structure-aware" chunker that splits text at the element level and adds metadata for each header "relevant" to any given chunk. It can return chunks element by element or combine elements with the same metadata, with the objectives of (a) keeping related text grouped (more or less) semantically and (b) preserving context-rich information encoded in document structures. It can be used with other text splitters as part of a chunking pipeline.Usage examples‚Äã1) With an HTML string:‚Äãfrom langchain.text_splitter import HTMLHeaderTextSplitterhtml_string ="""<!DOCTYPE html><html><body>    <div>        <h1>Foo</h1>        <p>Some intro text about Foo.</p>        <div>            <h2>Bar main section</h2>            <p>Some intro text about Bar.</p>            <h3>Bar subsection 1</h3>            <p>Some text about the first subtopic of Bar.</p>            <h3>Bar subsection 2</h3>            <p>Some text about the second subtopic of Bar.</p>        </div>        <div>            <h2>Baz</h2>            <p>Some text about Baz</p>        </div>        <br>        <p>Some concluding text about Foo</p>    </div></body></html>"""headers_to_split_on = [    ("h1", "Header 1"),
Description and motivation
Description and motivation ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalDocument loadersDocument transformersText splittersHTMLHeaderTextSplitterSplit by characterSplit codeMarkdownHeaderTextSplitterRecursively split by characterSplit by tokensPost retrievalText embedding modelsVector storesRetrieversIndexingChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesRetrievalDocument transformersText splittersHTMLHeaderTextSplitterOn this pageHTMLHeaderTextSplitterDescription and motivation‚ÄãSimilar in concept to the MarkdownHeaderTextSplitter, the HTMLHeaderTextSplitter is a "structure-aware" chunker that splits text at the element level and adds metadata for each header "relevant" to any given chunk. It can return chunks element by element or combine elements with the same metadata, with the objectives of (a) keeping related text grouped (more or less) semantically and (b) preserving context-rich information encoded in document structures. It can be used with other text splitters as part of a chunking pipeline.Usage examples‚Äã1) With an HTML string:‚Äãfrom langchain.text_splitter import HTMLHeaderTextSplitterhtml_string ="""<!DOCTYPE html><html><body>    <div>        <h1>Foo</h1>        <p>Some intro text about Foo.</p>        <div>            <h2>Bar main section</h2>            <p>Some intro text about Bar.</p>            <h3>Bar subsection 1</h3>            <p>Some text about the first subtopic of Bar.</p>            <h3>Bar subsection 2</h3>            <p>Some text about the second subtopic of Bar.</p>        </div>        <div>            <h2>Baz</h2>            <p>Some text about Baz</p>        </div>        <br>        <p>Some concluding text about Foo</p>    </div></body></html>"""headers_to_split_on = [    ("h1", "Header 1"),