feat: add list_indices to the async api (#1074)

This commit is contained in:
Weston Pace
2024-03-12 14:41:21 -07:00
parent 9031ec6878
commit b6a522d483
14 changed files with 233 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
from typing import Dict, Optional
from typing import Dict, List, Optional
import pyarrow as pa
@@ -39,6 +39,11 @@ class Table:
async def checkout(self, version): ...
async def checkout_latest(self): ...
async def restore(self): ...
async def list_indices(self) -> List[IndexConfig]: ...
class IndexConfig:
index_type: str
columns: List[str]
async def connect(
uri: str,

View File

@@ -3,6 +3,9 @@ from typing import Optional
from ._lancedb import (
Index as LanceDbIndex,
)
from ._lancedb import (
IndexConfig,
)
class BTree(object):
@@ -155,3 +158,6 @@ class IvfPq(object):
max_iterations=max_iterations,
sample_rate=sample_rate,
)
__all__ = ["BTree", "IvfPq", "IndexConfig"]

View File

@@ -59,7 +59,7 @@ if TYPE_CHECKING:
from ._lancedb import Table as LanceDBTable
from .db import LanceDBConnection
from .index import BTree, IvfPq
from .index import BTree, IndexConfig, IvfPq
pd = safe_import_pandas()
@@ -2409,3 +2409,9 @@ class AsyncTable:
out state and the read_consistency_interval, if any, will apply.
"""
await self._inner.restore()
async def list_indices(self) -> IndexConfig:
"""
List all indices that have been created with Self::create_index
"""
return await self._inner.list_indices()

View File

@@ -41,6 +41,10 @@ async def test_create_scalar_index(some_table: AsyncTable):
await some_table.create_index("id")
# Can recreate if replace=True
await some_table.create_index("id", replace=True)
indices = await some_table.list_indices()
assert len(indices) == 1
assert indices[0].index_type == "BTree"
assert indices[0].columns == ["id"]
# Can't recreate if replace=False
with pytest.raises(RuntimeError, match="already exists"):
await some_table.create_index("id", replace=False)
@@ -59,3 +63,7 @@ async def test_create_vector_index(some_table: AsyncTable):
await some_table.create_index("vector", replace=False)
# Can also specify index type
await some_table.create_index("vector", config=IvfPq(num_partitions=100))
indices = await some_table.list_indices()
assert len(indices) == 1
assert indices[0].index_type == "IvfPq"
assert indices[0].columns == ["vector"]