Chunker langbase.chunker()
You can use the chunker()
function to split your content into smaller chunks. This is especially useful for RAG pipelines or when you need to work with only specific sections of a document.
Generate a User/Org API key
You will need to generate an API key to authenticate your requests. For more information, visit the User/Org API key documentation.
API reference
langbase.chunker(options)
Split content into chunks by running langbase.chunker()
function.
Function Signature
langbase.chunker(options);
// with types
langbase.chunker(options: ChunkerOptions);
options
- Name
options
- Type
- ChunkerOptions
- Description
ChunkerOptions Object
interface ChunkerOptions { content: string; chunkMaxLength?: number; chunkOverlap?: number; }
Following are the properties of the options object.
content
- Name
document
- Type
- string
- Required
- Required
- Description
The content of the document to be chunked.
chunkMaxLength
- Name
chunkMaxLength
- Type
- string
- Description
The maximum length for each document chunk. Must be between
1024
and30000
characters.Default:
1024
chunkOverlap
- Name
chunkOverlap
- Type
- string
- Description
The number of characters to overlap between chunks. Must be greater than or equal to
256
and less than chunkMaxLength.Default:
256
Usage example
Install the SDK
npm i langbase
Environment variables
.env file
LANGBASE_API_KEY="<USER/ORG-API-KEY>"
langbase.chunker()
examples
langbase.chunker()
import { Langbase } from 'langbase';
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
const content = `Langbase is the most powerful serverless AI platform for building AI agents with memory. Build, deploy, and scale AI agents with tools and memory (RAG). Simple AI primitives with a world-class developer experience without using any frameworks.`;
const chunks = await langbase.chunker({
content,
chunkMaxLength: 1024,
chunkOverlap: 256
});
console.log('Chunks:', chunks);
}
main();
Response
The response of langbase.chunker()
function is a Promise
that resolves to an array of string.
ChunkerResponse Type
type ChunkerResponse = string[];
- Name
response
- Type
- string[]
- Description
Array of text chunks created from the input document.
ChunkerResponse Example
[
"Langbase is the most powerful serverless AI platform for building AI agents with memory. Build, deploy, and scale AI agents with tools and memory (RAG). Simple AI primitives with a world-class developer experience without using any frameworks."
]