refresh_index - Advance async vector index visibility
On a Collection instance, refresh_index() ensures that committed asynchronous writes on the table backing the current Collection become visible in approximate vector search as soon as possible when HNSW vector indexes use asynchronous maintenance. It corresponds to SQL CALL dbms_index_manager.refresh();. For details, see REFRESH (DBMS_INDEX_MANAGER).
info
Call this method only on a Collection instance obtained through a SeekdbClient connection. For more information about SeekdbClient, see SeekdbClient.
Description
- In server mode and embedded mode, seekdb V1.3.0 and later use asynchronous vector indexes by default. To see data in approximate search immediately after a write, call
await collection.refresh_index()afteradd,upsert, or similar write operations.
Prerequisites
- You have installed seekdb-js. See Get started.
- You have connected to the database. See SeekdbClient.
- For server-mode seekdb, see Deploy seekdb with a package manager.
- You have obtained the target Collection (for example, through
createCollectionorgetCollection).
Request parameters
None.
Response parameters
None.
Request example
import { SeekdbClient } from "seekdb";
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
database: "test",
});
const name = "t1";
if (await client.hasCollection(name)) {
await client.deleteCollection(name);
}
const collection = await client.createCollection({
name,
configuration: { dimension: 3, distance: "l2" },
embeddingFunction: null,
});
await collection.add({
ids: ["16", "17", "18"],
embeddings: [
[1.0, 2.0, 3.0],
[1.0, 2.0, 3.0],
[1.0, 2.0, 3.0],
],
documents: ["seekdb 1.0", "seekdb 1.0", "seekdb 1.0"],
});
await collection.refresh_index();
const q = await collection.query({
queryEmbeddings: [[100, 100, 100]],
nResults: 5,
approximate: true,
include: ["documents", "distances"],
});
const rows = (q.ids[0] ?? []).map((id, i) => ({
id: Number(id),
document: q.documents?.[0]?.[i] ?? null,
distance: q.distances?.[0]?.[i] ?? null,
}));
console.log(rows);
await client.deleteCollection(name);