Files
lancedb/docs/web/snippets/curation_sampling.mdx
T
Xuanwo 2e46464589 docs: group ordered takes for training batches (#5351)
Training samplers can group several batches of offsets into one bounded
Enterprise request. The guide uses `take_offsets(...,
preserve_order=True)` on the sampler's table version and checks the
returned row count before splitting the rows back into the original
training batches. It explains the buffering trade-off and how to apply
the same cardinality check to row-ID lookups.

Related to [OSS-3134](https://linear.app/lancedb/issue/OSS-3134).
2026-12-02 09:19:33 +00:00

7 lines
1.4 KiB
Plaintext

{/* Auto-generated by scripts/mdx_snippets_gen.py. Do not edit manually. */}
export const PyGroupedTrainingTakes = "def take_training_batches(table, version, offset_batches, columns):\n from itertools import islice\n\n table.checkout(version)\n offset_batches = iter(offset_batches)\n while group := list(islice(offset_batches, 4)):\n batch_sizes = [len(batch) for batch in group]\n if sum(batch_sizes) > 1024:\n raise ValueError(\"A grouped take can request at most 1,024 rows\")\n\n offsets = [offset for batch in group for offset in batch]\n rows = (\n table.take_offsets(offsets, preserve_order=True).select(columns).to_arrow()\n )\n if rows.num_rows != len(offsets):\n raise ValueError(\"Some training offsets are missing from the snapshot\")\n\n start = 0\n for size in batch_sizes:\n yield rows.slice(start, size)\n start += size\n";
export const PySampleDataset = "table = db.create_table(\"records\", [{\"id\": i} for i in range(10)])\nsplits = (\n permutation_builder(table).split_random(counts=[3, 7], seed=42).execute()\n)\nsample = Permutation.from_tables(table, splits, split=0).with_format(\"arrow\")\nselected_ids = []\nfor batch in sample.iter(batch_size=3):\n selected_ids.extend(batch.column(\"id\").to_pylist())\nprint(f\"Selected {len(selected_ids)} rows: {selected_ids}\")\n";