@lancedb/lancedb 0.4.15 → 0.4.18

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.
@@ -1,6 +1,19 @@
1
- import { Connection as LanceDbConnection } from "./native";
1
+ import { ConnectionOptions, Connection as LanceDbConnection } from "./native";
2
2
  import { Table } from "./table";
3
3
  import { Table as ArrowTable, Schema } from "apache-arrow";
4
+ /**
5
+ * Connect to a LanceDB instance at the given URI.
6
+ *
7
+ * Accepted formats:
8
+ *
9
+ * - `/path/to/database` - local database
10
+ * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
11
+ * - `db://host:port` - remote database (LanceDB cloud)
12
+ * @param {string} uri - The uri of the database. If the database uri starts
13
+ * with `db://` then it connects to a remote database.
14
+ * @see {@link ConnectionOptions} for more details on the URI format.
15
+ */
16
+ export declare function connect(uri: string, opts?: Partial<ConnectionOptions>): Promise<Connection>;
4
17
  export interface CreateTableOptions {
5
18
  /**
6
19
  * The mode to use when creating the table.
@@ -17,6 +30,38 @@ export interface CreateTableOptions {
17
30
  * then no error will be raised.
18
31
  */
19
32
  existOk: boolean;
33
+ /**
34
+ * Configuration for object storage.
35
+ *
36
+ * Options already set on the connection will be inherited by the table,
37
+ * but can be overridden here.
38
+ *
39
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
40
+ */
41
+ storageOptions?: Record<string, string>;
42
+ }
43
+ export interface OpenTableOptions {
44
+ /**
45
+ * Configuration for object storage.
46
+ *
47
+ * Options already set on the connection will be inherited by the table,
48
+ * but can be overridden here.
49
+ *
50
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
51
+ */
52
+ storageOptions?: Record<string, string>;
53
+ /**
54
+ * Set the size of the index cache, specified as a number of entries
55
+ *
56
+ * The exact meaning of an "entry" will depend on the type of index:
57
+ * - IVF: there is one entry for each IVF partition
58
+ * - BTREE: there is one entry for the entire index
59
+ *
60
+ * This cache applies to the entire opened table, across all indices.
61
+ * Setting this value higher will increase performance on larger datasets
62
+ * at the expense of more RAM
63
+ */
64
+ indexCacheSize?: number;
20
65
  }
