-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose new hybrid chunker, update docs (#384)
Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
598 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Copyright IBM Corp. 2024 - 2024 | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
from docling_core.transforms.chunker.base import BaseChunk, BaseChunker, BaseMeta | ||
from docling_core.transforms.chunker.hierarchical_chunker import ( | ||
DocChunk, | ||
DocMeta, | ||
HierarchicalChunker, | ||
) | ||
from docling_core.transforms.chunker.hybrid_chunker import HybridChunker |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Introduction | ||
|
||
A *chunker* is a Docling abstraction that, given a | ||
[`DoclingDocument`](./docling_document.md), returns a stream of chunks, each of which | ||
captures some part of the document as a string accompanied by respective metadata. | ||
|
||
To enable both flexibility for downstream applications and out-of-the-box utility, | ||
Docling defines a chunker class hierarchy, providing a base type, `BaseChunker`, as well | ||
as specific subclasses. | ||
|
||
Docling integration with gen AI frameworks like LlamaIndex is done using the | ||
`BaseChunker` interface, so users can easily plug in any built-in, self-defined, or | ||
third-party `BaseChunker` implementation. | ||
|
||
## Base Chunker | ||
|
||
The `BaseChunker` base class API defines that any chunker should provide the following: | ||
|
||
- `def chunk(self, dl_doc: DoclingDocument, **kwargs) -> Iterator[BaseChunk]`: | ||
Returning the chunks for the provided document. | ||
- `def serialize(self, chunk: BaseChunk) -> str`: | ||
Returning the potentially metadata-enriched serialization of the chunk, typically | ||
used to feed an embedding model (or generation model). | ||
|
||
## Hybrid Chunker | ||
|
||
!!! note "To access `HybridChunker`" | ||
|
||
- If you are using the `docling` package, you can import as follows: | ||
```python | ||
from docling.chunking import HybridChunker | ||
``` | ||
- If you are only using the `docling-core` package, you must ensure to install | ||
the `chunking` extra, e.g. | ||
```shell | ||
pip install 'docling-core[chunking]' | ||
``` | ||
and then you | ||
can import as follows: | ||
```python | ||
from docling_core.transforms.chunker.hybrid_chunker import HybridChunker | ||
``` | ||
|
||
The `HybridChunker` implementation uses a hybrid approach, applying tokenization-aware | ||
refinements on top of document-based [hierarchical](#hierarchical-chunker) chunking. | ||
|
||
More precisely: | ||
|
||
- it starts from the result of the hierarchical chunker and, based on the user-provided | ||
tokenizer (typically to be aligned to the embedding model tokenizer), it: | ||
- does one pass where it splits chunks only when needed (i.e. oversized w.r.t. | ||
tokens), & | ||
- another pass where it merges chunks only when possible (i.e. undersized successive | ||
chunks with same headings & captions) — users can opt out of this step via param | ||
`merge_peers` (by default `True`) | ||
|
||
👉 Example: see [here](../../examples/hybrid_chunking). | ||
|
||
## Hierarchical Chunker | ||
|
||
The `HierarchicalChunker` implementation uses the document structure information from | ||
the [`DoclingDocument`](../docling_document) to create one chunk for each individual | ||
detected document element, by default only merging together list items (can be opted out | ||
via param `merge_list_items`). It also takes care of attaching all relevant document | ||
metadata, including headers and captions. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# IBM | ||
|
||
International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American multinational technology company headquartered in Armonk, New York and present in over 175 countries. | ||
|
||
It is a publicly traded company and one of the 30 companies in the Dow Jones Industrial Average. | ||
|
||
IBM is the largest industrial research organization in the world, with 19 research facilities across a dozen countries, having held the record for most annual U.S. patents generated by a business for 29 consecutive years from 1993 to 2021. | ||
|
||
IBM was founded in 1911 as the Computing-Tabulating-Recording Company (CTR), a holding company of manufacturers of record-keeping and measuring systems. It was renamed "International Business Machines" in 1924 and soon became the leading manufacturer of punch-card tabulating systems. During the 1960s and 1970s, the IBM mainframe, exemplified by the System/360, was the world's dominant computing platform, with the company producing 80 percent of computers in the U.S. and 70 percent of computers worldwide.[11] | ||
|
||
IBM debuted in the microcomputer market in 1981 with the IBM Personal Computer, — its DOS software provided by Microsoft, — which became the basis for the majority of personal computers to the present day.[12] The company later also found success in the portable space with the ThinkPad. Since the 1990s, IBM has concentrated on computer services, software, supercomputers, and scientific research; it sold its microcomputer division to Lenovo in 2005. IBM continues to develop mainframes, and its supercomputers have consistently ranked among the most powerful in the world in the 21st century. | ||
|
||
As one of the world's oldest and largest technology companies, IBM has been responsible for several technological innovations, including the automated teller machine (ATM), dynamic random-access memory (DRAM), the floppy disk, the hard disk drive, the magnetic stripe card, the relational database, the SQL programming language, and the UPC barcode. The company has made inroads in advanced computer chips, quantum computing, artificial intelligence, and data infrastructure.[13][14][15] IBM employees and alumni have won various recognitions for their scientific research and inventions, including six Nobel Prizes and six Turing Awards.[16] | ||
|
||
## 1910s–1950s | ||
|
||
IBM originated with several technological innovations developed and commercialized in the late 19th century. Julius E. Pitrap patented the computing scale in 1885;[17] Alexander Dey invented the dial recorder (1888);[18] Herman Hollerith patented the Electric Tabulating Machine (1889);[19] and Willard Bundy invented a time clock to record workers' arrival and departure times on a paper tape (1889).[20] On June 16, 1911, their four companies were amalgamated in New York State by Charles Ranlett Flint forming a fifth company, the Computing-Tabulating-Recording Company (CTR) based in Endicott, New York.[1][21] The five companies had 1,300 employees and offices and plants in Endicott and Binghamton, New York; Dayton, Ohio; Detroit, Michigan; Washington, D.C.; and Toronto, Canada.[22] | ||
|
||
Collectively, the companies manufactured a wide array of machinery for sale and lease, ranging from commercial scales and industrial time recorders, meat and cheese slicers, to tabulators and punched cards. Thomas J. Watson, Sr., fired from the National Cash Register Company by John Henry Patterson, called on Flint and, in 1914, was offered a position at CTR.[23] Watson joined CTR as general manager and then, 11 months later, was made President when antitrust cases relating to his time at NCR were resolved.[24] Having learned Patterson's pioneering business practices, Watson proceeded to put the stamp of NCR onto CTR's companies.[23]: 105 He implemented sales conventions, "generous sales incentives, a focus on customer service, an insistence on well-groomed, dark-suited salesmen and had an evangelical fervor for instilling company pride and loyalty in every worker".[25][26] His favorite slogan, "THINK", became a mantra for each company's employees.[25] During Watson's first four years, revenues reached $9 million ($158 million today) and the company's operations expanded to Europe, South America, Asia and Australia.[25] Watson never liked the clumsy hyphenated name "Computing-Tabulating-Recording Company" and chose to replace it with the more expansive title "International Business Machines" which had previously been used as the name of CTR's Canadian Division;[27] the name was changed on February 14, 1924.[28] By 1933, most of the subsidiaries had been merged into one company, IBM. | ||
|
||
## 1960s–1980s | ||
|
||
In 1961, IBM developed the SABRE reservation system for American Airlines and introduced the highly successful Selectric typewriter. |