Skip to content

Commit 292d482

Browse files
committed
fix: queryToSql omitted TOPK clause for vector search — flat WASM search returned wrong result count
1 parent 4682397 commit 292d482

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/wasm-engine.integration.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,13 @@ describe("queryToSql", () => {
398398
const sql = queryToSql({ ...base, offset: 0 });
399399
expect(sql).toContain("OFFSET 0");
400400
});
401+
402+
it("includes TOPK in vector search SQL", () => {
403+
const sql = queryToSql({
404+
...base,
405+
vectorSearch: { column: "embedding", queryVector: new Float32Array([0.1, 0.2, 0.3]), topK: 10 },
406+
});
407+
expect(sql).toContain("NEAR [");
408+
expect(sql).toContain("TOPK 10");
409+
});
401410
});

src/wasm-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ export function queryToSql(query: QueryDescriptor): string {
10711071
for (let i = 0; i < vs.queryVector.length; i++) { if (i > 0) vecStr += ","; vecStr += vs.queryVector[i]; }
10721072
vecStr += "]";
10731073
const hasWhere = andConditions.length > 0 || orGroupConditions.length > 0;
1074-
parts.push(`${hasWhere ? "AND" : "WHERE"} ${quote(vs.column)} NEAR ${vecStr}`);
1074+
parts.push(`${hasWhere ? "AND" : "WHERE"} ${quote(vs.column)} NEAR ${vecStr} TOPK ${vs.topK}`);
10751075
}
10761076

10771077
if (query.groupBy?.length) parts.push(`GROUP BY ${query.groupBy.map(quote).join(", ")}`);

0 commit comments

Comments
 (0)