<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knn on INFINI Pizza</title><link>https://pizza.rs/tags/knn/</link><description>Recent content in Knn on INFINI Pizza</description><generator>Hugo</generator><language>en</language><atom:link href="https://pizza.rs/tags/knn/index.xml" rel="self" type="application/rss+xml"/><item><title>Vector query (kNN)</title><link>https://pizza.rs/docs/references/search/vector/vector/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pizza.rs/docs/references/search/vector/vector/</guid><description>&lt;h1 id="vector-query-knn">
 Vector query (kNN)
 &lt;a class="anchor" href="#vector-query-knn">#&lt;/a>
&lt;/h1>
&lt;p>Finds the &lt;code>k&lt;/code> nearest neighbors of a query vector — similarity search
over &lt;code>dense_vector&lt;/code> / &lt;code>sparse_vector&lt;/code> fields. The query vector can be
supplied directly, or as natural-language text that the serving layer
embeds with the field&amp;rsquo;s configured model (schema-driven semantic
search).&lt;/p>
&lt;h2 id="how-it-works">
 How it works
 &lt;a class="anchor" href="#how-it-works">#&lt;/a>
&lt;/h2>
&lt;p>Execution depends on where the documents live:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Realtime (not yet flushed)&lt;/strong> — an exact brute-force scan over the
mutable store: every vector is scored, a size-&lt;code>k&lt;/code> min-heap keeps the
best, and a filter (see below) is tested before any distance is
computed.&lt;/li>
&lt;li>&lt;strong>Flushed segments&lt;/strong> — the field&amp;rsquo;s &lt;code>index_type&lt;/code> decides: &lt;code>flat&lt;/code>
scans the stored f32 vectors (exact, &lt;code>O(N·dims)&lt;/code>); the graph types
(&lt;code>hnsw_flat&lt;/code>, &lt;code>turbo_quant_hnsw&lt;/code>, &lt;code>bbq_hnsw&lt;/code>) traverse the persisted
HNSW graph with distances computed on the flat vectors — scores stay
exact and only an &lt;code>ef&lt;/code>-bounded neighborhood is evaluated; the
quantized scans (&lt;code>turbo_quant&lt;/code>, &lt;code>bbq_flat&lt;/code>) score compact codes for
a &lt;code>k × oversampling&lt;/code> candidate pool and rescore it with full
precision (approximate). The per-type breakdown is in

 &lt;a href="#index-types">Index types&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>Scores follow the field&amp;rsquo;s &lt;code>similarity&lt;/code> (overridable per query, but it
must match the schema): &lt;code>cosine&lt;/code> is the cosine similarity in
&lt;code>[-1.0, 1.0]&lt;/code>; &lt;code>dot_product&lt;/code> the raw dot product; &lt;code>l2&lt;/code> scores as the
&lt;strong>negated squared&lt;/strong> Euclidean distance — &lt;code>0&lt;/code> means identical vectors.
Higher is always more similar, so one top-&lt;code>k&lt;/code> heap serves all three.&lt;/p></description></item></channel></rss>