@lancedb/lancedb 0.21.2-beta.1 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md ADDED
@@ -0,0 +1,13 @@
1
+ These are the typescript bindings of LanceDB.
2
+ The core Rust library is in the `../rust/lancedb` directory, the rust binding
3
+ code is in the `src/` directory and the typescript bindings are in
4
+ the `lancedb/` directory.
5
+
6
+ Whenever you change the Rust code, you will need to recompile: `npm run build`.
7
+
8
+ Common commands:
9
+ * Build: `npm run build`
10
+ * Lint: `npm run lint`
11
+ * Fix lints: `npm run lint-fix`
12
+ * Test: `npm test`
13
+ * Run single test file: `npm test __test__/arrow.test.ts`
package/dist/arrow.js CHANGED
@@ -56,6 +56,13 @@ exports.dataTypeToJson = dataTypeToJson;
56
56
  const apache_arrow_1 = require("apache-arrow");
57
57
  const registry_1 = require("./embedding/registry");
58
58
  const sanitize_1 = require("./sanitize");
59
+ /**
60
+ * Check if a field name indicates a vector column.
61
+ */
62
+ function nameSuggestsVectorColumn(fieldName) {
63
+ const nameLower = fieldName.toLowerCase();
64
+ return nameLower.includes("vector") || nameLower.includes("embedding");
65
+ }
59
66
  __exportStar(require("apache-arrow"), exports);
60
67
  function isMultiVector(value) {
61
68
  return Array.isArray(value) && isIntoVector(value[0]);
@@ -494,10 +501,18 @@ function inferType(value, path, opts) {
494
501
  return undefined;
495
502
  }
496
503
  // Try to automatically detect embedding columns.
497
- if (valueType instanceof apache_arrow_1.Float && path[path.length - 1] === "vector") {
498
- // We default to Float32 for vectors.
499
- const child = new apache_arrow_1.Field("item", new apache_arrow_1.Float32(), true);
500
- return new apache_arrow_1.FixedSizeList(value.length, child);
504
+ if (nameSuggestsVectorColumn(path[path.length - 1])) {
505
+ // Check if value is a Uint8Array for integer vector type determination
506
+ if (value instanceof Uint8Array) {
507
+ // For integer vectors, we default to Uint8 (matching Python implementation)
508
+ const child = new apache_arrow_1.Field("item", new apache_arrow_1.Uint8(), true);
509
+ return new apache_arrow_1.FixedSizeList(value.length, child);
510
+ }
511
+ else {
512
+ // For float vectors, we default to Float32
513
+ const child = new apache_arrow_1.Field("item", new apache_arrow_1.Float32(), true);
514
+ return new apache_arrow_1.FixedSizeList(value.length, child);
515
+ }
501
516
  }
502
517
  else {
503
518
  const child = new apache_arrow_1.Field("item", valueType, true);
@@ -62,6 +62,9 @@ export interface OpenTableOptions {
62
62
  /**
63
63
  * Set the size of the index cache, specified as a number of entries
64
64
  *
65
+ * @deprecated Use session-level cache configuration instead.
66
+ * Create a Session with custom cache sizes and pass it to the connect() function.
67
+ *
65
68
  * The exact meaning of an "entry" will depend on the type of index:
66
69
  * - IVF: there is one entry for each IVF partition
67
70
  * - BTREE: there is one entry for the entire index
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Connection } from "./connection";
2
- import { ConnectionOptions } from "./native.js";
2
+ import { ConnectionOptions, Session } from "./native.js";
3
3
  export { AddColumnsSql, ConnectionOptions, IndexStatistics, IndexConfig, ClientConfig, TimeoutConfig, RetryConfig, OptimizeStats, CompactionStats, RemovalStats, TableStatistics, FragmentStatistics, FragmentSummaryStats, Tags, TagContents, MergeResult, AddResult, AddColumnsResult, AlterColumnsResult, DeleteResult, DropColumnsResult, UpdateResult, } from "./native.js";
4
4
  export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
5
5
  export { Connection, CreateTableOptions, TableNamesOptions, OpenTableOptions, } from "./connection";
6
- export { ExecutableQuery, Query, QueryBase, VectorQuery, QueryExecutionOptions, FullTextSearchOptions, RecordBatchIterator, FullTextQuery, MatchQuery, PhraseQuery, BoostQuery, MultiMatchQuery, BooleanQuery, FullTextQueryType, Operator, Occur, } from "./query";
6
+ export { Session } from "./native.js";
7
+ export { ExecutableQuery, Query, QueryBase, VectorQuery, TakeQuery, QueryExecutionOptions, FullTextSearchOptions, RecordBatchIterator, FullTextQuery, MatchQuery, PhraseQuery, BoostQuery, MultiMatchQuery, BooleanQuery, FullTextQueryType, Operator, Occur, } from "./query";
7
8
  export { Index, IndexOptions, IvfPqOptions, IvfFlatOptions, HnswPqOptions, HnswSqOptions, FtsOptions, } from "./indices";
8
9
  export { Table, AddDataOptions, UpdateOptions, OptimizeOptions, Version, ColumnAlteration, } from "./table";
9
10
  export { MergeInsertBuilder, WriteExecutionOptions } from "./merge";
@@ -35,7 +36,7 @@ export { IntoSql, packBits } from "./util";
35
36
  * });
36
37
  * ```
37
38
  */
38
- export declare function connect(uri: string, options?: Partial<ConnectionOptions>): Promise<Connection>;
39
+ export declare function connect(uri: string, options?: Partial<ConnectionOptions>, session?: Session): Promise<Connection>;
39
40
  /**
40
41
  * Connect to a LanceDB instance at the given URI.
41
42
  *
@@ -53,6 +54,15 @@ export declare function connect(uri: string, options?: Partial<ConnectionOptions
53
54
  * storageOptions: {timeout: "60s"}
54
55
  * });
55
56
  * ```
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const session = Session.default();
61
+ * const conn = await connect({
62
+ * uri: "/path/to/database",
63
+ * session: session
64
+ * });
65
+ * ```
56
66
  */
57
67
  export declare function connect(options: Partial<ConnectionOptions> & {
58
68
  uri: string;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.packBits = exports.rerankers = exports.embedding = exports.MergeInsertBuilder = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.TagContents = exports.Tags = void 0;
5
+ exports.packBits = exports.rerankers = exports.embedding = exports.MergeInsertBuilder = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.TakeQuery = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Session = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.TagContents = exports.Tags = void 0;
6
6
  exports.connect = connect;
7
7
  const connection_1 = require("./connection");
8
8
  const native_js_1 = require("./native.js");
@@ -15,10 +15,13 @@ Object.defineProperty(exports, "MakeArrowTableOptions", { enumerable: true, get:
15
15
  Object.defineProperty(exports, "VectorColumnOptions", { enumerable: true, get: function () { return arrow_1.VectorColumnOptions; } });
16
16
  var connection_2 = require("./connection");
17
17
  Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_2.Connection; } });
18
+ var native_js_3 = require("./native.js");
19
+ Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return native_js_3.Session; } });
18
20
  var query_1 = require("./query");
19
21
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
20
22
  Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
21
23
  Object.defineProperty(exports, "VectorQuery", { enumerable: true, get: function () { return query_1.VectorQuery; } });
24
+ Object.defineProperty(exports, "TakeQuery", { enumerable: true, get: function () { return query_1.TakeQuery; } });
22
25
  Object.defineProperty(exports, "RecordBatchIterator", { enumerable: true, get: function () { return query_1.RecordBatchIterator; } });
23
26
  Object.defineProperty(exports, "MatchQuery", { enumerable: true, get: function () { return query_1.MatchQuery; } });
24
27
  Object.defineProperty(exports, "PhraseQuery", { enumerable: true, get: function () { return query_1.PhraseQuery; } });
@@ -38,21 +41,23 @@ exports.embedding = require("./embedding");
38
41
  exports.rerankers = require("./rerankers");
39
42
  var util_1 = require("./util");
40
43
  Object.defineProperty(exports, "packBits", { enumerable: true, get: function () { return util_1.packBits; } });
41
- async function connect(uriOrOptions, options = {}) {
44
+ async function connect(uriOrOptions, options) {
42
45
  let uri;
46
+ let finalOptions = {};
43
47
  if (typeof uriOrOptions !== "string") {
44
48
  const { uri: uri_, ...opts } = uriOrOptions;
45
49
  uri = uri_;
46
- options = opts;
50
+ finalOptions = opts;
47
51
  }
48
52
  else {
49
53
  uri = uriOrOptions;
54
+ finalOptions = options || {};
50
55
  }
51
56
  if (!uri) {
52
57
  throw new Error("uri is required");
53
58
  }
54
- options = options ?? {};
55
- options.storageOptions = (0, connection_1.cleanseStorageOptions)(options.storageOptions);
56
- const nativeConn = await native_js_1.Connection.new(uri, options);
59
+ finalOptions = finalOptions ?? {};
60
+ finalOptions.storageOptions = (0, connection_1.cleanseStorageOptions)(finalOptions.storageOptions);
61
+ const nativeConn = await native_js_1.Connection.new(uri, finalOptions);
57
62
  return new connection_1.LocalConnection(nativeConn);
58
63
  }
package/dist/native.d.ts CHANGED
@@ -5,6 +5,14 @@
5
5
 
6
6
  /** Timeout configuration for remote HTTP client. */
7
7
  export interface TimeoutConfig {
8
+ /**
9
+ * The overall timeout for the entire request in seconds. This includes
10
+ * connection, send, and read time. If the entire request doesn't complete
11
+ * within this time, it will fail. Default is None (no overall timeout).
12
+ * This can also be set via the environment variable `LANCE_CLIENT_TIMEOUT`,
13
+ * as an integer number of seconds.
14
+ */
15
+ timeout?: number
8
16
  /**
9
17
  * The timeout for establishing a connection in seconds. Default is 120
10
18
  * seconds (2 minutes). This can also be set via the environment variable
@@ -274,6 +282,11 @@ export interface ConnectionOptions {
274
282
  * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
275
283
  */
276
284
  storageOptions?: Record<string, string>
285
+ /**
286
+ * (For LanceDB OSS only): the session to use for this connection. Holds
287
+ * shared caches and other session-specific state.
288
+ */
289
+ session?: Session
277
290
  /** (For LanceDB cloud only): configuration for the remote HTTP client. */
278
291
  clientConfig?: ClientConfig
279
292
  /**
@@ -380,6 +393,14 @@ export class VectorQuery {
380
393
  explainPlan(verbose: boolean): Promise<string>
381
394
  analyzePlan(): Promise<string>
382
395
  }
396
+ export class TakeQuery {
397
+ select(columns: Array<[string, string]>): void
398
+ selectColumns(columns: Array<string>): void
399
+ withRowId(): void
400
+ execute(maxBatchLength?: number | undefined | null, timeoutMs?: number | undefined | null): Promise<RecordBatchIterator>
401
+ explainPlan(verbose: boolean): Promise<string>
402
+ analyzePlan(): Promise<string>
403
+ }
383
404
  export class JsFullTextQuery {
384
405
  static matchQuery(query: string, column: string, boost: number, fuzziness: number | undefined | null, maxExpansions: number, operator: string, prefixLength: number): JsFullTextQuery
385
406
  static phraseQuery(query: string, column: string, slop: number): JsFullTextQuery
@@ -403,6 +424,40 @@ export class RrfReranker {
403
424
  static tryNew(k: Float32Array): Promise<RrfReranker>
404
425
  rerankHybrid(query: string, vecResults: Buffer, ftsResults: Buffer): Promise<Buffer>
405
426
  }
427
+ /**
428
+ * A session for managing caches and object stores across LanceDB operations.
429
+ *
430
+ * Sessions allow you to configure cache sizes for index and metadata caches,
431
+ * which can significantly impact memory use and performance. They can
432
+ * also be re-used across multiple connections to share the same cache state.
433
+ */
434
+ export class Session {
435
+ /**
436
+ * Create a new session with custom cache sizes.
437
+ *
438
+ * # Parameters
439
+ *
440
+ * - `index_cache_size_bytes`: The size of the index cache in bytes.
441
+ * Index data is stored in memory in this cache to speed up queries.
442
+ * Defaults to 6GB if not specified.
443
+ * - `metadata_cache_size_bytes`: The size of the metadata cache in bytes.
444
+ * The metadata cache stores file metadata and schema information in memory.
445
+ * This cache improves scan and write performance.
446
+ * Defaults to 1GB if not specified.
447
+ */
448
+ constructor(indexCacheSizeBytes?: bigint | undefined | null, metadataCacheSizeBytes?: bigint | undefined | null)
449
+ /**
450
+ * Create a session with default cache sizes.
451
+ *
452
+ * This is equivalent to creating a session with 6GB index cache
453
+ * and 1GB metadata cache.
454
+ */
455
+ static default(): Session
456
+ /** Get the current size of the session caches in bytes. */
457
+ sizeBytes(): bigint
458
+ /** Get the approximate number of items cached in the session. */
459
+ approxNumItems(): number
460
+ }
406
461
  export class Table {
407
462
  name: string
408
463
  display(): string
@@ -420,6 +475,8 @@ export class Table {
420
475
  stats(): Promise<TableStatistics>
421
476
  update(onlyIf: string | undefined | null, columns: Array<[string, string]>): Promise<UpdateResult>
422
477
  query(): Query
478
+ takeOffsets(offsets: Array<number>): TakeQuery
479
+ takeRowIds(rowIds: Array<number>): TakeQuery
423
480
  vectorSearch(vector: Float32Array): VectorQuery
424
481
  addColumns(transforms: Array<AddColumnsSql>): Promise<AddColumnsResult>
425
482
  alterColumns(alterations: Array<ColumnAlteration>): Promise<AlterColumnsResult>
package/dist/native.js CHANGED
@@ -319,16 +319,18 @@ if (!nativeBinding) {
319
319
  }
320
320
  throw new Error(`Failed to load native binding`);
321
321
  }
322
- const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, JsFullTextQuery, Reranker, RrfReranker, Table, TagContents, Tags } = nativeBinding;
322
+ const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, TakeQuery, JsFullTextQuery, Reranker, RrfReranker, Session, Table, TagContents, Tags } = nativeBinding;
323
323
  module.exports.Connection = Connection;
324
324
  module.exports.Index = Index;
325
325
  module.exports.RecordBatchIterator = RecordBatchIterator;
326
326
  module.exports.NativeMergeInsertBuilder = NativeMergeInsertBuilder;
327
327
  module.exports.Query = Query;
328
328
  module.exports.VectorQuery = VectorQuery;
329
+ module.exports.TakeQuery = TakeQuery;
329
330
  module.exports.JsFullTextQuery = JsFullTextQuery;
330
331
  module.exports.Reranker = Reranker;
331
332
  module.exports.RrfReranker = RrfReranker;
333
+ module.exports.Session = Session;
332
334
  module.exports.Table = Table;
333
335
  module.exports.TagContents = TagContents;
334
336
  module.exports.Tags = Tags;
package/dist/query.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Table as ArrowTable, type IntoVector, RecordBatch } from "./arrow";
2
2
  import { type IvfPqOptions } from "./indices";
3
- import { JsFullTextQuery, RecordBatchIterator as NativeBatchIterator, Query as NativeQuery, Table as NativeTable, VectorQuery as NativeVectorQuery } from "./native";
3
+ import { JsFullTextQuery, RecordBatchIterator as NativeBatchIterator, Query as NativeQuery, Table as NativeTable, TakeQuery as NativeTakeQuery, VectorQuery as NativeVectorQuery } from "./native";
4
4
  import { Reranker } from "./rerankers";
5
5
  export declare class RecordBatchIterator implements AsyncIterator<RecordBatch> {
6
6
  private promisedInner?;
@@ -43,7 +43,7 @@ export interface FullTextSearchOptions {
43
43
  *
44
44
  * @hideconstructor
45
45
  */
46
- export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery> implements AsyncIterable<RecordBatch> {
46
+ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery | NativeTakeQuery> implements AsyncIterable<RecordBatch> {
47
47
  protected inner: NativeQueryType | Promise<NativeQueryType>;
48
48
  /**
49
49
  * @hidden
@@ -53,26 +53,6 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
53
53
  * @hidden
54
54
  */
55
55
  protected doCall(fn: (inner: NativeQueryType) => void): void;
56
- /**
57
- * A filter statement to be applied to this query.
58
- *
59
- * The filter should be supplied as an SQL query string. For example:
60
- * @example
61
- * x > 10
62
- * y > 0 AND y < 100
63
- * x > 5 OR y = 'test'
64
- *
65
- * Filtering performance can often be improved by creating a scalar index
66
- * on the filter column(s).
67
- */
68
- where(predicate: string): this;
69
- /**
70
- * A filter statement to be applied to this query.
71
- * @see where
72
- * @deprecated Use `where` instead
73
- */
74
- filter(predicate: string): this;
75
- fullTextSearch(query: string | FullTextQuery, options?: Partial<FullTextSearchOptions>): this;
76
56
  /**
77
57
  * Return only the specified columns.
78
58
  *
@@ -104,21 +84,6 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
104
84
  * object insertion order is easy to get wrong and `Map` is more foolproof.
105
85
  */
106
86
  select(columns: string[] | Map<string, string> | Record<string, string> | string): this;
107
- /**
108
- * Set the maximum number of results to return.
109
- *
110
- * By default, a plain search has no limit. If this method is not
111
- * called then every valid row from the table will be returned.
112
- */
113
- limit(limit: number): this;
114
- offset(offset: number): this;
115
- /**
116
- * Skip searching un-indexed data. This can make search faster, but will miss
117
- * any data that is not yet indexed.
118
- *
119
- * Use {@link Table#optimize} to index all un-indexed data.
120
- */
121
- fastSearch(): this;
122
87
  /**
123
88
  * Whether to return the row id in the results.
124
89
  *
@@ -197,6 +162,49 @@ export declare class QueryBase<NativeQueryType extends NativeQuery | NativeVecto
197
162
  */
198
163
  analyzePlan(): Promise<string>;
199
164
  }
165
+ export declare class StandardQueryBase<NativeQueryType extends NativeQuery | NativeVectorQuery> extends QueryBase<NativeQueryType> implements ExecutableQuery {
166
+ constructor(inner: NativeQueryType | Promise<NativeQueryType>);
167
+ /**
168
+ * A filter statement to be applied to this query.
169
+ *
170
+ * The filter should be supplied as an SQL query string. For example:
171
+ * @example
172
+ * x > 10
173
+ * y > 0 AND y < 100
174
+ * x > 5 OR y = 'test'
175
+ *
176
+ * Filtering performance can often be improved by creating a scalar index
177
+ * on the filter column(s).
178
+ */
179
+ where(predicate: string): this;
180
+ /**
181
+ * A filter statement to be applied to this query.
182
+ * @see where
183
+ * @deprecated Use `where` instead
184
+ */
185
+ filter(predicate: string): this;
186
+ fullTextSearch(query: string | FullTextQuery, options?: Partial<FullTextSearchOptions>): this;
187
+ /**
188
+ * Set the maximum number of results to return.
189
+ *
190
+ * By default, a plain search has no limit. If this method is not
191
+ * called then every valid row from the table will be returned.
192
+ */
193
+ limit(limit: number): this;
194
+ /**
195
+ * Set the number of rows to skip before returning results.
196
+ *
197
+ * This is useful for pagination.
198
+ */
199
+ offset(offset: number): this;
200
+ /**
201
+ * Skip searching un-indexed data. This can make search faster, but will miss
202
+ * any data that is not yet indexed.
203
+ *
204
+ * Use {@link Table#optimize} to index all un-indexed data.
205
+ */
206
+ fastSearch(): this;
207
+ }
200
208
  /**
201
209
  * An interface for a query that can be executed
202
210
  *
@@ -213,7 +221,7 @@ export interface ExecutableQuery {
213
221
  *
214
222
  * @hideconstructor
215
223
  */
216
- export declare class VectorQuery extends QueryBase<NativeVectorQuery> {
224
+ export declare class VectorQuery extends StandardQueryBase<NativeVectorQuery> {
217
225
  /**
218
226
  * @hidden
219
227
  */
@@ -364,13 +372,21 @@ export declare class VectorQuery extends QueryBase<NativeVectorQuery> {
364
372
  addQueryVector(vector: IntoVector): VectorQuery;
365
373
  rerank(reranker: Reranker): VectorQuery;
366
374
  }
375
+ /**
376
+ * A query that returns a subset of the rows in the table.
377
+ *
378
+ * @hideconstructor
379
+ */
380
+ export declare class TakeQuery extends QueryBase<NativeTakeQuery> {
381
+ constructor(inner: NativeTakeQuery);
382
+ }
367
383
  /** A builder for LanceDB queries.
368
384
  *
369
385
  * @see {@link Table#query}, {@link Table#search}
370
386
  *
371
387
  * @hideconstructor
372
388
  */
373
- export declare class Query extends QueryBase<NativeQuery> {
389
+ export declare class Query extends StandardQueryBase<NativeQuery> {
374
390
  /**
375
391
  * @hidden
376
392
  */
package/dist/query.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.Query = exports.VectorQuery = exports.QueryBase = exports.RecordBatchIterator = void 0;
5
+ exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.Query = exports.TakeQuery = exports.VectorQuery = exports.StandardQueryBase = exports.QueryBase = exports.RecordBatchIterator = void 0;
6
6
  exports.instanceOfFullTextQuery = instanceOfFullTextQuery;
7
7
  const arrow_1 = require("./arrow");
8
8
  const native_1 = require("./native");
@@ -77,53 +77,6 @@ class QueryBase {
77
77
  fn(this.inner);
78
78
  }
79
79
  }
80
- /**
81
- * A filter statement to be applied to this query.
82
- *
83
- * The filter should be supplied as an SQL query string. For example:
84
- * @example
85
- * x > 10
86
- * y > 0 AND y < 100
87
- * x > 5 OR y = 'test'
88
- *
89
- * Filtering performance can often be improved by creating a scalar index
90
- * on the filter column(s).
91
- */
92
- where(predicate) {
93
- this.doCall((inner) => inner.onlyIf(predicate));
94
- return this;
95
- }
96
- /**
97
- * A filter statement to be applied to this query.
98
- * @see where
99
- * @deprecated Use `where` instead
100
- */
101
- filter(predicate) {
102
- return this.where(predicate);
103
- }
104
- fullTextSearch(query, options) {
105
- let columns = null;
106
- if (options) {
107
- if (typeof options.columns === "string") {
108
- columns = [options.columns];
109
- }
110
- else if (Array.isArray(options.columns)) {
111
- columns = options.columns;
112
- }
113
- }
114
- this.doCall((inner) => {
115
- if (typeof query === "string") {
116
- inner.fullTextSearch({
117
- query: query,
118
- columns: columns,
119
- });
120
- }
121
- else {
122
- inner.fullTextSearch({ query: query.inner });
123
- }
124
- });
125
- return this;
126
- }
127
80
  /**
128
81
  * Return only the specified columns.
129
82
  *
@@ -179,30 +132,6 @@ class QueryBase {
179
132
  }
180
133
  return this;
181
134
  }
182
- /**
183
- * Set the maximum number of results to return.
184
- *
185
- * By default, a plain search has no limit. If this method is not
186
- * called then every valid row from the table will be returned.
187
- */
188
- limit(limit) {
189
- this.doCall((inner) => inner.limit(limit));
190
- return this;
191
- }
192
- offset(offset) {
193
- this.doCall((inner) => inner.offset(offset));
194
- return this;
195
- }
196
- /**
197
- * Skip searching un-indexed data. This can make search faster, but will miss
198
- * any data that is not yet indexed.
199
- *
200
- * Use {@link Table#optimize} to index all un-indexed data.
201
- */
202
- fastSearch() {
203
- this.doCall((inner) => inner.fastSearch());
204
- return this;
205
- }
206
135
  /**
207
136
  * Whether to return the row id in the results.
208
137
  *
@@ -329,6 +258,88 @@ class QueryBase {
329
258
  }
330
259
  }
331
260
  exports.QueryBase = QueryBase;
261
+ class StandardQueryBase extends QueryBase {
262
+ constructor(inner) {
263
+ super(inner);
264
+ }
265
+ /**
266
+ * A filter statement to be applied to this query.
267
+ *
268
+ * The filter should be supplied as an SQL query string. For example:
269
+ * @example
270
+ * x > 10
271
+ * y > 0 AND y < 100
272
+ * x > 5 OR y = 'test'
273
+ *
274
+ * Filtering performance can often be improved by creating a scalar index
275
+ * on the filter column(s).
276
+ */
277
+ where(predicate) {
278
+ this.doCall((inner) => inner.onlyIf(predicate));
279
+ return this;
280
+ }
281
+ /**
282
+ * A filter statement to be applied to this query.
283
+ * @see where
284
+ * @deprecated Use `where` instead
285
+ */
286
+ filter(predicate) {
287
+ return this.where(predicate);
288
+ }
289
+ fullTextSearch(query, options) {
290
+ let columns = null;
291
+ if (options) {
292
+ if (typeof options.columns === "string") {
293
+ columns = [options.columns];
294
+ }
295
+ else if (Array.isArray(options.columns)) {
296
+ columns = options.columns;
297
+ }
298
+ }
299
+ this.doCall((inner) => {
300
+ if (typeof query === "string") {
301
+ inner.fullTextSearch({
302
+ query: query,
303
+ columns: columns,
304
+ });
305
+ }
306
+ else {
307
+ inner.fullTextSearch({ query: query.inner });
308
+ }
309
+ });
310
+ return this;
311
+ }
312
+ /**
313
+ * Set the maximum number of results to return.
314
+ *
315
+ * By default, a plain search has no limit. If this method is not
316
+ * called then every valid row from the table will be returned.
317
+ */
318
+ limit(limit) {
319
+ this.doCall((inner) => inner.limit(limit));
320
+ return this;
321
+ }
322
+ /**
323
+ * Set the number of rows to skip before returning results.
324
+ *
325
+ * This is useful for pagination.
326
+ */
327
+ offset(offset) {
328
+ this.doCall((inner) => inner.offset(offset));
329
+ return this;
330
+ }
331
+ /**
332
+ * Skip searching un-indexed data. This can make search faster, but will miss
333
+ * any data that is not yet indexed.
334
+ *
335
+ * Use {@link Table#optimize} to index all un-indexed data.
336
+ */
337
+ fastSearch() {
338
+ this.doCall((inner) => inner.fastSearch());
339
+ return this;
340
+ }
341
+ }
342
+ exports.StandardQueryBase = StandardQueryBase;
332
343
  /**
333
344
  * A builder used to construct a vector search
334
345
  *
@@ -338,7 +349,7 @@ exports.QueryBase = QueryBase;
338
349
  *
339
350
  * @hideconstructor
340
351
  */
341
- class VectorQuery extends QueryBase {
352
+ class VectorQuery extends StandardQueryBase {
342
353
  /**
343
354
  * @hidden
344
355
  */
@@ -575,13 +586,24 @@ class VectorQuery extends QueryBase {
575
586
  }
576
587
  }
577
588
  exports.VectorQuery = VectorQuery;
589
+ /**
590
+ * A query that returns a subset of the rows in the table.
591
+ *
592
+ * @hideconstructor
593
+ */
594
+ class TakeQuery extends QueryBase {
595
+ constructor(inner) {
596
+ super(inner);
597
+ }
598
+ }
599
+ exports.TakeQuery = TakeQuery;
578
600
  /** A builder for LanceDB queries.
579
601
  *
580
602
  * @see {@link Table#query}, {@link Table#search}
581
603
  *
582
604
  * @hideconstructor
583
605
  */
584
- class Query extends QueryBase {
606
+ class Query extends StandardQueryBase {
585
607
  /**
586
608
  * @hidden
587
609
  */
package/dist/table.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Table as ArrowTable, Data, DataType, IntoVector, MultiVector, Schema }
2
2
  import { IndexOptions } from "./indices";
3
3
  import { MergeInsertBuilder } from "./merge";
4
4
  import { AddColumnsResult, AddColumnsSql, AddResult, AlterColumnsResult, DeleteResult, DropColumnsResult, IndexConfig, IndexStatistics, OptimizeStats, TableStatistics, Tags, UpdateResult, Table as _NativeTable } from "./native";
5
- import { FullTextQuery, Query, VectorQuery } from "./query";
5
+ import { FullTextQuery, Query, TakeQuery, VectorQuery } from "./query";
6
6
  import { IntoSql } from "./util";
7
7
  export { IndexConfig } from "./native";
8
8
  /**
@@ -269,6 +269,18 @@ export declare abstract class Table {
269
269
  * @returns {Query} A builder that can be used to parameterize the query
270
270
  */
271
271
  abstract query(): Query;
272
+ /**
273
+ * Create a query that returns a subset of the rows in the table.
274
+ * @param offsets The offsets of the rows to return.
275
+ * @returns A builder that can be used to parameterize the query.
276
+ */
277
+ abstract takeOffsets(offsets: number[]): TakeQuery;
278
+ /**
279
+ * Create a query that returns a subset of the rows in the table.
280
+ * @param rowIds The row ids of the rows to return.
281
+ * @returns A builder that can be used to parameterize the query.
282
+ */
283
+ abstract takeRowIds(rowIds: number[]): TakeQuery;
272
284
  /**
273
285
  * Create a search query to find the nearest neighbors
274
286
  * of the given query
@@ -462,6 +474,8 @@ export declare class LocalTable extends Table {
462
474
  dropIndex(name: string): Promise<void>;
463
475
  prewarmIndex(name: string): Promise<void>;
464
476
  waitForIndex(indexNames: string[], timeoutSeconds: number): Promise<void>;
477
+ takeOffsets(offsets: number[]): TakeQuery;
478
+ takeRowIds(rowIds: number[]): TakeQuery;
465
479
  query(): Query;
466
480
  search(query: string | IntoVector | MultiVector | FullTextQuery, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
467
481
  vectorSearch(vector: IntoVector | MultiVector): VectorQuery;
package/dist/table.js CHANGED
@@ -134,6 +134,12 @@ class LocalTable extends Table {
134
134
  async waitForIndex(indexNames, timeoutSeconds) {
135
135
  await this.inner.waitForIndex(indexNames, timeoutSeconds);
136
136
  }
137
+ takeOffsets(offsets) {
138
+ return new query_1.TakeQuery(this.inner.takeOffsets(offsets));
139
+ }
140
+ takeRowIds(rowIds) {
141
+ return new query_1.TakeQuery(this.inner.takeRowIds(rowIds));
142
+ }
137
143
  query() {
138
144
  return new query_1.Query(this.inner);
139
145
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "ann"
12
12
  ],
13
13
  "private": false,
14
- "version": "0.21.2-beta.1",
14
+ "version": "0.21.3",
15
15
  "main": "dist/index.js",
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  ]
37
37
  }
38
38
  },
39
- "license": "Apache 2.0",
39
+ "license": "Apache-2.0",
40
40
  "devDependencies": {
41
41
  "@aws-sdk/client-dynamodb": "^3.33.0",
42
42
  "@aws-sdk/client-kms": "^3.33.0",
@@ -100,14 +100,14 @@
100
100
  "reflect-metadata": "^0.2.2"
101
101
  },
102
102
  "optionalDependencies": {
103
- "@lancedb/lancedb-darwin-x64": "0.21.2-beta.1",
104
- "@lancedb/lancedb-darwin-arm64": "0.21.2-beta.1",
105
- "@lancedb/lancedb-linux-x64-gnu": "0.21.2-beta.1",
106
- "@lancedb/lancedb-linux-arm64-gnu": "0.21.2-beta.1",
107
- "@lancedb/lancedb-linux-x64-musl": "0.21.2-beta.1",
108
- "@lancedb/lancedb-linux-arm64-musl": "0.21.2-beta.1",
109
- "@lancedb/lancedb-win32-x64-msvc": "0.21.2-beta.1",
110
- "@lancedb/lancedb-win32-arm64-msvc": "0.21.2-beta.1"
103
+ "@lancedb/lancedb-darwin-x64": "0.21.3",
104
+ "@lancedb/lancedb-darwin-arm64": "0.21.3",
105
+ "@lancedb/lancedb-linux-x64-gnu": "0.21.3",
106
+ "@lancedb/lancedb-linux-arm64-gnu": "0.21.3",
107
+ "@lancedb/lancedb-linux-x64-musl": "0.21.3",
108
+ "@lancedb/lancedb-linux-arm64-musl": "0.21.3",
109
+ "@lancedb/lancedb-win32-x64-msvc": "0.21.3",
110
+ "@lancedb/lancedb-win32-arm64-msvc": "0.21.3"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "apache-arrow": ">=15.0.0 <=18.1.0"