@lancedb/lancedb 0.19.0-beta.6 → 0.19.0-beta.8

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/dist/native.d.ts CHANGED
@@ -208,7 +208,7 @@ export interface ConnectionOptions {
208
208
  * Note: this consistency only applies to read operations. Write operations are
209
209
  * always consistent.
210
210
  */
211
- readConsistencyInterval?: number | null
211
+ readConsistencyInterval?: number
212
212
  /**
213
213
  * (For LanceDB OSS only): configuration for object storage.
214
214
  *
@@ -283,7 +283,7 @@ export class NativeMergeInsertBuilder {
283
283
  }
284
284
  export class Query {
285
285
  onlyIf(predicate: string): void
286
- fullTextSearch(query: unknown): void
286
+ fullTextSearch(query: object): void
287
287
  select(columns: Array<[string, string]>): void
288
288
  selectColumns(columns: Array<string>): void
289
289
  limit(limit: number): void
@@ -306,7 +306,7 @@ export class VectorQuery {
306
306
  ef(ef: number): void
307
307
  bypassVectorIndex(): void
308
308
  onlyIf(predicate: string): void
309
- fullTextSearch(query: unknown): void
309
+ fullTextSearch(query: object): void
310
310
  select(columns: Array<[string, string]>): void
311
311
  selectColumns(columns: Array<string>): void
312
312
  limit(limit: number): void
@@ -318,6 +318,12 @@ export class VectorQuery {
318
318
  explainPlan(verbose: boolean): Promise<string>
319
319
  analyzePlan(): Promise<string>
320
320
  }
321
+ export class JsFullTextQuery {
322
+ static matchQuery(query: string, column: string, boost: number, fuzziness: number | undefined | null, maxExpansions: number): JsFullTextQuery
323
+ static phraseQuery(query: string, column: string): JsFullTextQuery
324
+ static boostQuery(positive: JsFullTextQuery, negative: JsFullTextQuery, negativeBoost?: number | undefined | null): JsFullTextQuery
325
+ static multiMatchQuery(query: string, columns: Array<string>, boosts?: Array<number> | undefined | null): JsFullTextQuery
326
+ }
321
327
  /**
322
328
  * Reranker implementation that "wraps" a NodeJS Reranker implementation.
323
329
  * This contains references to the callbacks that can be used to invoke the
@@ -345,6 +351,7 @@ export class Table {
345
351
  delete(predicate: string): Promise<void>
346
352
  createIndex(index: Index | undefined | null, column: string, replace?: boolean | undefined | null): Promise<void>
347
353
  dropIndex(indexName: string): Promise<void>
354
+ prewarmIndex(indexName: string): Promise<void>
348
355
  update(onlyIf: string | undefined | null, columns: Array<[string, string]>): Promise<bigint>
349
356
  query(): Query
350
357
  vectorSearch(vector: Float32Array): VectorQuery
package/dist/native.js CHANGED
@@ -319,13 +319,14 @@ if (!nativeBinding) {
319
319
  }
320
320
  throw new Error(`Failed to load native binding`);
321
321
  }
322
- const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, Reranker, RrfReranker, Table } = nativeBinding;
322
+ const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, JsFullTextQuery, Reranker, RrfReranker, Table } = 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.JsFullTextQuery = JsFullTextQuery;
329
330
  module.exports.Reranker = Reranker;
330
331
  module.exports.RrfReranker = RrfReranker;
331
332
  module.exports.Table = Table;
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 { 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, VectorQuery as NativeVectorQuery } from "./native";
4
4
  import { Reranker } from "./rerankers";
5
5
  export declare class RecordBatchIterator implements AsyncIterator<RecordBatch> {
6
6
  private promisedInner?;
@@ -412,31 +412,41 @@ export declare enum FullTextQueryType {
412
412
  * including methods to retrieve the query type and convert the query to a dictionary format.
413
413
  */
414
414
  export interface FullTextQuery {
415
+ /**
416
+ * Returns the inner query object.
417
+ * This is the underlying query object used by the database engine.
418
+ * @ignore
419
+ */
420
+ inner: JsFullTextQuery;
421
+ /**
422
+ * The type of the full-text query.
423
+ */
415
424
  queryType(): FullTextQueryType;
416
- toDict(): Record<string, unknown>;
417
425
  }
426
+ export declare function instanceOfFullTextQuery(obj: any): obj is FullTextQuery;
418
427
  export declare class MatchQuery implements FullTextQuery {
419
- private query;
420
- private column;
421
- private boost;
422
- private fuzziness;
423
- private maxExpansions;
428
+ /** @ignore */
429
+ readonly inner: JsFullTextQuery;
424
430
  /**
425
431
  * Creates an instance of MatchQuery.
426
432
  *
427
433
  * @param query - The text query to search for.
428
434
  * @param column - The name of the column to search within.
429
- * @param boost - (Optional) The boost factor to influence the relevance score of this query. Default is `1.0`.
430
- * @param fuzziness - (Optional) The allowed edit distance for fuzzy matching. Default is `0`.
431
- * @param maxExpansions - (Optional) The maximum number of terms to consider for fuzzy matching. Default is `50`.
435
+ * @param options - Optional parameters for the match query.
436
+ * - `boost`: The boost factor for the query (default is 1.0).
437
+ * - `fuzziness`: The fuzziness level for the query (default is 0).
438
+ * - `maxExpansions`: The maximum number of terms to consider for fuzzy matching (default is 50).
432
439
  */
433
- constructor(query: string, column: string, boost?: number, fuzziness?: number, maxExpansions?: number);
440
+ constructor(query: string, column: string, options?: {
441
+ boost?: number;
442
+ fuzziness?: number;
443
+ maxExpansions?: number;
444
+ });
434
445
  queryType(): FullTextQueryType;
435
- toDict(): Record<string, unknown>;
436
446
  }
437
447
  export declare class PhraseQuery implements FullTextQuery {
438
- private query;
439
- private column;
448
+ /** @ignore */
449
+ readonly inner: JsFullTextQuery;
440
450
  /**
441
451
  * Creates an instance of `PhraseQuery`.
442
452
  *
@@ -445,38 +455,39 @@ export declare class PhraseQuery implements FullTextQuery {
445
455
  */
446
456
  constructor(query: string, column: string);
447
457
  queryType(): FullTextQueryType;
448
- toDict(): Record<string, unknown>;
449
458
  }
450
459
  export declare class BoostQuery implements FullTextQuery {
451
- private positive;
452
- private negative;
453
- private negativeBoost;
460
+ /** @ignore */
461
+ readonly inner: JsFullTextQuery;
454
462
  /**
455
463
  * Creates an instance of BoostQuery.
464
+ * The boost returns documents that match the positive query,
465
+ * but penalizes those that match the negative query.
466
+ * the penalty is controlled by the `negativeBoost` parameter.
456
467
  *
457
468
  * @param positive - The positive query that boosts the relevance score.
458
469
  * @param negative - The negative query that reduces the relevance score.
459
- * @param negativeBoost - The factor by which the negative query reduces the score.
470
+ * @param options - Optional parameters for the boost query.
471
+ * - `negativeBoost`: The boost factor for the negative query (default is 0.0).
460
472
  */
461
- constructor(positive: FullTextQuery, negative: FullTextQuery, negativeBoost: number);
473
+ constructor(positive: FullTextQuery, negative: FullTextQuery, options?: {
474
+ negativeBoost?: number;
475
+ });
462
476
  queryType(): FullTextQueryType;
463
- toDict(): Record<string, unknown>;
464
477
  }
465
478
  export declare class MultiMatchQuery implements FullTextQuery {
466
- private query;
467
- private columns;
468
- private boosts;
479
+ /** @ignore */
480
+ readonly inner: JsFullTextQuery;
469
481
  /**
470
482
  * Creates an instance of MultiMatchQuery.
471
483
  *
472
484
  * @param query - The text query to search for across multiple columns.
473
485
  * @param columns - An array of column names to search within.
474
- * @param boosts - (Optional) An array of boost factors corresponding to each column. Default is an array of 1.0 for each column.
475
- *
476
- * The `boosts` array should have the same length as `columns`. If not provided, all columns will have a default boost of 1.0.
477
- * If the length of `boosts` is less than `columns`, it will be padded with 1.0s.
486
+ * @param options - Optional parameters for the multi-match query.
487
+ * - `boosts`: An array of boost factors for each column (default is 1.0 for all).
478
488
  */
479
- constructor(query: string, columns: string[], boosts?: number[]);
489
+ constructor(query: string, columns: string[], options?: {
490
+ boosts?: number[];
491
+ });
480
492
  queryType(): FullTextQueryType;
481
- toDict(): Record<string, unknown>;
482
493
  }
package/dist/query.js CHANGED
@@ -3,7 +3,9 @@
3
3
  // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.FullTextQueryType = exports.Query = exports.VectorQuery = exports.QueryBase = exports.RecordBatchIterator = void 0;
6
+ exports.instanceOfFullTextQuery = instanceOfFullTextQuery;
6
7
  const arrow_1 = require("./arrow");
8
+ const native_1 = require("./native");
7
9
  class RecordBatchIterator {
8
10
  promisedInner;
9
11
  inner;
@@ -117,9 +119,7 @@ class QueryBase {
117
119
  });
118
120
  }
