#6791 Improve type checking around FAISS
State: closed | Author: Dref360 (CONTRIBUTOR)

Fixes #6791 

Small PR to raise a better error when a dataset is not embedded properly.

Comments: The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/datasets/pr_6803). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

CI failures are unrelated.

<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.005063 / 0.011353 (-0.006290) | 0.003598 / 0.011008 (-0.007410) | 0.062929 / 0.038508 (0.024421) | 0.031723 / 0.023109 (0.008614) | 0.246503 / 0.275898 (-0.029395) | 0.268742 / 0.323480 (-0.054738) | 0.003249 / 0.007986 (-0.004737) | 0.002613 / 0.004328 (-0.001715) | 0.049001 / 0.004250 (0.044751) | 0.045740 / 0.037052 (0.008687) | 0.261182 / 0.258489 (0.002693) | 0.297328 / 0.293841 (0.003487) | 0.026925 / 0.128546 (-0.101621) | 0.010588 / 0.075646 (-0.065059) | 0.208954 / 0.419271 (-0.210317) | 0.035286 / 0.043533 (-0.008246) | 0.277678 / 0.255139 (0.022539) | 0.269313 / 0.283200 (-0.013887) | 0.019865 / 0.141683 (-0.121818) | 1.145883 / 1.452155 (-0.306272) | 1.196766 / 1.492716 (-0.295950) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.093886 / 0.018006 (0.075879) | 0.305118 / 0.000490 (0.304629) | 0.000207 / 0.000200 (0.000008) | 0.000048 / 0.000054 (-0.000006) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.018473 / 0.037411 (-0.018938) | 0.061719 / 0.014526 (0.047193) | 0.074980 / 0.176557 (-0.101577) | 0.122354 / 0.737135 (-0.614781) | 0.076111 / 0.296338 (-0.220227) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.280222 / 0.215209 (0.065013) | 2.692820 / 2.077655 (0.615165) | 1.440897 / 1.504120 (-0.063223) | 1.313829 / 1.541195 (-0.227366) | 1.324392 / 1.468490 (-0.144098) | 0.570114 / 4.584777 (-4.014662) | 2.373946 / 3.745712 (-1.371766) | 2.804485 / 5.269862 (-2.465377) | 1.753595 / 4.565676 (-2.812081) | 0.062660 / 0.424275 (-0.361615) | 0.005267 / 0.007607 (-0.002340) | 0.323108 / 0.226044 (0.097063) | 3.257302 / 2.268929 (0.988373) | 1.802613 / 55.444624 (-53.642011) | 1.510590 / 6.876477 (-5.365886) | 1.567452 / 2.142072 (-0.574621) | 0.649872 / 4.805227 (-4.155355) | 0.117245 / 6.500664 (-6.383419) | 0.042260 / 0.075469 (-0.033209) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.976068 / 1.841788 (-0.865720) | 11.565981 / 8.074308 (3.491672) | 9.598650 / 10.191392 (-0.592742) | 0.129903 / 0.680424 (-0.550520) | 0.014925 / 0.534201 (-0.519276) | 0.290732 / 0.579283 (-0.288551) | 0.271236 / 0.434364 (-0.163128) | 0.325450 / 0.540337 (-0.214888) | 0.420218 / 1.386936 (-0.966718) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.005404 / 0.011353 (-0.005949) | 0.003710 / 0.011008 (-0.007298) | 0.050982 / 0.038508 (0.012474) | 0.031340 / 0.023109 (0.008231) | 0.279221 / 0.275898 (0.003323) | 0.300936 / 0.323480 (-0.022544) | 0.004251 / 0.007986 (-0.003735) | 0.002697 / 0.004328 (-0.001631) | 0.049335 / 0.004250 (0.045085) | 0.040979 / 0.037052 (0.003926) | 0.287121 / 0.258489 (0.028632) | 0.315100 / 0.293841 (0.021259) | 0.029093 / 0.128546 (-0.099454) | 0.010618 / 0.075646 (-0.065028) | 0.059095 / 0.419271 (-0.360177) | 0.032953 / 0.043533 (-0.010580) | 0.274861 / 0.255139 (0.019722) | 0.292284 / 0.283200 (0.009085) | 0.017882 / 0.141683 (-0.123801) | 1.150590 / 1.452155 (-0.301565) | 1.203501 / 1.492716 (-0.289215) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.096868 / 0.018006 (0.078862) | 0.306460 / 0.000490 (0.305971) | 0.000230 / 0.000200 (0.000030) | 0.000058 / 0.000054 (0.000003) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.022031 / 0.037411 (-0.015381) | 0.074847 / 0.014526 (0.060321) | 0.086951 / 0.176557 (-0.089606) | 0.125706 / 0.737135 (-0.611429) | 0.088244 / 0.296338 (-0.208094) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.297861 / 0.215209 (0.082652) | 2.923172 / 2.077655 (0.845518) | 1.628511 / 1.504120 (0.124391) | 1.499907 / 1.541195 (-0.041288) | 1.490060 / 1.468490 (0.021570) | 0.564087 / 4.584777 (-4.020690) | 2.441201 / 3.745712 (-1.304511) | 2.805283 / 5.269862 (-2.464578) | 1.762703 / 4.565676 (-2.802974) | 0.063038 / 0.424275 (-0.361237) | 0.005276 / 0.007607 (-0.002331) | 0.343413 / 0.226044 (0.117369) | 3.400858 / 2.268929 (1.131930) | 2.039937 / 55.444624 (-53.404687) | 1.674622 / 6.876477 (-5.201855) | 1.688371 / 2.142072 (-0.453702) | 0.635321 / 4.805227 (-4.169907) | 0.120235 / 6.500664 (-6.380429) | 0.041106 / 0.075469 (-0.034363) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.017469 / 1.841788 (-0.824319) | 12.383734 / 8.074308 (4.309426) | 10.352393 / 10.191392 (0.161001) | 0.131981 / 0.680424 (-0.548443) | 0.015204 / 0.534201 (-0.518997) | 0.286157 / 0.579283 (-0.293126) | 0.278270 / 0.434364 (-0.156094) | 0.325105 / 0.540337 (-0.215233) | 0.422301 / 1.386936 (-0.964635) |

</details>
</details>

![](https://cml.dev/watermark.png#9323521505b7fab098fbe2a304389ee2d59783ff "CML watermark")