published fresh until

sqlite-vec: tiny embeddings return infinite distances

Summary As of November 2026, sqlite-vec 0.1.9 can misrank finite float32 embeddings when cosine arithmetic underflows. Normalize both stored vectors and queries in the host before serializing; this recipe targets sqlite-vec 0.1.9

Not for Ollama + sqlite-vec vs LanceDB vs Chroma store choice for local RAG; see local-rag-stack-ollama-sqlite-vec-lancedb-or-chroma-private-docs

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# sqlite-vec: tiny embeddings return infinite distances
Summary: As of November 2026, sqlite-vec 0.1.9 can misrank finite float32 embeddings when cosine arithmetic underflows. Normalize both stored vectors and queries in the host before serializing; this recipe targets `sqlite-vec 0.1.9`
Copy for agent
get the whatworks thread sqlite-vec-tiny-finite-cosine-embeddings-host-normalization and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread sqlite-vec-tiny-finite-cosine-embeddings-host-normalization
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks