What this thread does
Normalize corpus and query embeddings in host arithmetic before float32 serialization when sqlite-vec 0.1.9 returns infinite cosine distances for tiny finite vectors.
As of November 2026. This is a numerical guard for cosine retrieval in an agent memory store, not an embedding-model migration.
What changed
- JoeyLYZ666's September 29, 2026 report #324 shows finite inputs producing infinite distances on 0.1.9, including incorrect nearest-neighbor order. Calling
vec_normalize()on the same tiny inputs also produces non-finite output. - The 0.1.9 release note, dated March 31, concerns DELETE handling. MayCXC's October 23 proposal #338 addresses scalar and NEON cosine accumulation; it remains an open proposal rather than a release guarantee.
Do first:
1. Check SELECT vec_version(); and confirm the table uses distance_metric=cosine. The versioned report concerns 0.1.9. 2. Reject non-finite and zero vectors, then normalize before calling serialize_float32(). Apply the same conversion to stored embeddings and incoming queries. This Python containment recipe scales first so the host norm does not need to square the original extreme values:
import math
from sqlite_vec import serialize_float32
def cosine_blob(values, dimensions):
values = [float(v) for v in values]
if len(values) != dimensions or not values:
raise ValueError("wrong embedding dimension")
if not all(math.isfinite(v) for v in values):
raise ValueError("embedding must be finite")
scale = max(abs(v) for v in values)
if scale == 0:
raise ValueError("zero embedding has no cosine direction")
scaled = [v / scale for v in values]
norm = math.hypot(*scaled)
return serialize_float32([v / norm for v in scaled])
The Python math reference documents isfinite() and hypot(); the sqlite-vec Python guide documents float32 serialization. The host normalization is a mathematical containment recommendation, not a published sqlite-vec patch.
3. Rebuild affected stored embeddings from their original values using the same conversion. For the application's dimension and CPU build, compare nearest-neighbor order for an ordinary vector and a positively scaled copy before resuming retrieval. Scaling a nonzero vector should preserve its cosine direction.
Diagnostic: finite inputs produce infinite cosine distances
The report contrasts a query along the first axis with a stored vector scaled down to 1e-25: the mathematical distance stays zero, while 0.1.9 returns negative infinity. A finite-value check alone cannot catch this failure because the input itself is finite.
vlasky's October 5 response in the same issue attributes it to float32 accumulation and describes a scalar fix in a fork. That response explicitly excludes the upstream NEON path. PR #338 later proposes widening both paths; a scalar fork result does not establish identical behavior on an ARM vectorized build.
Limits
The API reference documents vec_normalize() as L2 normalization; that API contract does not establish numerical safety for these 0.1.9 inputs. Normalization changes L2 magnitudes, so this recipe is scoped to cosine retrieval. It does not recover values already rounded to an all-zero float32 vector. Zero vectors require rejection or a separate application policy.
Not for: choosing Ollama plus sqlite-vec, LanceDB or Chroma for a local RAG stack; see local-rag-stack-ollama-sqlite-vec-lancedb-or-chroma-private-docs.
Started from a post by @JoeyLYZ666, packaged by the editor. Original post