feat(index): expose layered RaBitQ defaults across SDKs

This commit is contained in:
Yang Cen
2026-10-14 19:30:09 +08:00
parent ad79e9328e
commit bb48446f20
14 changed files with 216 additions and 58 deletions
+32 -8
View File
@@ -1695,14 +1695,38 @@ describe("When creating an index", () => {
});
});
it("should be able to create IVF_RQ", async () => {
await tbl.createIndex("vec", {
config: Index.ivfRq({
numPartitions: 10,
numBits: 1,
}),
});
});
test.each([
[1, true],
[2, true],
[5, undefined],
[5, false],
[5, true],
] as const)(
"should create IVF_RQ with bits=%s layered=%s",
async (numBits, layered) => {
await tbl.createIndex("vec", {
config: Index.ivfRq({ numPartitions: 10, numBits, layered }),
});
const indices = await tbl.listIndices();
expect(indices).toHaveLength(1);
expect(indices[0].indexType).toBe("IvfRq");
const expected = await tbl
.vectorSearch(queryVec)
.bypassVectorIndex()
.limit(10)
.toArray();
const actual = await tbl
.vectorSearch(queryVec)
.nprobes(10)
.refineFactor(30)
.limit(10)
.toArray();
const ids = new Set(expected.map((row) => row.id));
expect(
actual.filter((row) => ids.has(row.id)).length,
).toBeGreaterThanOrEqual(5);
},
);
it("should allow me to replace (or not) an existing index", async () => {
await tbl.createIndex("id");
+8 -1
View File
@@ -131,10 +131,16 @@ export interface IvfRqOptions {
*
* This value controls how much each residual component is compressed. The more
* bits, the more accurate the index will be but the slower search. Typical values
* are small integers; the default is 1 bit per dimension.
* are small integers; the default is 5 bits per dimension.
*/
numBits?: number;
/**
* Use prefix planes. Unset uses the product default: false in OSS and true
* in Enterprise. Ignored for 1-bit and 2-bit codes.
*/
layered?: boolean;
/**
* Distance type to use to build the index.
*
@@ -660,6 +666,7 @@ export class Index {
options?.numBits,
options?.maxIterations,
options?.sampleRate,
options?.layered,
),
);
}
+4
View File
@@ -137,8 +137,12 @@ impl Index {
num_bits: Option<u32>,
max_iterations: Option<u32>,
sample_rate: Option<u32>,
layered: Option<bool>,
) -> napi::Result<Self> {
let mut ivf_rq_builder = IvfRqIndexBuilder::default();
if let Some(layered) = layered {
ivf_rq_builder = ivf_rq_builder.layered(layered);
}
if let Some(distance_type) = distance_type {
let distance_type = parse_distance_type(distance_type)?;
ivf_rq_builder = ivf_rq_builder.distance_type(distance_type);