feat: add drop_index() method (#2039)

Closes #1665
This commit is contained in:
Will Jones
2025-01-20 10:08:51 -08:00
committed by GitHub
parent 3dc1803c07
commit f059372137
18 changed files with 388 additions and 34 deletions

View File

@@ -586,6 +586,26 @@ class Table(ABC):
"""
raise NotImplementedError
def drop_index(self, name: str) -> None:
"""
Drop an index from the table.
Parameters
----------
name: str
The name of the index to drop.
Notes
-----
This does not delete the index from disk, it just removes it from the table.
To delete the index, run [optimize][lancedb.table.Table.optimize]
after dropping the index.
Use [list_indices][lancedb.table.Table.list_indices] to find the names of
the indices.
"""
raise NotImplementedError
@abstractmethod
def create_scalar_index(
self,
@@ -1594,6 +1614,9 @@ class LanceTable(Table):
)
)
def drop_index(self, name: str) -> None:
return LOOP.run(self._table.drop_index(name))
def create_scalar_index(
self,
column: str,
@@ -2716,6 +2739,26 @@ class AsyncTable:
add_note(e, help_msg)
raise e
async def drop_index(self, name: str) -> None:
"""
Drop an index from the table.
Parameters
----------
name: str
The name of the index to drop.
Notes
-----
This does not delete the index from disk, it just removes it from the table.
To delete the index, run [optimize][lancedb.table.AsyncTable.optimize]
after dropping the index.
Use [list_indices][lancedb.table.AsyncTable.list_indices] to find the names
of the indices.
"""
await self._inner.drop_index(name)
async def add(
self,
data: DATA,

View File

@@ -80,6 +80,10 @@ async def test_create_scalar_index(some_table: AsyncTable):
# can also specify index type
await some_table.create_index("id", config=BTree())
await some_table.drop_index("id_idx")
indices = await some_table.list_indices()
assert len(indices) == 0
@pytest.mark.asyncio
async def test_create_bitmap_index(some_table: AsyncTable):

View File

@@ -1008,6 +1008,10 @@ def test_create_scalar_index(mem_db: DBConnection):
results = table.search([5, 5]).where("x != 'b'").to_arrow()
assert results["_distance"][0].as_py() > 0
table.drop_index(scalar_index.name)
indices = table.list_indices()
assert len(indices) == 0
def test_empty_query(mem_db: DBConnection):
table = mem_db.create_table(

View File

@@ -194,6 +194,14 @@ impl Table {
})
}
pub fn drop_index(self_: PyRef<'_, Self>, index_name: String) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner_ref()?.clone();
future_into_py(self_.py(), async move {
inner.drop_index(&index_name).await.infer_error()?;
Ok(())
})
}
pub fn list_indices(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner_ref()?.clone();
future_into_py(self_.py(), async move {