Skip to main content
Enterprise only
Semantic sampling draws rows from every partition of an existing IVF vector index. Each partition acts as a cluster of similar embeddings. Use it to inspect examples across your embedding space, build a dataset with broader topic coverage, or try an expensive operation on examples from each cluster. The clusters reflect your embeddings and index; they do not guarantee coverage of every label or topic.

Sample rows from every cluster

Connect with an Enterprise SQL client. The examples assume a documents table with id, caption, and embedding columns. The embedding column must have an up-to-date, single-segment IVF vector index that includes every live row. Wait for the index build to finish before sampling.
This selects up to 100 rows from each IVF partition, without replacement. A partition with fewer than 100 rows contributes all its rows; empty partitions contribute none. The result contains the table’s existing columns, so you can project the fields you need without returning embedding. The count is per partition, not a limit on the whole result. For example: With 1,024 populated partitions, the query returns at most 102,400 rows. Choose the quota with the number of partitions and your output budget in mind. Equal quotas give sparse clusters more weight relative to their size. This makes semantic sampling useful for cluster coverage, but the resulting sample does not preserve the table’s overall distribution. Use Statistical Sampling for uniform row sampling or account for the different sampling probabilities when estimating whole-table statistics. To group records by partition or select a subset of whole partitions, use ivf_partition() instead. Its count argument selects the number of partitions; TABLESAMPLE IVF selects rows within every partition.

Repeat a sample

REPEATABLE (42) fixes the seed. With the same table snapshot, index, and seed, repeated queries select the same rows. Output order is unspecified. Omit REPEATABLE to draw a new sample each time. Changes to the source data or rebuilding the index can change the selected rows even with the same seed. Save a sample when you need a fixed dataset for evaluation or comparison:
Create the output once with a fresh name and keep it unchanged. Record the source version and sampling policy alongside the result.

Filter sampled rows

Sampling happens before WHERE, joins, aggregation, and an outer LIMIT. For example, this draws up to 100 rows per partition and then removes rows with missing captions:
The result can contain fewer than 100 rows from a partition after filtering. If you need a quota from an eligible subset, first save that subset as a base table and build its IVF index before sampling it.

Requirements and limits

Sampling examines the membership of every partition and fetches projected data for the selected rows. A small quota limits the result size, but does not limit index reads to that many entries. Large partitions can still require substantial index reads and memory.