Elffuss BraidHub

kikocis/lancedb public

fix: list_indices can handle fts indexes (#1753)

Fixes #1752
Changeset29678251014b85b58fdb810d35b1898da4d0838615039eefa8b8d6c08f784c79
AuthorWill Jones <willjones127@gmail.com> · 2024-10-16 10:39 -07:00
CommitterGitHub <noreply@github.com> · 2024-10-16 10:39 -07:00
Parentsfc131e0c8c49

Browse the files at this changeset

2 files changed

modified rust/lancedb/src/index.rs +1 −1
@@ -144,7 +144,7 @@
144144 "BTREE" => Ok(Self::BTree),
145145 "BITMAP" => Ok(Self::Bitmap),
146146 "LABEL_LIST" | "LABELLIST" => Ok(Self::LabelList),
147- "FTS" => Ok(Self::FTS),
147+ "FTS" | "INVERTED" => Ok(Self::FTS),
148148 "IVF_PQ" => Ok(Self::IvfPq),
149149 "IVF_HNSW_PQ" => Ok(Self::IvfHnswPq),
150150 "IVF_HNSW_SQ" => Ok(Self::IvfHnswSq),
modified rust/lancedb/src/table.rs +46 −26
@@ -2110,7 +2110,6 @@
21102110 use arrow_schema::{DataType, Field, Schema, TimeUnit};
21112111 use futures::TryStreamExt;
21122112 use lance::dataset::{Dataset, WriteMode};
2113- use lance::index::DatasetIndexInternalExt;
21142113 use lance::io::{ObjectStoreParams, WrappingObjectStore};
21152114 use rand::Rng;
21162115 use tempfile::tempdir;
@@ -3002,22 +3001,8 @@
30023001 let index_configs = table.list_indices().await.unwrap();
30033002 assert_eq!(index_configs.len(), 1);
30043003 let index = index_configs.into_iter().next().unwrap();
3005- // TODO: Fix via https://github.com/lancedb/lance/issues/2039
3006- // assert_eq!(index.index_type, crate::index::IndexType::Bitmap);
3004+ assert_eq!(index.index_type, crate::index::IndexType::Bitmap);
30073005 assert_eq!(index.columns, vec!["category".to_string()]);
3008-
3009- // For now, just open the index to verify its type
3010- let lance_dataset = table.as_native().unwrap().dataset.get().await.unwrap();
3011- let indices = lance_dataset
3012- .load_indices_by_name(&index.name)
3013- .await
3014- .unwrap();
3015- let index_meta = &indices[0];
3016- let idx = lance_dataset
3017- .open_scalar_index("category", &index_meta.uuid.to_string())
3018- .await
3019- .unwrap();
3020- assert_eq!(idx.index_type(), IndexType::Bitmap);
30213006 }
30223007
30233008 #[tokio::test]
@@ -3086,22 +3071,57 @@
30863071 let index_configs = table.list_indices().await.unwrap();
30873072 assert_eq!(index_configs.len(), 1);
30883073 let index = index_configs.into_iter().next().unwrap();
3089- // TODO: Fix via https://github.com/lancedb/lance/issues/2039
3090- // assert_eq!(index.index_type, crate::index::IndexType::LabelList);
3074+ assert_eq!(index.index_type, crate::index::IndexType::LabelList);
30913075 assert_eq!(index.columns, vec!["tags".to_string()]);
3076+ }
3077+
3078+ #[tokio::test]
3079+ async fn test_create_inverted_index() {
3080+ let tmp_dir = tempdir().unwrap();
3081+ let uri = tmp_dir.path().to_str().unwrap();
3082+
3083+ let conn = ConnectBuilder::new(uri).execute().await.unwrap();
3084+ const WORDS: [&str; 3] = ["cat", "dog", "fish"];
3085+ let mut text_builder = StringBuilder::new();
3086+ let num_rows = 120;
3087+ for i in 0..num_rows {
3088+ text_builder.append_value(WORDS[i % 3]);
3089+ }
3090+ let text = Arc::new(text_builder.finish());
3091+
3092+ let schema = Arc::new(Schema::new(vec![
3093+ Field::new("id", DataType::Int32, false),
3094+ Field::new("text", DataType::Utf8, true),
3095+ ]));
3096+ let batch = RecordBatch::try_new(
3097+ schema.clone(),
3098+ vec![
3099+ Arc::new(Int32Array::from_iter_values(0..num_rows as i32)),
3100+ text,
3101+ ],
3102+ )
3103+ .unwrap();
30923104
3093- // For now, just open the index to verify its type
3094- let lance_dataset = table.as_native().unwrap().dataset.get().await.unwrap();
3095- let indices = lance_dataset
3096- .load_indices_by_name(&index.name)
3105+ let table = conn
3106+ .create_table(
3107+ "test_bitmap",
3108+ RecordBatchIterator::new(vec![Ok(batch.clone())], batch.schema()),
3109+ )
3110+ .execute()
30973111 .await
30983112 .unwrap();
3099- let index_meta = &indices[0];
3100- let idx = lance_dataset
3101- .open_scalar_index("tags", &index_meta.uuid.to_string())
3113+
3114+ table
3115+ .create_index(&["text"], Index::FTS(Default::default()))
3116+ .execute()
31023117 .await
31033118 .unwrap();
3104- assert_eq!(idx.index_type(), IndexType::LabelList);
3119+ let index_configs = table.list_indices().await.unwrap();
3120+ assert_eq!(index_configs.len(), 1);
3121+ let index = index_configs.into_iter().next().unwrap();
3122+ assert_eq!(index.index_type, crate::index::IndexType::FTS);
3123+ assert_eq!(index.columns, vec!["text".to_string()]);
3124+ assert_eq!(index.name, "text_idx");
31053125 }
31063126
31073127 #[tokio::test]