Whatever message this page gives is out now! Go check it out!

transformSegments

Last update:
May 18, 2026
Applies a UDF transformation to each text segment produced by split(). Use to post-process chunks after splitting, for example, to add metadata or normalise content before embedding.

Syntax

docService.transformSegments(segments, transformer)

Parameters

Parameter
Type
Required
Description
segments
Array
Required
Array of text segment Structs as returned by split().
transformer
UDF / Closure
Required
Function with signature function(required Struct segment) that returns a modified segment Struct.

Returns

Returns an Array of transformed text segment Structs.

Example

enriched = docService.transformSegments(segments, function(required segment) {
    segment.metadata.processedAt = now();
    segment.metadata.wordCount   = listLen(segment.text, " ");
    return segment;
});

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page