Skip to content

[core] Validate ANN segment metric against the built-in metric - #10264

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:m/core-063-vector-metric
Open

LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:m/core-063-vector-metric

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Purpose

PkVectorAnnSegmentSearcher is meant to reject searching an ANN segment whose distance metric differs from the configured one, but the guard compares two values that both come from the current table configuration, so it is always true and never rejects anything. Once the configured metric changes, the already-built segments are scored with the new metric and the nearest-neighbor results are silently wrong.

This records the metric each ANN segment was built with in VectorIndexMeta and exposes it through a new VectorGlobalIndexer.segmentMetric(byte[]), a default method that returns null and is overridden by NativeVectorGlobalIndexer. The searcher now compares the segment's recorded metric against the configured metric and fails fast on a mismatch. Segments written before this change carry no metric and are treated as exempt, so existing indexes keep working, and other VectorGlobalIndexer implementations that record no metric return null and are skipped.

This closes #10263.

Tests

  • PkVectorAnnSegmentSearcherMetricTest pins the guard: a matching metric passes, a differing metric fails fast, a legacy segment with no recorded metric is exempt, and alias or case differences (both sides go through the same normalize) do not falsely reject.
  • VectorIndexMetaTest pins that the metric round-trips through the segment metadata and that legacy metadata carrying no metric deserializes to null.

API and Format

The persisted vector segment metadata gains an optional metric field. Metadata written before this change has no such field and deserializes to null, which is treated as exempt, so the change is backward compatible. Flagging for format review.

Documentation

No.

The metric guard in PkVectorAnnSegmentSearcher compared two values
that both derive from the current table config, so it could never
fail: changing the metric option after ANN segments were built let
searches score old segments with the new metric and silently return
wrong distances.

Record the effective metric in the segment's vector index metadata
when writing it, expose it through VectorGlobalIndexer.segmentMetric,
and reject segments whose recorded metric differs from the current
one. Legacy segments that record no metric are still accepted.

Assisted-by: GLM-5.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vector search metric guard is ineffective and ANN segments are scored with the wrong distance metric after the metric changes

1 participant