refresh_index - 推进异步向量索引可见性
Collection 实例上的 refresh_index() 用于在 HNSW 异步向量索引场景下,确保当前 Collection 对应表中已提交的异步写入尽快在近似向量检索中可见,语义上对应 SQL CALL dbms_index_manager.refresh();,详见 REFRESH(DBMS_INDEX_MANAGER)。
信息
仅支持在使用 SeekdbClient 连接时,通过已获取的 Collection 实例调用本方法。关于 SeekdbClient 的详细介绍,参见 SeekdbClient。
说明
- seekdb 服务器模式与嵌入式模式在 V1.3.0 及以上默认使用异步向量索引;写入后若需立即在近似检索中看到数据,宜在
add/upsert等写入后调用await collection.refresh_index()。
前提条件
- 已安装 seekdb-js,参见 快速开始。
- 已连接数据库,参见 SeekdbClient。
- 若使用服务器模式 seekdb,参见 通过包管理工具部署 seekdb。
- 已获取目标 Collection(例如
createCollection/getCollection)。
请求参数
无。
返回参数
无。
请求示例
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);