119
121
  else {
120
- // If query is a FullTextQuery object, convert it to a dict
121
- const queryObj = query.toDict();
122
- inner.fullTextSearch(queryObj);
122
+ inner.fullTextSearch({ query: query.inner });
123
123
  }
124
124
  });
125
125
  return this;
@@ -640,8 +640,7 @@ class Query extends QueryBase {
640
640
  });
641
641
  }
642
642
  else {
643
- const queryObj = query.toDict();
644
- inner.fullTextSearch(queryObj);
643
+ inner.fullTextSearch({ query: query.inner });
645
644
  }
646
645
  });
647
646
  return this;
@@ -663,49 +662,38 @@ var FullTextQueryType;
663
662
  FullTextQueryType["Boost"] = "boost";
664
663
  FullTextQueryType["MultiMatch"] = "multi_match";
665
664
  })(FullTextQueryType || (exports.FullTextQueryType = FullTextQueryType = {}));
665
+ // biome-ignore lint/suspicious/noExplicitAny: we want any here
666
+ function instanceOfFullTextQuery(obj) {
667
+ return obj != null && obj.inner instanceof native_1.JsFullTextQuery;
668
+ }
666
669
  class MatchQuery {
667
- query;
668
- column;
669
- boost;
670
- fuzziness;
671
- maxExpansions;
670
+ /** @ignore */
671
+ inner;
672
672
  /**
673
673
  * Creates an instance of MatchQuery.
674
674
  *
675
675
  * @param query - The text query to search for.
676
676
  * @param column - The name of the column to search within.
677
- * @param boost - (Optional) The boost factor to influence the relevance score of this query. Default is `1.0`.
678
- * @param fuzziness - (Optional) The allowed edit distance for fuzzy matching. Default is `0`.
679
- * @param maxExpansions - (Optional) The maximum number of terms to consider for fuzzy matching. Default is `50`.
677
+ * @param options - Optional parameters for the match query.
678
+ * - `boost`: The boost factor for the query (default is 1.0).
679
+ * - `fuzziness`: The fuzziness level for the query (default is 0).
680
+ * - `maxExpansions`: The maximum number of terms to consider for fuzzy matching (default is 50).
680
681
  */
681
- constructor(query, column, boost = 1.0, fuzziness = 0, maxExpansions = 50) {
682
- this.query = query;
683
- this.column = column;
684
- this.boost = boost;
685
- this.fuzziness = fuzziness;
686
- this.maxExpansions = maxExpansions;
682
+ constructor(query, column, options) {
683
+ let fuzziness = options?.fuzziness;
684
+ if (fuzziness === undefined) {
685
+ fuzziness = 0;
686
+ }
687
+ this.inner = native_1.JsFullTextQuery.matchQuery(query, column, options?.boost ?? 1.0, fuzziness, options?.maxExpansions ?? 50);
687
688
  }
688
689
  queryType() {
689
690
  return FullTextQueryType.Match;
690
691
  }
691
- toDict() {
692
- return {
693
- [this.queryType()]: {
694
- [this.column]: {
695
- query: this.query,
696
- boost: this.boost,
697
- fuzziness: this.fuzziness,
698
- // biome-ignore lint/style/useNamingConvention: use underscore for consistency with the other APIs
699
- max_expansions: this.maxExpansions,
700
- },
701
- },
702
- };
703
- }
704
692
  }
705
693
  exports.MatchQuery = MatchQuery;
706
694
  class PhraseQuery {
707
- query;
708
- column;
695
+ /** @ignore */
696
+ inner;
709
697
  /**
710
698
  * Creates an instance of `PhraseQuery`.
711
699
  *
@@ -713,82 +701,51 @@ class PhraseQuery {
713
701
  * @param column - The name of the column to search within.
714
702
  */
715
703
  constructor(query, column) {
716
- this.query = query;
717
- this.column = column;
704
+ this.inner = native_1.JsFullTextQuery.phraseQuery(query, column);
718
705
  }
719
706
  queryType() {
720
707
  return FullTextQueryType.MatchPhrase;
721
708
  }
722
- toDict() {
723
- return {
724
- [this.queryType()]: {
725
- [this.column]: this.query,
726
- },
727
- };
728
- }
729
709
  }
730
710
  exports.PhraseQuery = PhraseQuery;
731
711
  class BoostQuery {
732
- positive;
733
- negative;
734
- negativeBoost;
712
+ /** @ignore */
713
+ inner;
735
714
  /**
736
715
  * Creates an instance of BoostQuery.
716
+ * The boost returns documents that match the positive query,
717
+ * but penalizes those that match the negative query.
718
+ * the penalty is controlled by the `negativeBoost` parameter.
737
719
  *
738
720
  * @param positive - The positive query that boosts the relevance score.
739
721
  * @param negative - The negative query that reduces the relevance score.
740
- * @param negativeBoost - The factor by which the negative query reduces the score.
722
+ * @param options - Optional parameters for the boost query.
723
+ * - `negativeBoost`: The boost factor for the negative query (default is 0.0).
741
724
  */
742
- constructor(positive, negative, negativeBoost) {
743
- this.positive = positive;
744
- this.negative = negative;
745
- this.negativeBoost = negativeBoost;
725
+ constructor(positive, negative, options) {
726
+ this.inner = native_1.JsFullTextQuery.boostQuery(positive.inner, negative.inner, options?.negativeBoost);
746
727
  }
747
728
  queryType() {
748
729
  return FullTextQueryType.Boost;
749
730
  }
750
- toDict() {
751
- return {
752
- [this.queryType()]: {
753
- positive: this.positive.toDict(),
754
- negative: this.negative.toDict(),
755
- // biome-ignore lint/style/useNamingConvention: use underscore for consistency with the other APIs
756
- negative_boost: this.negativeBoost,
757
- },
758
- };
759
- }
760
731
  }
761
732
  exports.BoostQuery = BoostQuery;
762
733
  class MultiMatchQuery {
763
- query;
764
- columns;
765
- boosts;
734
+ /** @ignore */
735
+ inner;
766
736
  /**
767
737
  * Creates an instance of MultiMatchQuery.
768
738
  *
769
739
  * @param query - The text query to search for across multiple columns.
770
740
  * @param columns - An array of column names to search within.
771
- * @param boosts - (Optional) An array of boost factors corresponding to each column. Default is an array of 1.0 for each column.
772
- *
773
- * The `boosts` array should have the same length as `columns`. If not provided, all columns will have a default boost of 1.0.
774
- * If the length of `boosts` is less than `columns`, it will be padded with 1.0s.
741
+ * @param options - Optional parameters for the multi-match query.
742
+ * - `boosts`: An array of boost factors for each column (default is 1.0 for all).
775
743
  */
776
- constructor(query, columns, boosts = columns.map(() => 1.0)) {
777
- this.query = query;
778
- this.columns = columns;
779
- this.boosts = boosts;
744
+ constructor(query, columns, options) {
745
+ this.inner = native_1.JsFullTextQuery.multiMatchQuery(query, columns, options?.boosts);
780
746
  }
781
747
  queryType() {
782
748
  return FullTextQueryType.MultiMatch;
783
749
  }
784
- toDict() {
785
- return {
786
- [this.queryType()]: {
787
- query: this.query,
788
- columns: this.columns,
789
- boost: this.boosts,
790
- },
791
- };
792
- }
793
750
  }
794
751
  exports.MultiMatchQuery = MultiMatchQuery;
package/dist/table.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Table as ArrowTable, Data, DataType, IntoVector, Schema } from "./arrow
2
2
  import { IndexOptions } from "./indices";
3
3
  import { MergeInsertBuilder } from "./merge";
4
4
  import { AddColumnsSql, IndexConfig, IndexStatistics, OptimizeStats, Table as _NativeTable } from "./native";
5
- import { Query, VectorQuery } from "./query";
5
+ import { FullTextQuery, Query, VectorQuery } from "./query";
6
6
  import { IntoSql } from "./util";
7
7
  export { IndexConfig } from "./native";
8
8
  /**
@@ -187,6 +187,16 @@ export declare abstract class Table {
187
187
  * Use {@link Table.listIndices} to find the names of the indices.
188
188
  */
189
189
  abstract dropIndex(name: string): Promise<void>;
190
+ /**
191
+ * Prewarm an index in the table.
192
+ *
193
+ * @param name The name of the index.
194
+ *
195
+ * This will load the index into memory. This may reduce the cold-start time for
196
+ * future queries. If the index does not fit in the cache then this call may be
197
+ * wasteful.
198
+ */
199
+ abstract prewarmIndex(name: string): Promise<void>;
190
200
  /**
191
201
  * Create a {@link Query} Builder.
192
202
  *
@@ -249,7 +259,7 @@ export declare abstract class Table {
249
259
  * when "auto" is used, if the query is a string and an embedding function is defined, it will be treated as a vector query
250
260
  * if the query is a string and no embedding function is defined, it will be treated as a full text search query
251
261
  */
252
- abstract search(query: string | IntoVector, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
262
+ abstract search(query: string | IntoVector | FullTextQuery, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
253
263
  /**
254
264
  * Search the table with a given query vector.
255
265
  *
@@ -401,8 +411,9 @@ export declare class LocalTable extends Table {
401
411
  delete(predicate: string): Promise<void>;
402
412
  createIndex(column: string, options?: Partial<IndexOptions>): Promise<void>;
403
413
  dropIndex(name: string): Promise<void>;
414
+ prewarmIndex(name: string): Promise<void>;
404
415
  query(): Query;
405
- search(query: string | IntoVector, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
416
+ search(query: string | IntoVector | FullTextQuery, queryType?: string, ftsColumns?: string | string[]): VectorQuery | Query;
406
417
  vectorSearch(vector: IntoVector): VectorQuery;
407
418
  addColumns(newColumnTransforms: AddColumnsSql[]): Promise<void>;
408
419
  alterColumns(columnAlterations: ColumnAlteration[]): Promise<void>;
package/dist/table.js CHANGED
@@ -128,11 +128,14 @@ class LocalTable extends Table {
128
128
  async dropIndex(name) {
129
129
  await this.inner.dropIndex(name);
130
130
  }
131
+ async prewarmIndex(name) {
132
+ await this.inner.prewarmIndex(name);
133
+ }
131
134
  query() {
132
135
  return new query_1.Query(this.inner);
133
136
  }
134
137
  search(query, queryType = "auto", ftsColumns) {
135
- if (typeof query !== "string") {
138
+ if (typeof query !== "string" && !(0, query_1.instanceOfFullTextQuery)(query)) {
136
139
  if (queryType === "fts") {
137
140
  throw new Error("Cannot perform full text search on a vector query");
138
141
  }
@@ -146,7 +149,8 @@ class LocalTable extends Table {
146
149
  }
147
150
  // The query type is auto or vector
148
151
  // fall back to full text search if no embedding functions are defined and the query is a string
149
- if (queryType === "auto" && (0, registry_1.getRegistry)().length() === 0) {
152
+ if (queryType === "auto" &&
153
+ ((0, registry_1.getRegistry)().length() === 0 || (0, query_1.instanceOfFullTextQuery)(query))) {
150
154
  return this.query().fullTextSearch(query, {
151
155
  columns: ftsColumns,
152
156
  });
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "ann"
12
12
  ],
13
13
  "private": false,
14
- "version": "0.19.0-beta.6",
14
+ "version": "0.19.0-beta.8",
15
15
  "main": "dist/index.js",
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
@@ -100,14 +100,14 @@
100
100
  "reflect-metadata": "^0.2.2"
101
101
  },
102
102
  "optionalDependencies": {
103
- "@lancedb/lancedb-darwin-x64": "0.19.0-beta.6",
104
- "@lancedb/lancedb-darwin-arm64": "0.19.0-beta.6",
105
- "@lancedb/lancedb-linux-x64-gnu": "0.19.0-beta.6",
106
- "@lancedb/lancedb-linux-arm64-gnu": "0.19.0-beta.6",
107
- "@lancedb/lancedb-linux-x64-musl": "0.19.0-beta.6",
108
- "@lancedb/lancedb-linux-arm64-musl": "0.19.0-beta.6",
109
- "@lancedb/lancedb-win32-x64-msvc": "0.19.0-beta.6",
110
- "@lancedb/lancedb-win32-arm64-msvc": "0.19.0-beta.6"
103
+ "@lancedb/lancedb-darwin-x64": "0.19.0-beta.8",
104
+ "@lancedb/lancedb-darwin-arm64": "0.19.0-beta.8",
105
+ "@lancedb/lancedb-linux-x64-gnu": "0.19.0-beta.8",
106
+ "@lancedb/lancedb-linux-arm64-gnu": "0.19.0-beta.8",
107
+ "@lancedb/lancedb-linux-x64-musl": "0.19.0-beta.8",
108
+ "@lancedb/lancedb-linux-arm64-musl": "0.19.0-beta.8",
109
+ "@lancedb/lancedb-win32-x64-msvc": "0.19.0-beta.8",
110
+ "@lancedb/lancedb-win32-arm64-msvc": "0.19.0-beta.8"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "apache-arrow": ">=15.0.0 <=18.1.0"