| embedding_distance | R Documentation |
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.
cosine(x, y)
l2(x, y)
dot(x, y)
x |
An embedding column. |
y |
An embedding column, or a constant numeric query vector. |
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()).
A double column.
as_embedding()
## Not run:
q <- rnorm(128)
tbl("vecs.vtr") |>
mutate(d = cosine(emb, q)) |>
slice_min(d, n = 10) |>
collect()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.