Changesets · Branches · Tags · Compare
| Changeset | e822b4e34fb724b18fb5fd77f67e5d31b3c72576a277ef74b28c1a00a85f3360 |
|---|---|
| Author | Gagan Bhullar <g.deepsingh1@gmail.com> · 2024-09-25 10:16 -06:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-25 09:16 -07:00 |
| Parents | ffc27a8ff454 |
2 files changed
modified rust/lancedb/src/index/vector.rs +5 −0
| @@ -214,6 +214,11 @@ | ||
| 214 | 214 | max(1, num_partitions) |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | +pub(crate) fn suggested_num_partitions_for_hnsw(rows: usize, dim: u32) -> u32 { | |
| 218 | + let num_partitions = (((rows as u64) * (dim as u64)) / (256 * 5_000_000)) as u32; | |
| 219 | + max(1, num_partitions) | |
| 220 | +} | |
| 221 | + | |
| 217 | 222 | pub(crate) fn suggested_num_sub_vectors(dim: u32) -> u32 { |
| 218 | 223 | if dim % 16 == 0 { |
| 219 | 224 | // Should be more aggressive than this default. |
modified rust/lancedb/src/table.rs +21 −5
| @@ -54,7 +54,8 @@ | ||
| 54 | 54 | use crate::error::{Error, Result}; |
| 55 | 55 | use crate::index::scalar::FtsIndexBuilder; |
| 56 | 56 | use crate::index::vector::{ |
| 57 | - IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, IvfPqIndexBuilder, VectorIndex, | |
| 57 | + suggested_num_partitions_for_hnsw, IvfHnswPqIndexBuilder, IvfHnswSqIndexBuilder, | |
| 58 | + IvfPqIndexBuilder, VectorIndex, | |
| 58 | 59 | }; |
| 59 | 60 | use crate::index::IndexConfig; |
| 60 | 61 | use crate::index::IndexStatistics; |
| @@ -1440,11 +1441,19 @@ | ||
| 1440 | 1441 | }); |
| 1441 | 1442 | } |
| 1442 | 1443 | |
| 1443 | - let num_partitions = if let Some(n) = index.num_partitions { | |
| 1444 | + let num_partitions: u32 = if let Some(n) = index.num_partitions { | |
| 1444 | 1445 | n |
| 1445 | 1446 | } else { |
| 1446 | - suggested_num_partitions(self.count_rows(None).await?) | |
| 1447 | + match field.data_type() { | |
| 1448 | + arrow_schema::DataType::FixedSizeList(_, n) => Ok::<u32, Error>( | |
| 1449 | + suggested_num_partitions_for_hnsw(self.count_rows(None).await?, *n as u32), | |
| 1450 | + ), | |
| 1451 | + _ => Err(Error::Schema { | |
| 1452 | + message: format!("Column '{}' is not a FixedSizeList", field.name()), | |
| 1453 | + }), | |
| 1454 | + }? | |
| 1447 | 1455 | }; |
| 1456 | + | |
| 1448 | 1457 | let num_sub_vectors: u32 = if let Some(n) = index.num_sub_vectors { |
| 1449 | 1458 | n |
| 1450 | 1459 | } else { |
| @@ -1503,10 +1512,17 @@ | ||
| 1503 | 1512 | }); |
| 1504 | 1513 | } |
| 1505 | 1514 | |
| 1506 | - let num_partitions = if let Some(n) = index.num_partitions { | |
| 1515 | + let num_partitions: u32 = if let Some(n) = index.num_partitions { | |
| 1507 | 1516 | n |
| 1508 | 1517 | } else { |
| 1509 | - suggested_num_partitions(self.count_rows(None).await?) | |
| 1518 | + match field.data_type() { | |
| 1519 | + arrow_schema::DataType::FixedSizeList(_, n) => Ok::<u32, Error>( | |
| 1520 | + suggested_num_partitions_for_hnsw(self.count_rows(None).await?, *n as u32), | |
| 1521 | + ), | |
| 1522 | + _ => Err(Error::Schema { | |
| 1523 | + message: format!("Column '{}' is not a FixedSizeList", field.name()), | |
| 1524 | + }), | |
| 1525 | + }? | |
| 1510 | 1526 | }; |
| 1511 | 1527 | |
| 1512 | 1528 | let mut dataset = self.dataset.get_mut().await?; |