langchain/docs
Luke f69695069d
text_splitters: Add HTMLSemanticPreservingSplitter (#25911)
**Description:** 

With current HTML splitters, they rely on secondary use of the
`RecursiveCharacterSplitter` to further chunk the document into
manageable chunks. The issue with this is it fails to maintain important
structures such as tables, lists, etc within HTML.

This Implementation of a HTML splitter, allows the user to define a
maximum chunk size, HTML elements to preserve in full, options to
preserve `<a>` href links in the output and custom handlers.

The core splitting begins with headers, similar to `HTMLHeaderSplitter`.
If these sections exceed the length of the `max_chunk_size` further
recursive splitting is triggered. During this splitting, elements listed
to preserve, will be excluded from the splitting process. This can cause
chunks to be slightly larger then the max size, depending on preserved
length. However, all contextual relevance of the preserved item remains
intact.

**Custom Handlers**: Sometimes, companies such as Atlassian have custom
HTML elements, that are not parsed by default with `BeautifulSoup`.
Custom handlers allows a user to provide a function to be ran whenever a
specific html tag is encountered. This allows the user to preserve and
gather information within custom html tags that `bs4` will potentially
miss during extraction.

**Dependencies:** User will need to install `bs4` in their project to
utilise this class

I have also added in `how_to` and unit tests, which require `bs4` to
run, otherwise they will be skipped.

Flowchart of process:


![HTMLSemanticPreservingSplitter](https://github.com/user-attachments/assets/20873c36-22ed-4c80-884b-d3c6f433f5a7)

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
2024-12-19 12:09:22 -05:00
..
api_reference docs: ganalytics in api ref (#28697) 2024-12-12 23:55:59 +00:00
cassettes text_splitters: Add HTMLSemanticPreservingSplitter (#25911) 2024-12-19 12:09:22 -05:00
data docs: 👥 Update LangChain people data (#27022) 2024-10-08 17:09:07 +00:00
docs text_splitters: Add HTMLSemanticPreservingSplitter (#25911) 2024-12-19 12:09:22 -05:00
scripts docs: integration providers index update (#28808) 2024-12-19 02:28:37 +00:00
src docs: Adding VoyageAI to 'integrations/text_embedding/' dropdown (#28817) 2024-12-19 09:29:30 -05:00
static community: update Memgraph integration (#27017) 2024-12-10 10:57:21 -05:00
.gitignore infra: cleanup docs build (#21134) 2024-05-01 17:34:05 -07:00
.yarnrc.yml docs[minor]: Add thumbs up/down to all docs pages (#18526) 2024-03-04 15:14:28 -08:00
babel.config.js Restructure docs (#11620) 2023-10-10 12:55:19 -07:00
docusaurus.config.js docs: throw on broken anchors (#27773) 2024-11-13 14:29:27 -05:00
ignore-step.sh docs: ignore case production fork master (#27971) 2024-11-07 13:55:21 -08:00
Makefile docs: more useful vercel warnings (#28699) 2024-12-13 03:07:24 +00:00
package.json docs: raw loader codeblock (#28548) 2024-12-06 09:26:34 -08:00
README.md docs: reorganize contributing docs (#27649) 2024-10-25 22:41:54 +00:00
sidebars.js docs: reorg sidebar (#27978) 2024-11-15 14:28:18 -08:00
vercel_requirements.txt docs: more useful vercel warnings (#28699) 2024-12-13 03:07:24 +00:00
vercel.json text_splitters: Add HTMLSemanticPreservingSplitter (#25911) 2024-12-19 12:09:22 -05:00
yarn.lock docs: raw loader codeblock (#28548) 2024-12-06 09:26:34 -08:00

LangChain Documentation

For more information on contributing to our documentation, see the Documentation Contributing Guide