Changesets · Branches · Tags · Compare
| Changeset | 29678251014b85b58fdb810d35b1898da4d0838615039eefa8b8d6c08f784c79 |
|---|---|
| Author | Will Jones <willjones127@gmail.com> · 2024-10-16 10:39 -07:00 |
| Committer | GitHub <noreply@github.com> · 2024-10-16 10:39 -07:00 |
| Parents | fc131e0c8c49 |
2 files changed
modified rust/lancedb/src/index.rs +1 −1
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | "BTREE" => Ok(Self::BTree), |
| 145 | 145 | "BITMAP" => Ok(Self::Bitmap), |
| 146 | 146 | "LABEL_LIST" | "LABELLIST" => Ok(Self::LabelList), |
| 147 | - "FTS" => Ok(Self::FTS), | |
| 147 | + "FTS" | "INVERTED" => Ok(Self::FTS), | |
| 148 | 148 | "IVF_PQ" => Ok(Self::IvfPq), |
| 149 | 149 | "IVF_HNSW_PQ" => Ok(Self::IvfHnswPq), |
| 150 | 150 | "IVF_HNSW_SQ" => Ok(Self::IvfHnswSq), |
modified rust/lancedb/src/table.rs +46 −26
| @@ -2110,7 +2110,6 @@ | ||
| 2110 | 2110 | use arrow_schema::{DataType, Field, Schema, TimeUnit}; |
| 2111 | 2111 | use futures::TryStreamExt; |
| 2112 | 2112 | use lance::dataset::{Dataset, WriteMode}; |
| 2113 | - use lance::index::DatasetIndexInternalExt; | |
| 2114 | 2113 | use lance::io::{ObjectStoreParams, WrappingObjectStore}; |
| 2115 | 2114 | use rand::Rng; |
| 2116 | 2115 | use tempfile::tempdir; |
| @@ -3002,22 +3001,8 @@ | ||
| 3002 | 3001 | let index_configs = table.list_indices().await.unwrap(); |
| 3003 | 3002 | assert_eq!(index_configs.len(), 1); |
| 3004 | 3003 | 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); | |
| 3007 | 3005 | 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); | |
| 3021 | 3006 | } |
| 3022 | 3007 | |
| 3023 | 3008 | #[tokio::test] |
| @@ -3086,22 +3071,57 @@ | ||
| 3086 | 3071 | let index_configs = table.list_indices().await.unwrap(); |
| 3087 | 3072 | assert_eq!(index_configs.len(), 1); |
| 3088 | 3073 | 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); | |
| 3091 | 3075 | 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(); | |
| 3092 | 3104 | |
| 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() | |
| 3097 | 3111 | .await |
| 3098 | 3112 | .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() | |
| 3102 | 3117 | .await |
| 3103 | 3118 | .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"); | |
| 3105 | 3125 | } |
| 3106 | 3126 | |
| 3107 | 3127 | #[tokio::test] |