diff --git a/python/python/lancedb/db.py b/python/python/lancedb/db.py index c5d3a5b9..204edc87 100644 --- a/python/python/lancedb/db.py +++ b/python/python/lancedb/db.py @@ -248,6 +248,18 @@ class DBConnection(EnforceOverrides): """ raise NotImplementedError + def rename_table(self, cur_name: str, new_name: str): + """Rename a table in the database. + + Parameters + ---------- + cur_name: str + The current name of the table. + new_name: str + The new name of the table. + """ + raise NotImplementedError + def drop_database(self): """ Drop database diff --git a/python/python/lancedb/remote/db.py b/python/python/lancedb/remote/db.py index c252fc5c..3809c511 100644 --- a/python/python/lancedb/remote/db.py +++ b/python/python/lancedb/remote/db.py @@ -281,6 +281,24 @@ class RemoteDBConnection(DBConnection): ) self._table_cache.pop(name) + @override + def rename_table(self, cur_name: str, new_name: str): + """Rename a table in the database. + + Parameters + ---------- + cur_name: str + The current name of the table. + new_name: str + The new name of the table. + """ + self._client.post( + f"/v1/table/{cur_name}/rename/", + json={"new_table_name": new_name}, + ) + self._table_cache.pop(cur_name) + self._table_cache[new_name] = True + async def close(self): """Close the connection to the database.""" self._client.close() diff --git a/python/python/lancedb/remote/table.py b/python/python/lancedb/remote/table.py index d17410f8..c6a0078b 100644 --- a/python/python/lancedb/remote/table.py +++ b/python/python/lancedb/remote/table.py @@ -72,7 +72,7 @@ class RemoteTable(Table): return resp def index_stats(self, index_uuid: str): - """List all the indices on the table""" + """List all the stats of a specified index""" resp = self._conn._client.post( f"/v1/table/{self._name}/index/{index_uuid}/stats/" ) diff --git a/rust/lancedb/src/index/vector.rs b/rust/lancedb/src/index/vector.rs index 11f25fee..c2637378 100644 --- a/rust/lancedb/src/index/vector.rs +++ b/rust/lancedb/src/index/vector.rs @@ -46,10 +46,18 @@ impl VectorIndex { } } +#[derive(Debug, Deserialize)] +pub struct VectorIndexMetadata { + pub metric_type: String, + pub index_type: String, +} + #[derive(Debug, Deserialize)] pub struct VectorIndexStatistics { pub num_indexed_rows: usize, pub num_unindexed_rows: usize, + pub index_type: String, + pub indices: Vec, } /// Builder for an IVF PQ index. diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index d5d3d1dd..8efbd115 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -1061,6 +1061,26 @@ impl NativeTable { } } + pub async fn get_index_type(&self, index_uuid: &str) -> Result> { + match self.load_index_stats(index_uuid).await? { + Some(stats) => Ok(Some(stats.index_type)), + None => Ok(None), + } + } + + pub async fn get_distance_type(&self, index_uuid: &str) -> Result> { + match self.load_index_stats(index_uuid).await? { + Some(stats) => Ok(Some( + stats + .indices + .iter() + .map(|i| i.metric_type.clone()) + .collect(), + )), + None => Ok(None), + } + } + pub async fn load_indices(&self) -> Result> { let dataset = self.dataset.get().await?; let (indices, mf) = futures::try_join!(dataset.load_indices(), dataset.latest_manifest())?;