21
66
  export interface TableNamesOptions {
22
67
  /**
@@ -75,7 +120,7 @@ export declare class Connection {
75
120
  * Open a table in the database.
76
121
  * @param {string} name - The name of the table
77
122
  */
78
- openTable(name: string): Promise<Table>;
123
+ openTable(name: string, options?: Partial<OpenTableOptions>): Promise<Table>;
79
124
  /**
80
125
  * Creates a new Table and initialize it with new data.
81
126
  * @param {string} name - The name of the table.
@@ -13,10 +13,30 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Connection = void 0;
16
+ exports.Connection = exports.connect = void 0;
17
17
  const arrow_1 = require("./arrow");
18
+ const native_1 = require("./native");
18
19
  const table_1 = require("./table");
19
20
  const apache_arrow_1 = require("apache-arrow");
21
+ /**
22
+ * Connect to a LanceDB instance at the given URI.
23
+ *
24
+ * Accepted formats:
25
+ *
26
+ * - `/path/to/database` - local database
27
+ * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
28
+ * - `db://host:port` - remote database (LanceDB cloud)
29
+ * @param {string} uri - The uri of the database. If the database uri starts
30
+ * with `db://` then it connects to a remote database.
31
+ * @see {@link ConnectionOptions} for more details on the URI format.
32
+ */
33
+ async function connect(uri, opts) {
34
+ opts = opts ?? {};
35
+ opts.storageOptions = cleanseStorageOptions(opts.storageOptions);
36
+ const nativeConn = await native_1.Connection.new(uri, opts);
37
+ return new Connection(nativeConn);
38
+ }
39
+ exports.connect = connect;
20
40
  /**
21
41
  * A LanceDB Connection that allows you to open tables and create new ones.
22
42
  *
@@ -72,8 +92,8 @@ class Connection {
72
92
  * Open a table in the database.
73
93
  * @param {string} name - The name of the table
74
94
  */
75
- async openTable(name) {
76
- const innerTable = await this.inner.openTable(name);
95
+ async openTable(name, options) {
96
+ const innerTable = await this.inner.openTable(name, cleanseStorageOptions(options?.storageOptions), options?.indexCacheSize);
77
97
  return new table_1.Table(innerTable);
78
98
  }
79
99
  /**
@@ -96,7 +116,7 @@ class Connection {
96
116
  table = (0, arrow_1.makeArrowTable)(data);
97
117
  }
98
118
  const buf = await (0, arrow_1.fromTableToBuffer)(table);
99
- const innerTable = await this.inner.createTable(name, buf, mode);
119
+ const innerTable = await this.inner.createTable(name, buf, mode, cleanseStorageOptions(options?.storageOptions));
100
120
  return new table_1.Table(innerTable);
101
121
  }
102
122
  /**
@@ -112,7 +132,7 @@ class Connection {
112
132
  }
113
133
  const table = (0, arrow_1.makeEmptyTable)(schema);
114
134
  const buf = await (0, arrow_1.fromTableToBuffer)(table);
115
- const innerTable = await this.inner.createEmptyTable(name, buf, mode);
135
+ const innerTable = await this.inner.createEmptyTable(name, buf, mode, cleanseStorageOptions(options?.storageOptions));
116
136
  return new table_1.Table(innerTable);
117
137
  }
118
138
  /**
@@ -124,3 +144,38 @@ class Connection {
124
144
  }
125
145
  }
126
146
  exports.Connection = Connection;
147
+ /**
148
+ * Takes storage options and makes all the keys snake case.
149
+ */
150
+ function cleanseStorageOptions(options) {
151
+ if (options === undefined) {
152
+ return undefined;
153
+ }
154
+ const result = {};
155
+ for (const [key, value] of Object.entries(options)) {
156
+ if (value !== undefined) {
157
+ const newKey = camelToSnakeCase(key);
158
+ result[newKey] = value;
159
+ }
160
+ }
161
+ return result;
162
+ }
163
+ /**
164
+ * Convert a string to snake case. It might already be snake case, in which case it is
165
+ * returned unchanged.
166
+ */
167
+ function camelToSnakeCase(camel) {
168
+ if (camel.includes("_")) {
169
+ // Assume if there is at least one underscore, it is already snake case
170
+ return camel;
171
+ }
172
+ if (camel.toLocaleUpperCase() === camel) {
173
+ // Assume if the string is all uppercase, it is already snake case
174
+ return camel;
175
+ }
176
+ let result = camel.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
177
+ if (result.startsWith("_")) {
178
+ result = result.slice(1);
179
+ }
180
+ return result;
181
+ }
package/dist/index.d.ts CHANGED
@@ -1,22 +1,7 @@
1
- import { Connection } from "./connection";
2
- import { ConnectionOptions } from "./native.js";
3
1
  export { WriteOptions, WriteMode, AddColumnsSql, ColumnAlteration, ConnectionOptions, } from "./native.js";
4
2
  export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
5
- export { Connection, CreateTableOptions, TableNamesOptions, } from "./connection";
3
+ export { connect, Connection, CreateTableOptions, TableNamesOptions, } from "./connection";
6
4
  export { ExecutableQuery, Query, QueryBase, VectorQuery, RecordBatchIterator, } from "./query";
7
5
  export { Index, IndexOptions, IvfPqOptions } from "./indices";
8
6
  export { Table, AddDataOptions, IndexConfig, UpdateOptions } from "./table";
9
7
  export * as embedding from "./embedding";
10
- /**
11
- * Connect to a LanceDB instance at the given URI.
12
- *
13
- * Accpeted formats:
14
- *
15
- * - `/path/to/database` - local database
16
- * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
17
- * - `db://host:port` - remote database (LanceDB cloud)
18
- * @param {string} uri - The uri of the database. If the database uri starts
19
- * with `db://` then it connects to a remote database.
20
- * @see {@link ConnectionOptions} for more details on the URI format.
21
- */
22
- export declare function connect(uri: string, opts?: Partial<ConnectionOptions>): Promise<Connection>;
package/dist/index.js CHANGED
@@ -13,15 +13,14 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.connect = exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = void 0;
17
- const connection_1 = require("./connection");
18
- const native_js_1 = require("./native.js");
16
+ exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.connect = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = void 0;
19
17
  var arrow_1 = require("./arrow");
20
18
  Object.defineProperty(exports, "makeArrowTable", { enumerable: true, get: function () { return arrow_1.makeArrowTable; } });
21
19
  Object.defineProperty(exports, "MakeArrowTableOptions", { enumerable: true, get: function () { return arrow_1.MakeArrowTableOptions; } });
22
20
  Object.defineProperty(exports, "VectorColumnOptions", { enumerable: true, get: function () { return arrow_1.VectorColumnOptions; } });
23
- var connection_2 = require("./connection");
24
- Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_2.Connection; } });
21
+ var connection_1 = require("./connection");
22
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connection_1.connect; } });
23
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
25
24
  var query_1 = require("./query");
