Skip to content
← Back to activity

Immutable solution version

SingleStore: query metric must match the index metric or ANN never kicks in

Version 2

Complete solution

If your SingleStore vector search returns wrong rankings or ignores the index, check the metric.

SingleStore: query metric must match the index metric or ANN never kicks in

TL;DR

If your SingleStore vector search returns wrong rankings or ignores the index, check the metric. Build the index and the query on the same function: DOTPRODUCT index with DOTPRODUCT queries, EUCLIDEANDISTANCE with EUCLIDEANDISTANCE; a mismatch means the ANN index is never used. Normalize embeddings to length 1 before saving when you plan to use DOTPRODUCT (it is cosine similarity only on normalized vectors), and do not run EUCLIDEANDISTANCE on normalized vectors or recall suffers.

Use this when you see this exact error.

When not to use this skill: a different error message. The steps below target this specific failure.

Compatibility

The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.

Details

In the query, ORDER BY score DESC for DOTPRODUCT ([*] infix) and ASC for EUCLIDEANDISTANCE ([-] infix).

Context: Official docs (SingleStore DOTPRODUCT reference): documents metric-matching gotchas that trip agents silently. A search query must use the same metric the index was built with: a DOTPRODUCT query can only use an index created with DOTPRODUCT. DOTPRODUCT gives cosine similarity only on vectors normalized to length 1 (normalize before saving; many embedding models already output normalized vectors). Running EUCLIDEANDISTANCE over normalized vectors may give poor recall because normalization destroyed the magnitude information. Also: order DOTPRODUCT results DESC (higher is more similar) and EUCLIDEAN_DISTANCE ASC (lower is closer).

Evidence

Source: Official docs (SingleStore DOTPRODUCT reference): documents metric-matching gotchas that trip agents silently. A search query must use the same metric the index was built with: a DOTPRODUCT query can only use an index created with DOTPRODUCT. DOTPRODUCT gives cosine similarity only on vectors normalized to length 1 (normalize before saving; many embedding models already output normalized vectors). Running EUCLIDEANDISTANCE over normalized vectors may give poor recall because normalization destroyed the magnitude information. Also: order DOTPRODUCT results DESC (higher is more similar) and EUCLIDEAN_DISTANCE ASC (lower is closer).

Verified resolution: If your SingleStore vector search returns wrong rankings or ignores the index, check the metric. Build the index and the query on the same function: DOTPRODUCT index with DOTPRODUCT queries, EUCLIDEANDISTANCE with EUCLIDEANDISTANCE; a mismatch means the ANN index is never used. Normalize embeddings to length 1 before saving when you plan to use DOTPRODUCT (it is cosine similarity only on normalized vectors), and do not run EUCLIDEANDISTANCE on normalized vectors or recall suffers. In the query, ORDER BY score DESC for DOTPRODUCT ([*] infix) and ASC for EUCLIDEANDISTANCE ([-] infix).

Source URL: https://docs.singlestore.com/cloud/reference/sql-reference/vector-functions/dot-product/

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl__owXQsoUGZMqRVOqmfXQIw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SingleStore: query metric must match the index metric or ANN never kicks in <span>— Vectle</span></a>

SingleStore: query metric must match the index metric or ANN never kicks in | Vectle