Skip to content

本页尚未翻译

本页内容仍为英文原文,源自官方文档 sql/dql/duplicate-pairs。中文翻译正在分批进行中。

DUPLICATE_PAIRS ​

The duplicate_pairs() table function: every close pair in a vector column, scanned over the index.

Applies to: Embedded ❌, Enterprise ✅

duplicate_pairs scans a vector column's index partitions for every pair of rows closer than a distance threshold, without a full pairwise scan or a shuffle. It returns one row per close pair, not one row per source row -- use it to inspect what would be collapsed before committing to dedupe, which resolves these same pairs into groups.

sql
SELECT * FROM duplicate_pairs(
    <table>,
    <vector_column>,
    distance_threshold => <float>
    [, id_column => <column>]
    [, selection => 'all' | 'first' | 'random', count => <int>, seed => <int>]
)
sql
SELECT * FROM duplicate_pairs(
    'frames',
    'vec',
    distance_threshold => 0.02
)

说明

Earlier releases spelled this vector_duplicate_pairs; that name is rejected on current deployments.

Input ​

ArgumentTypeRequiredMeaning
table namestring literalyesthe table to scan
vector columnstring literalyesthe indexed vector column to compare
distance_thresholdfloatyesmaximum distance for a pair to count as close
id_columncolumn namenoproject this column's value instead of the internal row ID -- see Application-level identifiers
selection'all' (default) | 'first' | 'random'nowhich index partitions to scan
countintnonumber of partitions to sample when selection => 'random'
seedintnorandom seed when selection => 'random'

resolution is refused on duplicate_pairs: a pair has no notion of a group, only dedupe accepts it.

Output ​

One row per close pair found, in a fixed schema independent of the source table:

ColumnTypeMeaning
row_id_auint64internal row ID of the first row in the pair, the same identifier as the _rowid pseudo-column
row_id_buint64internal row ID of the second row in the pair
distancefloat32distance between the pair's vectors, at or below distance_threshold. For l2, this is the squared distance, not its square root
segment_idUtf8which index segment the pair was found in, a UUID
partition_iduint64which index partition the pair was found in
dataset_versionuint64the dataset version the scan ran against

Application-level identifiers ​

A row ID is internal and not stable across compaction. Pass id_column, a top-level scalar column such as a primary key, to also project its value: id_a/id_b, typed like id_column, are appended alongside row_id_a/row_id_b, which remain in the output.

sql
SELECT * FROM duplicate_pairs(
    'frames',
    'vec',
    distance_threshold => 0.02,
    id_column => 'frame_id'
)

Sampling partitions ​

selection scopes the scan to a sample of partitions instead of all of them, the same all (default) / first / random choice as ivf_partition. Use it to estimate a distance threshold or duplicate rate on a large table before scanning it in full:

sql
SELECT * FROM duplicate_pairs(
    'frames',
    'vec',
    distance_threshold => 0.02,
    selection => 'random',
    count => 100,
    seed => 42
)
DEDUPEResolve these same pairs into one representative row per group.Deduplicate near-duplicatesWhen to reach for this instead of exact-key deduplication.