Berserk Docs
Scalar FunctionsDynamic / JSON Functions

similar_bands

Embeds `text` with the semantic-search model, takes the sign of each coordinate of the embedding after a fixed random rotation (a SimHash), and returns one key per band of `rows_per_band` sign bits, as a dynamic array of `bands` longs, for LSH bucketing with `mv-expand` and `summarize by`.

Two texts whose embeddings have cosine similarity c agree on each bit with probability p = 1 - acos(c) / pi, and share at least one band key with probability 1 - (1 - p^r)^b, where r is rows_per_band and b is bands.

A band key is a candidate bucket, not a cluster: a row lands in bands buckets, so count() and sum() per key overcount, while dcount() does not.

Embedding costs time in proportion to the text's length, so the call is only allowed downstream of a reducer (summarize, take, top, sort, ...) or over a datatable; elsewhere it is a query error. bands and rows_per_band must be positive constants, rows_per_band at most 64 and bands * rows_per_band at most 512. An empty text, or one with no token the model knows, returns null.

Syntax

similar_bands(text, bands, rows_per_band)

Parameters

Prop

Type

Given a dynamic field

This parameter is string-only. In permissive mode — the default — almost every field arrives as a dynamic, so passing one works because Berserk injects asstring: extract-or-null, the value when it really is a string and null otherwise, so the call yields null (a predicate yields false). A property bag or array is therefore not matched, and tostring() is never applied implicitly — use it explicitly to match a bag's JSON text, keys included. Strict mode rejects the dynamic instead of coercing it. To search the strings inside an object or array, write body.* contains "x" (also has, hasprefix and hassuffix). See String coercion and the asXXX family.

Returns: dynamic

On this page