mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
fix(node): retain deferred query promise failures until execution (#5280)
## Summary Observe Promise-backed query preparation when the builder stores it, including promises produced by fluent modifiers. Terminal operations still await the original promise and receive its original rejection. ## Validation - Both delayed-execution regressions fail on main. The new tests exercise a plain Promise-backed builder and a builder with chained filters, and check rejection identity. - Native Jest query suite: 43 passed. TypeScript compilation with `--noEmit` and Biome checks passed. - Ran real embedded direct-Promise and forced string-vector queries with Node's strict unhandled rejection mode. Both baseline processes exit before execution. With the fix each process survives the delay, receives the expected error when awaited, and successfully executes a control query. Fixes https://github.com/lancedb/lancedb/issues/5279 --------- Co-authored-by: Divyam Talwar <DivyamTalwar@users.noreply.github.com> Co-authored-by: Divyam Talwar <152021174+DivyamTalwar@users.noreply.github.com>
This commit is contained in:
co-authored by
Divyam Talwar
Divyam Talwar
parent
e2f6ba1b69
commit
4abb2b282c
@@ -78,6 +78,20 @@ describe("Query outputSchema", () => {
|
||||
expect(schema.fields[1].type.toString()).toBe("Float32");
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
"reports a rejected vector when outputSchema is called later (with filters: %s)",
|
||||
async (withFilters) => {
|
||||
const failure = new Error("vector preparation failed");
|
||||
const query = table.query().nearestTo(Promise.reject(failure));
|
||||
if (withFilters) {
|
||||
query.where("a > 1").limit(1);
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
await expect(query.outputSchema()).rejects.toBe(failure);
|
||||
},
|
||||
);
|
||||
|
||||
it("should return schema for FTS search", async () => {
|
||||
await table.createIndex("text", { config: Index.fts() });
|
||||
|
||||
@@ -110,6 +124,49 @@ describe("Query outputSchema", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("vectorSearch with promised additional vectors", () => {
|
||||
let tmpDir: tmp.DirResult;
|
||||
let table: Table;
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = tmp.dirSync({ unsafeCleanup: true });
|
||||
const db = await connect(tmpDir.name);
|
||||
table = await db.createTable("vectors", [
|
||||
{ label: "first", vector: [1, 2] },
|
||||
{ label: "second", vector: [3, 4] },
|
||||
]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
tmpDir.removeCallback();
|
||||
});
|
||||
|
||||
it("rejects with the original error when the promised vector fails", async () => {
|
||||
const failure = new Error("additional vector rejected");
|
||||
const query = table.vectorSearch([[1, 2], Promise.reject(failure)]);
|
||||
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
await expect(query.toArray()).rejects.toBe(failure);
|
||||
});
|
||||
|
||||
it("returns results for both vectors when the promised vector resolves", async () => {
|
||||
const results = await table
|
||||
.vectorSearch([[1, 2], Promise.resolve([3, 4])])
|
||||
.limit(1)
|
||||
.toArray();
|
||||
|
||||
expect(results).toHaveLength(2);
|
||||
expect(
|
||||
results.map(({ query_index, label }) => [query_index, label]),
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
[0, "first"],
|
||||
[1, "second"],
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Query empty results", () => {
|
||||
let tmpDir: tmp.DirResult;
|
||||
let table: Table;
|
||||
|
||||
Reference in New Issue
Block a user