26
25
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
27
26
  Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
@@ -32,21 +31,3 @@ Object.defineProperty(exports, "Index", { enumerable: true, get: function () { r
32
31
  var table_1 = require("./table");
33
32
  Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
34
33
  exports.embedding = require("./embedding");
35
- /**
36
- * Connect to a LanceDB instance at the given URI.
37
- *
38
- * Accpeted formats:
39
- *
40
- * - `/path/to/database` - local database
41
- * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
42
- * - `db://host:port` - remote database (LanceDB cloud)
43
- * @param {string} uri - The uri of the database. If the database uri starts
44
- * with `db://` then it connects to a remote database.
45
- * @see {@link ConnectionOptions} for more details on the URI format.
46
- */
47
- async function connect(uri, opts) {
48
- opts = opts ?? {};
49
- const nativeConn = await native_js_1.Connection.new(uri, opts);
50
- return new connection_1.Connection(nativeConn);
51
- }
52
- exports.connect = connect;
package/dist/native.d.ts CHANGED
@@ -62,6 +62,12 @@ export interface ConnectionOptions {
62
62
  * always consistent.
63
63
  */
64
64
  readConsistencyInterval?: number
65
+ /**
66
+ * (For LanceDB OSS only): configuration for object storage.
67
+ *
68
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
69
+ */
70
+ storageOptions?: Record<string, string>
65
71
  }
66
72
  /** Write mode for writing a table. */
67
73
  export const enum WriteMode {
@@ -73,7 +79,9 @@ export const enum WriteMode {
73
79
  export interface WriteOptions {
74
80
  mode?: WriteMode
75
81
  }
76
- export function connect(uri: string, options: ConnectionOptions): Promise<Connection>
82
+ export interface OpenTableOptions {
83
+ storageOptions?: Record<string, string>
84
+ }
77
85
  export class Connection {
78
86
  /** Create a new Connection instance from the given URI. */
79
87
  static new(uri: string, options: ConnectionOptions): Promise<Connection>
@@ -90,9 +98,9 @@ export class Connection {
90
98
  * - buf: The buffer containing the IPC file.
91
99
  *
92
100
  */
93
- createTable(name: string, buf: Buffer, mode: string): Promise<Table>
94
- createEmptyTable(name: string, schemaBuf: Buffer, mode: string): Promise<Table>
95
- openTable(name: string): Promise<Table>
101
+ createTable(name: string, buf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
102
+ createEmptyTable(name: string, schemaBuf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
103
+ openTable(name: string, storageOptions?: Record<string, string> | undefined | null, indexCacheSize?: number | undefined | null): Promise<Table>
96
104
  /** Drop table with the name. Or raise an error if the table does not exist. */
97
105
  dropTable(name: string): Promise<void>
98
106
  }
package/dist/native.js CHANGED
@@ -303,7 +303,7 @@ if (!nativeBinding) {
303
303
  }
304
304
  throw new Error(`Failed to load native binding`);
305
305
  }
306
- const { Connection, Index, RecordBatchIterator, Query, VectorQuery, Table, WriteMode, connect } = nativeBinding;
306
+ const { Connection, Index, RecordBatchIterator, Query, VectorQuery, Table, WriteMode } = nativeBinding;
307
307
  module.exports.Connection = Connection;
308
308
  module.exports.Index = Index;
309
309
  module.exports.RecordBatchIterator = RecordBatchIterator;
@@ -311,4 +311,3 @@ module.exports.Query = Query;
311
311
  module.exports.VectorQuery = VectorQuery;
312
312
  module.exports.Table = Table;
313
313
  module.exports.WriteMode = WriteMode;
314
- module.exports.connect = connect;
@@ -13,10 +13,32 @@
13
13
  // limitations under the License.
14
14
 
15
15
  import { fromTableToBuffer, makeArrowTable, makeEmptyTable } from "./arrow";
16
- import { Connection as LanceDbConnection } from "./native";
16
+ import { ConnectionOptions, Connection as LanceDbConnection } from "./native";
17
17
  import { Table } from "./table";
18
18
  import { Table as ArrowTable, Schema } from "apache-arrow";
19
19
 
20
+ /**
21
+ * Connect to a LanceDB instance at the given URI.
22
+ *
23
+ * Accepted formats:
24
+ *
25
+ * - `/path/to/database` - local database
26
+ * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
27
+ * - `db://host:port` - remote database (LanceDB cloud)
28
+ * @param {string} uri - The uri of the database. If the database uri starts
29
+ * with `db://` then it connects to a remote database.
30
+ * @see {@link ConnectionOptions} for more details on the URI format.
31
+ */
32
+ export async function connect(
33
+ uri: string,
34
+ opts?: Partial<ConnectionOptions>,
35
+ ): Promise<Connection> {
36
+ opts = opts ?? {};
37
+ opts.storageOptions = cleanseStorageOptions(opts.storageOptions);
38
+ const nativeConn = await LanceDbConnection.new(uri, opts);
39
+ return new Connection(nativeConn);
40
+ }
41
+
20
42
  export interface CreateTableOptions {
21
43
  /**
22
44
  * The mode to use when creating the table.
@@ -33,6 +55,40 @@ export interface CreateTableOptions {
33
55
  * then no error will be raised.
34
56
  */
35
57
  existOk: boolean;
58
+
59
+ /**
60
+ * Configuration for object storage.
61
+ *
62
+ * Options already set on the connection will be inherited by the table,
63
+ * but can be overridden here.
64
+ *
65
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
66
+ */
67
+ storageOptions?: Record<string, string>;
68
+ }
69
+
70
+ export interface OpenTableOptions {
71
+ /**
72
+ * Configuration for object storage.
73
+ *
74
+ * Options already set on the connection will be inherited by the table,
75
+ * but can be overridden here.
76
+ *
77
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
78
+ */
79
+ storageOptions?: Record<string, string>;
80
+ /**
81
+ * Set the size of the index cache, specified as a number of entries
82
+ *
83
+ * The exact meaning of an "entry" will depend on the type of index:
84
+ * - IVF: there is one entry for each IVF partition
85
+ * - BTREE: there is one entry for the entire index
86
+ *
87
+ * This cache applies to the entire opened table, across all indices.
88
+ * Setting this value higher will increase performance on larger datasets
89
+ * at the expense of more RAM
90
+ */
91
+ indexCacheSize?: number;
36
92
  }
37
93
 
38
94
  export interface TableNamesOptions {
@@ -109,8 +165,15 @@ export class Connection {
109
165
  * Open a table in the database.
110
166
  * @param {string} name - The name of the table
111
167
  */
112
- async openTable(name: string): Promise<Table> {
113
- const innerTable = await this.inner.openTable(name);
168
+ async openTable(
169
+ name: string,
170
+ options?: Partial<OpenTableOptions>,
171
+ ): Promise<Table> {
172
+ const innerTable = await this.inner.openTable(
173
+ name,
174
+ cleanseStorageOptions(options?.storageOptions),
175
+ options?.indexCacheSize,
176
+ );
114
177
  return new Table(innerTable);
115
178
  }
116
179
 
@@ -139,7 +202,12 @@ export class Connection {
139
202
  table = makeArrowTable(data);
140
203
  }
141
204
  const buf = await fromTableToBuffer(table);
142
- const innerTable = await this.inner.createTable(name, buf, mode);
205
+ const innerTable = await this.inner.createTable(
206
+ name,
207
+ buf,
208
+ mode,
209
+ cleanseStorageOptions(options?.storageOptions),
210
+ );
143
211
  return new Table(innerTable);
144
212
  }
145
213
 
@@ -162,7 +230,12 @@ export class Connection {
162
230
 
163
231
  const table = makeEmptyTable(schema);
164
232
  const buf = await fromTableToBuffer(table);
165
- const innerTable = await this.inner.createEmptyTable(name, buf, mode);
233
+ const innerTable = await this.inner.createEmptyTable(
234
+ name,
235
+ buf,
236
+ mode,
237
+ cleanseStorageOptions(options?.storageOptions),
238
+ );
166
239
  return new Table(innerTable);
167
240
  }
168
241
 
@@ -174,3 +247,43 @@ export class Connection {
174
247
  return this.inner.dropTable(name);
175
248
  }
176
249
  }
250
+
251
+ /**
252
+ * Takes storage options and makes all the keys snake case.
253
+ */
254
+ function cleanseStorageOptions(
255
+ options?: Record<string, string>,
256
+ ): Record<string, string> | undefined {
257
+ if (options === undefined) {
258
+ return undefined;
259
+ }
260
+ const result: Record<string, string> = {};
261
+ for (const [key, value] of Object.entries(options)) {
262
+ if (value !== undefined) {
263
+ const newKey = camelToSnakeCase(key);
264
+ result[newKey] = value;
265
+ }
266
+ }
267
+ return result;
268
+ }
269
+
270
+ /**
271
+ * Convert a string to snake case. It might already be snake case, in which case it is
272
+ * returned unchanged.
273
+ */
274
+ function camelToSnakeCase(camel: string): string {
275
+ if (camel.includes("_")) {
276
+ // Assume if there is at least one underscore, it is already snake case
277
+ return camel;
278
+ }
279
+ if (camel.toLocaleUpperCase() === camel) {
280
+ // Assume if the string is all uppercase, it is already snake case
281
+ return camel;
282
+ }
283
+
284
+ let result = camel.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
285
+ if (result.startsWith("_")) {
286
+ result = result.slice(1);
287
+ }
288
+ return result;
289
+ }
package/lancedb/index.ts CHANGED
@@ -12,12 +12,6 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- import { Connection } from "./connection";
16
- import {
17
- Connection as LanceDbConnection,
18
- ConnectionOptions,
19
- } from "./native.js";
20
-
21
15
  export {
22
16
  WriteOptions,
23
17
  WriteMode,
@@ -32,6 +26,7 @@ export {
32
26
  VectorColumnOptions,
33
27
  } from "./arrow";
34
28
  export {
29
+ connect,
35
30
  Connection,
36
31
  CreateTableOptions,
37
32
  TableNamesOptions,
@@ -46,24 +41,3 @@ export {
46
41
  export { Index, IndexOptions, IvfPqOptions } from "./indices";
47
42
  export { Table, AddDataOptions, IndexConfig, UpdateOptions } from "./table";
48
43
  export * as embedding from "./embedding";
49
-
50
- /**
51
- * Connect to a LanceDB instance at the given URI.
52
- *
53
- * Accpeted formats:
54
- *
55
- * - `/path/to/database` - local database
56
- * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
57
- * - `db://host:port` - remote database (LanceDB cloud)
58
- * @param {string} uri - The uri of the database. If the database uri starts
59
- * with `db://` then it connects to a remote database.
60
- * @see {@link ConnectionOptions} for more details on the URI format.
61
- */
62
- export async function connect(
63
- uri: string,
64
- opts?: Partial<ConnectionOptions>,
65
- ): Promise<Connection> {
66
- opts = opts ?? {};
67
- const nativeConn = await LanceDbConnection.new(uri, opts);
68
- return new Connection(nativeConn);
69
- }
@@ -1,6 +1,19 @@
1
- import { Connection as LanceDbConnection } from "./native";
1
+ import { ConnectionOptions, Connection as LanceDbConnection } from "./native";
2
2
  import { Table } from "./table";
3
3
  import { Table as ArrowTable, Schema } from "apache-arrow";
4
+ /**
5
+ * Connect to a LanceDB instance at the given URI.
6
+ *
7
+ * Accepted formats:
8
+ *
9
+ * - `/path/to/database` - local database
10
+ * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
11
+ * - `db://host:port` - remote database (LanceDB cloud)
12
+ * @param {string} uri - The uri of the database. If the database uri starts
13
+ * with `db://` then it connects to a remote database.
14
+ * @see {@link ConnectionOptions} for more details on the URI format.
15
+ */
16
+ export declare function connect(uri: string, opts?: Partial<ConnectionOptions>): Promise<Connection>;
4
17
  export interface CreateTableOptions {
5
18
  /**
6
19
  * The mode to use when creating the table.
@@ -17,6 +30,38 @@ export interface CreateTableOptions {
17
30
  * then no error will be raised.
18
31
  */
19
32
  existOk: boolean;
33
+ /**
34
+ * Configuration for object storage.
35
+ *
36
+ * Options already set on the connection will be inherited by the table,
37
+ * but can be overridden here.
38
+ *
39
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
40
+ */
41
+ storageOptions?: Record<string, string>;
42
+ }
43
+ export interface OpenTableOptions {
44
+ /**
45
+ * Configuration for object storage.
46
+ *
47
+ * Options already set on the connection will be inherited by the table,
48
+ * but can be overridden here.
49
+ *
50
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
51
+ */
52
+ storageOptions?: Record<string, string>;
53
+ /**
54
+ * Set the size of the index cache, specified as a number of entries
55
+ *
56
+ * The exact meaning of an "entry" will depend on the type of index:
57
+ * - IVF: there is one entry for each IVF partition
58
+ * - BTREE: there is one entry for the entire index
59
+ *
60
+ * This cache applies to the entire opened table, across all indices.
61
+ * Setting this value higher will increase performance on larger datasets
62
+ * at the expense of more RAM
63
+ */
64
+ indexCacheSize?: number;
20
65
  }
21
66
  export interface TableNamesOptions {
22
67
  /**
@@ -75,7 +120,7 @@ export declare class Connection {
75
120
  * Open a table in the database.
76
121
  * @param {string} name - The name of the table
77
122
  */
78
- openTable(name: string): Promise<Table>;
123
+ openTable(name: string, options?: Partial<OpenTableOptions>): Promise<Table>;
79
124
  /**
80
125
  * Creates a new Table and initialize it with new data.
81
126
  * @param {string} name - The name of the table.
@@ -13,10 +13,30 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Connection = void 0;
16
+ exports.Connection = exports.connect = void 0;
17
17
  const arrow_1 = require("./arrow");
18
+ const native_1 = require("./native");
18
19
  const table_1 = require("./table");
19
20
  const apache_arrow_1 = require("apache-arrow");
21
+ /**
22
+ * Connect to a LanceDB instance at the given URI.
23
+ *
24
+ * Accepted formats:
25
+ *
26
+ * - `/path/to/database` - local database
27
+ * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
28
+ * - `db://host:port` - remote database (LanceDB cloud)
29
+ * @param {string} uri - The uri of the database. If the database uri starts
30
+ * with `db://` then it connects to a remote database.
31
+ * @see {@link ConnectionOptions} for more details on the URI format.
32
+ */
33
+ async function connect(uri, opts) {
34
+ opts = opts ?? {};
35
+ opts.storageOptions = cleanseStorageOptions(opts.storageOptions);
36
+ const nativeConn = await native_1.Connection.new(uri, opts);
37
+ return new Connection(nativeConn);
38
+ }
39
+ exports.connect = connect;
20
40
  /**
21
41
  * A LanceDB Connection that allows you to open tables and create new ones.
22
42
  *
@@ -72,8 +92,8 @@ class Connection {
72
92
  * Open a table in the database.
73
93
  * @param {string} name - The name of the table
74
94
  */
75
- async openTable(name) {
76
- const innerTable = await this.inner.openTable(name);
95
+ async openTable(name, options) {
96
+ const innerTable = await this.inner.openTable(name, cleanseStorageOptions(options?.storageOptions), options?.indexCacheSize);
77
97
  return new table_1.Table(innerTable);
78
98
  }
79
99
  /**
@@ -96,7 +116,7 @@ class Connection {
96
116
  table = (0, arrow_1.makeArrowTable)(data);
97
117
  }
98
118
  const buf = await (0, arrow_1.fromTableToBuffer)(table);
99
- const innerTable = await this.inner.createTable(name, buf, mode);
119
+ const innerTable = await this.inner.createTable(name, buf, mode, cleanseStorageOptions(options?.storageOptions));
100
120
  return new table_1.Table(innerTable);
101
121
  }
102
122
  /**
@@ -112,7 +132,7 @@ class Connection {
112
132
  }
113
133
  const table = (0, arrow_1.makeEmptyTable)(schema);
114
134
  const buf = await (0, arrow_1.fromTableToBuffer)(table);
115
- const innerTable = await this.inner.createEmptyTable(name, buf, mode);
135
+ const innerTable = await this.inner.createEmptyTable(name, buf, mode, cleanseStorageOptions(options?.storageOptions));
116
136
  return new table_1.Table(innerTable);
117
137
  }
118
138
  /**
@@ -124,3 +144,38 @@ class Connection {
124
144
  }
125
145
  }
126
146
  exports.Connection = Connection;
147
+ /**
148
+ * Takes storage options and makes all the keys snake case.
149
+ */
150
+ function cleanseStorageOptions(options) {
151
+ if (options === undefined) {
152
+ return undefined;
153
+ }
154
+ const result = {};
155
+ for (const [key, value] of Object.entries(options)) {
156
+ if (value !== undefined) {
157
+ const newKey = camelToSnakeCase(key);
158
+ result[newKey] = value;
159
+ }
160
+ }
161
+ return result;
162
+ }
163
+ /**
164
+ * Convert a string to snake case. It might already be snake case, in which case it is
165
+ * returned unchanged.
166
+ */
167
+ function camelToSnakeCase(camel) {
168
+ if (camel.includes("_")) {
169
+ // Assume if there is at least one underscore, it is already snake case
170
+ return camel;
171
+ }
172
+ if (camel.toLocaleUpperCase() === camel) {
173
+ // Assume if the string is all uppercase, it is already snake case
174
+ return camel;
175
+ }
176
+ let result = camel.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
177
+ if (result.startsWith("_")) {
178
+ result = result.slice(1);
179
+ }
180
+ return result;
181
+ }
@@ -1,22 +1,7 @@
1
- import { Connection } from "./connection";
2
- import { ConnectionOptions } from "./native.js";
3
1
  export { WriteOptions, WriteMode, AddColumnsSql, ColumnAlteration, ConnectionOptions, } from "./native.js";
4
2
  export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
5
- export { Connection, CreateTableOptions, TableNamesOptions, } from "./connection";
3
+ export { connect, Connection, CreateTableOptions, TableNamesOptions, } from "./connection";
6
4
  export { ExecutableQuery, Query, QueryBase, VectorQuery, RecordBatchIterator, } from "./query";
7
5
  export { Index, IndexOptions, IvfPqOptions } from "./indices";
8
6
  export { Table, AddDataOptions, IndexConfig, UpdateOptions } from "./table";
9
7
  export * as embedding from "./embedding";
10
- /**
11
- * Connect to a LanceDB instance at the given URI.
12
- *
13
- * Accpeted formats:
14
- *
15
- * - `/path/to/database` - local database
16
- * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
17
- * - `db://host:port` - remote database (LanceDB cloud)
18
- * @param {string} uri - The uri of the database. If the database uri starts
19
- * with `db://` then it connects to a remote database.
20
- * @see {@link ConnectionOptions} for more details on the URI format.
21
- */
22
- export declare function connect(uri: string, opts?: Partial<ConnectionOptions>): Promise<Connection>;
@@ -13,15 +13,14 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.connect = exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = void 0;
17
- const connection_1 = require("./connection");
18
- const native_js_1 = require("./native.js");
16
+ exports.embedding = exports.Table = exports.Index = exports.RecordBatchIterator = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Connection = exports.connect = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = void 0;
19
17
  var arrow_1 = require("./arrow");
20
18
  Object.defineProperty(exports, "makeArrowTable", { enumerable: true, get: function () { return arrow_1.makeArrowTable; } });
21
19
  Object.defineProperty(exports, "MakeArrowTableOptions", { enumerable: true, get: function () { return arrow_1.MakeArrowTableOptions; } });
22
20
  Object.defineProperty(exports, "VectorColumnOptions", { enumerable: true, get: function () { return arrow_1.VectorColumnOptions; } });
23
- var connection_2 = require("./connection");
24
- Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_2.Connection; } });
21
+ var connection_1 = require("./connection");
22
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connection_1.connect; } });
23
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
25
24
  var query_1 = require("./query");
26
25
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
27
26
  Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
@@ -32,21 +31,3 @@ Object.defineProperty(exports, "Index", { enumerable: true, get: function () { r
32
31
  var table_1 = require("./table");
33
32
  Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
34
33
  exports.embedding = require("./embedding");
35
- /**
36
- * Connect to a LanceDB instance at the given URI.
37
- *
38
- * Accpeted formats:
39
- *
40
- * - `/path/to/database` - local database
41
- * - `s3://bucket/path/to/database` or `gs://bucket/path/to/database` - database on cloud storage
42
- * - `db://host:port` - remote database (LanceDB cloud)
43
- * @param {string} uri - The uri of the database. If the database uri starts
44
- * with `db://` then it connects to a remote database.
45
- * @see {@link ConnectionOptions} for more details on the URI format.
46
- */
47
- async function connect(uri, opts) {
48
- opts = opts ?? {};
49
- const nativeConn = await native_js_1.Connection.new(uri, opts);
50
- return new connection_1.Connection(nativeConn);
51
- }
52
- exports.connect = connect;
@@ -62,6 +62,12 @@ export interface ConnectionOptions {
62
62
  * always consistent.
63
63
  */
64
64
  readConsistencyInterval?: number
65
+ /**
66
+ * (For LanceDB OSS only): configuration for object storage.
67
+ *
68
+ * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
69
+ */
70
+ storageOptions?: Record<string, string>
65
71
  }
66
72
  /** Write mode for writing a table. */
67
73
  export const enum WriteMode {
@@ -73,7 +79,9 @@ export const enum WriteMode {
73
79
  export interface WriteOptions {
74
80
  mode?: WriteMode
75
81
  }
76
- export function connect(uri: string, options: ConnectionOptions): Promise<Connection>
82
+ export interface OpenTableOptions {
83
+ storageOptions?: Record<string, string>
84
+ }
77
85
  export class Connection {
78
86
  /** Create a new Connection instance from the given URI. */
79
87
  static new(uri: string, options: ConnectionOptions): Promise<Connection>
@@ -90,9 +98,9 @@ export class Connection {
90
98
  * - buf: The buffer containing the IPC file.
91
99
  *
92
100
  */
93
- createTable(name: string, buf: Buffer, mode: string): Promise<Table>
94
- createEmptyTable(name: string, schemaBuf: Buffer, mode: string): Promise<Table>
95
- openTable(name: string): Promise<Table>
101
+ createTable(name: string, buf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
102
+ createEmptyTable(name: string, schemaBuf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
103
+ openTable(name: string, storageOptions?: Record<string, string> | undefined | null, indexCacheSize?: number | undefined | null): Promise<Table>
96
104
  /** Drop table with the name. Or raise an error if the table does not exist. */
97
105
  dropTable(name: string): Promise<void>
98
106
  }
@@ -303,7 +303,7 @@ if (!nativeBinding) {
303
303
  }
304
304
  throw new Error(`Failed to load native binding`);
305
305
  }
306
- const { Connection, Index, RecordBatchIterator, Query, VectorQuery, Table, WriteMode, connect } = nativeBinding;
306
+ const { Connection, Index, RecordBatchIterator, Query, VectorQuery, Table, WriteMode } = nativeBinding;
307
307
  module.exports.Connection = Connection;
308
308
  module.exports.Index = Index;
309
309
  module.exports.RecordBatchIterator = RecordBatchIterator;
@@ -311,4 +311,3 @@ module.exports.Query = Query;
311
311
  module.exports.VectorQuery = VectorQuery;
312
312
  module.exports.Table = Table;
313
313
  module.exports.WriteMode = WriteMode;
314
- module.exports.connect = connect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancedb/lancedb",
3
- "version": "0.4.15",
3
+ "version": "0.4.18",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "napi": {
@@ -18,6 +18,8 @@
18
18
  },
19
19
  "license": "Apache 2.0",
20
20
  "devDependencies": {
21
+ "@aws-sdk/client-s3": "^3.33.0",
22
+ "@aws-sdk/client-kms": "^3.33.0",
21
23
  "@napi-rs/cli": "^2.18.0",
22
24
  "@types/jest": "^29.1.2",
23
25
  "@types/tmp": "^0.2.6",
@@ -63,18 +65,19 @@
63
65
  "lint": "eslint lancedb && eslint __test__",
64
66
  "prepublishOnly": "napi prepublish -t npm",
65
67
  "test": "npm run build && jest --verbose",
68
+ "integration": "S3_TEST=1 npm run test",
66
69
  "universal": "napi universal",
67
70
  "version": "napi version"
68
71
  },
69
- "optionalDependencies": {
70
- "@lancedb/lancedb-darwin-arm64": "0.4.15",
71
- "@lancedb/lancedb-linux-arm64-gnu": "0.4.15",
72
- "@lancedb/lancedb-darwin-x64": "0.4.15",
73
- "@lancedb/lancedb-linux-x64-gnu": "0.4.15",
74
- "@lancedb/lancedb-win32-x64-msvc": "0.4.15"
75
- },
76
72
  "dependencies": {
77
73
  "openai": "^4.29.2",
78
74
  "apache-arrow": "^15.0.0"
75
+ },
76
+ "optionalDependencies": {
77
+ "@lancedb/lancedb-darwin-arm64": "0.4.18",
78
+ "@lancedb/lancedb-linux-arm64-gnu": "0.4.18",
79
+ "@lancedb/lancedb-darwin-x64": "0.4.18",
80
+ "@lancedb/lancedb-linux-x64-gnu": "0.4.18",
81
+ "@lancedb/lancedb-win32-x64-msvc": "0.4.18"
79
82
  }
80
83
  }