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

@@ -473,6 +473,10 @@ describe("When creating an index", () => {
// test offset
rst = await tbl.query().limit(2).offset(1).nearestTo(queryVec).toArrow();
expect(rst.numRows).toBe(1);
await tbl.dropIndex("vec_idx");
const indices2 = await tbl.listIndices();
expect(indices2.length).toBe(0);
});
it("should search with distance range", async () => {

View File

@@ -226,6 +226,19 @@ export abstract class Table {
column: string,
options?: Partial<IndexOptions>,
): Promise<void>;
/**
* Drop an index from the table.
*
* @param name The name of the index.
*
* @note This does not delete the index from disk, it just removes it from the table.
* To delete the index, run {@link Table#optimize} after dropping the index.
*
* Use {@link Table.listIndices} to find the names of the indices.
*/
abstract dropIndex(name: string): Promise<void>;
/**
* Create a {@link Query} Builder.
*
@@ -426,6 +439,8 @@ export abstract class Table {
*
* @param {string} name The name of the index.
* @returns {IndexStatistics | undefined} The stats of the index. If the index does not exist, it will return undefined
*
* Use {@link Table.listIndices} to find the names of the indices.
*/
abstract indexStats(name: string): Promise<IndexStatistics | undefined>;
@@ -591,6 +606,10 @@ export class LocalTable extends Table {
await this.inner.createIndex(nativeIndex, column, options?.replace);
}
async dropIndex(name: string): Promise<void> {
await this.inner.dropIndex(name);
}
query(): Query {
return new Query(this.inner);
}

View File

@@ -135,6 +135,14 @@ impl Table {
builder.execute().await.default_error()
}
#[napi(catch_unwind)]
pub async fn drop_index(&self, index_name: String) -> napi::Result<()> {
self.inner_ref()?
.drop_index(&index_name)
.await
.default_error()
}
#[napi(catch_unwind)]
pub async fn update(
&self,