9.7 Vector search
near
Definition. Scores each row by the cosine distance between a vector field and a query vector.
Syntax
near <vector.field>, [<number>, <number>, …]
near <vector.field>, $vector
Behavior
- Writes the distance to
_distance(0 means the same direction, 2 the opposite). - Rows without the field are discarded; a dimension mismatch is an error.
- It does not reorder rows: pair it with
sort _distance | limit kfor k nearest neighbours, or withwhere _distance < tfor a radius search. - Streaming; combine with filters before it to search within a subset.
Examples
on products | near embedding, [0.1, 0.9, 0.0] | select code, label, _distance | sort _distance | limit 2
{"_distance":0.006116265326381098,"code":"P3","label":"Phone"}
{"_distance":0.7804878048780488,"code":"P2","label":"Printer"}
on products | near embedding, [0.0, 1.0, 0.0] | where _distance < 0.5 | select code, _distance
on products | where category == "office" | near embedding, $vector | sort _distance | limit 5