Recursive Splitter
Unstable API
0.8.0
@project-lakechain/recursive-character-text-splitter
The recursive character text splitter can be used to split text documents at scale based on a set of delimiters, a maximum chunk size, and a given chunk overlap. This implementation is based on Langchainβs RecursiveCharacterTextSplitter
.
π Splitting Text
To use this middleware, you import it in your CDK stack, and connect it to a data source providing text documents, such as the S3 Trigger.
Options
You can customize the way that the text splitter will split text documents by specifying a custom delimiter string, a maximum chunk size, and a chunk overlap.
βΉοΈ The below example splits text documents based on a maximum chunk size of
4096
characters, and a chunk overlap of200
.
The default values for this middleware options are documented below.
Option | Default | Description |
---|---|---|
separators | β\n\nβ, β\nβ, β β, "" | The delimiters used to split text. |
chunkSize | 4000 | The maximum size of each text chunk. |
chunkOverlap | 200 | The characters to overlap between chunks. |
π Output
This middleware takes as an input text documents of a given size, and outputs multiple text documents that are the result of the text splitting process. This allows to process each chunk of text in parallel in downstream middlewares.
In addition to producing new text documents, this middleware also associates metadata with each chunk, such as the chunk identifier and order relative to the original document. Below is an example of CloudEvent
produced by this middleware.
π Click to expand example
ποΈ Architecture
This middleware runs within a Lambda compute based on the ARM64 architecture, and packages the Langchain library to run the text splitting process.
π·οΈ Properties
Supported Inputs
Mime Type | Description |
---|---|
text/plain | UTF-8 text documents. |
Supported Outputs
Mime Type | Description |
---|---|
text/plain | UTF-8 text documents. |
Supported Compute Types
Type | Description |
---|---|
CPU | This middleware only supports CPU compute. |
π Examples
- Text Splitting Pipeline - Builds a pipeline for splitting text documents using different text splitting algorithms.
- RAG Pipeline - End-to-end RAG pipeline using Amazon Bedrock and Amazon OpenSearch.