跳到主要内容
版本:V1.3.0

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()。

前提条件​

请求参数​

无。

返回参数​

无。

请求示例​

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);

相关文档​