group
import { group } from '@routecraft/routecraft'
Transformer that groups an array into clusters using a comparator. Use with .transform(group(options)). By default it reads the body as the array and replaces the body with the array of clusters; use from / to to read and write sub-fields, and map to shape each cluster.
.transform(group({
comparator: cosine({ field: 'embedding', threshold: 0.82 }),
from: (body) => body.items,
map: (cluster) => ({ size: cluster.length, first: cluster[0] }),
}))
Options (GroupOptions):