diff --git a/nodejs/__test__/table.test.ts b/nodejs/__test__/table.test.ts index 34773094..e1f254c0 100644 --- a/nodejs/__test__/table.test.ts +++ b/nodejs/__test__/table.test.ts @@ -396,6 +396,10 @@ describe("When creating an index", () => { .toArrow(); expect(rst2.numRows).toBe(2); expect(rst.toString()).toEqual(rst2.toString()); + + // test offset + rst = await tbl.query().limit(2).offset(1).nearestTo(queryVec).toArrow(); + expect(rst.numRows).toBe(1); }); it("should allow parameters to be specified", async () => { diff --git a/nodejs/lancedb/query.ts b/nodejs/lancedb/query.ts index 594e56a1..8c0f51cf 100644 --- a/nodejs/lancedb/query.ts +++ b/nodejs/lancedb/query.ts @@ -234,6 +234,11 @@ export class QueryBase return this; } + offset(offset: number): this { + this.doCall((inner: NativeQueryType) => inner.offset(offset)); + return this; + } + protected nativeExecute( options?: Partial, ): Promise { diff --git a/nodejs/src/query.rs b/nodejs/src/query.rs index c0fd16d9..d3fe7283 100644 --- a/nodejs/src/query.rs +++ b/nodejs/src/query.rs @@ -64,6 +64,11 @@ impl Query { self.inner = self.inner.clone().limit(limit as usize); } + #[napi] + pub fn offset(&mut self, offset: u32) { + self.inner = self.inner.clone().offset(offset as usize); + } + #[napi] pub fn nearest_to(&mut self, vector: Float32Array) -> Result { let inner = self @@ -166,6 +171,11 @@ impl VectorQuery { self.inner = self.inner.clone().limit(limit as usize); } + #[napi] + pub fn offset(&mut self, offset: u32) { + self.inner = self.inner.clone().offset(offset as usize); + } + #[napi(catch_unwind)] pub async fn execute( &self,