embedding_distance: Embedding distance functions

embedding_distanceR Documentation

Embedding distance functions

Description

Distance and similarity functions over embedding columns (see as_embedding()), usable inside mutate() / filter() like any other expression. The query side is either another embedding column or a constant numeric vector. Decoding and the arithmetic run in C, one row at a time, parallelized over rows.

Usage

cosine(x, y)

l2(x, y)

dot(x, y)

Arguments

x

An embedding column.

y

An embedding column, or a constant numeric query vector.

Details

cosine() returns cosine distance (1 - similarity) and l2() Euclidean distance, so smaller means nearer – pair them with slice_min() for nearest-neighbour search. dot() returns the inner product, where larger means nearer (slice_max()).

Value

A double column.

See Also

as_embedding()

Examples

## Not run: 
q <- rnorm(128)
tbl("vecs.vtr") |>
  mutate(d = cosine(emb, q)) |>
  slice_min(d, n = 10) |>
  collect()

## End(Not run)


vectra documentation built on July 10, 2026, 5:08 p.m.