@dengxifeng/lancedb 0.26.2

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.
Files changed (43) hide show
  1. package/AGENTS.md +13 -0
  2. package/CONTRIBUTING.md +76 -0
  3. package/README.md +37 -0
  4. package/dist/arrow.d.ts +279 -0
  5. package/dist/arrow.js +1316 -0
  6. package/dist/connection.d.ts +259 -0
  7. package/dist/connection.js +224 -0
  8. package/dist/embedding/embedding_function.d.ts +103 -0
  9. package/dist/embedding/embedding_function.js +192 -0
  10. package/dist/embedding/index.d.ts +27 -0
  11. package/dist/embedding/index.js +101 -0
  12. package/dist/embedding/openai.d.ts +16 -0
  13. package/dist/embedding/openai.js +93 -0
  14. package/dist/embedding/registry.d.ts +74 -0
  15. package/dist/embedding/registry.js +165 -0
  16. package/dist/embedding/transformers.d.ts +36 -0
  17. package/dist/embedding/transformers.js +122 -0
  18. package/dist/header.d.ts +162 -0
  19. package/dist/header.js +217 -0
  20. package/dist/index.d.ts +85 -0
  21. package/dist/index.js +106 -0
  22. package/dist/indices.d.ts +692 -0
  23. package/dist/indices.js +156 -0
  24. package/dist/merge.d.ts +80 -0
  25. package/dist/merge.js +92 -0
  26. package/dist/native.d.ts +585 -0
  27. package/dist/native.js +339 -0
  28. package/dist/permutation.d.ts +143 -0
  29. package/dist/permutation.js +184 -0
  30. package/dist/query.d.ts +581 -0
  31. package/dist/query.js +853 -0
  32. package/dist/rerankers/index.d.ts +5 -0
  33. package/dist/rerankers/index.js +19 -0
  34. package/dist/rerankers/rrf.d.ts +14 -0
  35. package/dist/rerankers/rrf.js +28 -0
  36. package/dist/sanitize.d.ts +32 -0
  37. package/dist/sanitize.js +473 -0
  38. package/dist/table.d.ts +581 -0
  39. package/dist/table.js +321 -0
  40. package/dist/util.d.ts +14 -0
  41. package/dist/util.js +77 -0
  42. package/license_header.txt +2 -0
  43. package/package.json +122 -0
@@ -0,0 +1,259 @@
1
+ import { Data, SchemaLike, TableLike } from "./arrow";
2
+ import { EmbeddingFunctionConfig } from "./embedding/registry";
3
+ import { Connection as LanceDbConnection } from "./native";
4
+ import { Table } from "./table";
5
+ export interface CreateTableOptions {
6
+ /**
7
+ * The mode to use when creating the table.
8
+ *
9
+ * If this is set to "create" and the table already exists then either
10
+ * an error will be thrown or, if existOk is true, then nothing will
11
+ * happen. Any provided data will be ignored.
12
+ *
13
+ * If this is set to "overwrite" then any existing table will be replaced.
14
+ */
15
+ mode: "create" | "overwrite";
16
+ /**
17
+ * If this is true and the table already exists and the mode is "create"
18
+ * then no error will be raised.
19
+ */
20
+ existOk: boolean;
21
+ /**
22
+ * Configuration for object storage.
23
+ *
24
+ * Options already set on the connection will be inherited by the table,
25
+ * but can be overridden here.
26
+ *
27
+ * The available options are described at https://lancedb.com/docs/storage/
28
+ */
29
+ storageOptions?: Record<string, string>;
30
+ /**
31
+ * The version of the data storage format to use.
32
+ *
33
+ * The default is `stable`.
34
+ * Set to "legacy" to use the old format.
35
+ *
36
+ * @deprecated Pass `new_table_data_storage_version` to storageOptions instead.
37
+ */
38
+ dataStorageVersion?: string;
39
+ /**
40
+ * Use the new V2 manifest paths. These paths provide more efficient
41
+ * opening of datasets with many versions on object stores. WARNING:
42
+ * turning this on will make the dataset unreadable for older versions
43
+ * of LanceDB (prior to 0.10.0). To migrate an existing dataset, instead
44
+ * use the {@link LocalTable#migrateManifestPathsV2} method.
45
+ *
46
+ * @deprecated Pass `new_table_enable_v2_manifest_paths` to storageOptions instead.
47
+ */
48
+ enableV2ManifestPaths?: boolean;
49
+ schema?: SchemaLike;
50
+ embeddingFunction?: EmbeddingFunctionConfig;
51
+ }
52
+ export interface OpenTableOptions {
53
+ /**
54
+ * Configuration for object storage.
55
+ *
56
+ * Options already set on the connection will be inherited by the table,
57
+ * but can be overridden here.
58
+ *
59
+ * The available options are described at https://lancedb.com/docs/storage/
60
+ */
61
+ storageOptions?: Record<string, string>;
62
+ /**
63
+ * Set the size of the index cache, specified as a number of entries
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
+ *
68
+ * The exact meaning of an "entry" will depend on the type of index:
69
+ * - IVF: there is one entry for each IVF partition
70
+ * - BTREE: there is one entry for the entire index
71
+ *
72
+ * This cache applies to the entire opened table, across all indices.
73
+ * Setting this value higher will increase performance on larger datasets
74
+ * at the expense of more RAM
75
+ */
76
+ indexCacheSize?: number;
77
+ }
78
+ export interface TableNamesOptions {
79
+ /**
80
+ * If present, only return names that come lexicographically after the
81
+ * supplied value.
82
+ *
83
+ * This can be combined with limit to implement pagination by setting this to
84
+ * the last table name from the previous page.
85
+ */
86
+ startAfter?: string;
87
+ /** An optional limit to the number of results to return. */
88
+ limit?: number;
89
+ }
90
+ /**
91
+ * A LanceDB Connection that allows you to open tables and create new ones.
92
+ *
93
+ * Connection could be local against filesystem or remote against a server.
94
+ *
95
+ * A Connection is intended to be a long lived object and may hold open
96
+ * resources such as HTTP connection pools. This is generally fine and
97
+ * a single connection should be shared if it is going to be used many
98
+ * times. However, if you are finished with a connection, you may call
99
+ * close to eagerly free these resources. Any call to a Connection
100
+ * method after it has been closed will result in an error.
101
+ *
102
+ * Closing a connection is optional. Connections will automatically
103
+ * be closed when they are garbage collected.
104
+ *
105
+ * Any created tables are independent and will continue to work even if
106
+ * the underlying connection has been closed.
107
+ * @hideconstructor
108
+ */
109
+ export declare abstract class Connection {
110
+ /**
111
+ * Return true if the connection has not been closed
112
+ */
113
+ abstract isOpen(): boolean;
114
+ /**
115
+ * Close the connection, releasing any underlying resources.
116
+ *
117
+ * It is safe to call this method multiple times.
118
+ *
119
+ * Any attempt to use the connection after it is closed will result in an error.
120
+ */
121
+ abstract close(): void;
122
+ /**
123
+ * Return a brief description of the connection
124
+ */
125
+ abstract display(): string;
126
+ /**
127
+ * List all the table names in this database.
128
+ *
129
+ * Tables will be returned in lexicographical order.
130
+ * @param {Partial<TableNamesOptions>} options - options to control the
131
+ * paging / start point (backwards compatibility)
132
+ *
133
+ */
134
+ abstract tableNames(options?: Partial<TableNamesOptions>): Promise<string[]>;
135
+ /**
136
+ * List all the table names in this database.
137
+ *
138
+ * Tables will be returned in lexicographical order.
139
+ * @param {string[]} namespace - The namespace to list tables from (defaults to root namespace)
140
+ * @param {Partial<TableNamesOptions>} options - options to control the
141
+ * paging / start point
142
+ *
143
+ */
144
+ abstract tableNames(namespace?: string[], options?: Partial<TableNamesOptions>): Promise<string[]>;
145
+ /**
146
+ * Open a table in the database.
147
+ * @param {string} name - The name of the table
148
+ * @param {string[]} namespace - The namespace of the table (defaults to root namespace)
149
+ * @param {Partial<OpenTableOptions>} options - Additional options
150
+ */
151
+ abstract openTable(name: string, namespace?: string[], options?: Partial<OpenTableOptions>): Promise<Table>;
152
+ /**
153
+ * Creates a new Table and initialize it with new data.
154
+ * @param {object} options - The options object.
155
+ * @param {string} options.name - The name of the table.
156
+ * @param {Data} options.data - Non-empty Array of Records to be inserted into the table
157
+ * @param {string[]} namespace - The namespace to create the table in (defaults to root namespace)
158
+ *
159
+ */
160
+ abstract createTable(options: {
161
+ name: string;
162
+ data: Data;
163
+ } & Partial<CreateTableOptions>, namespace?: string[]): Promise<Table>;
164
+ /**
165
+ * Creates a new Table and initialize it with new data.
166
+ * @param {string} name - The name of the table.
167
+ * @param {Record<string, unknown>[] | TableLike} data - Non-empty Array of Records
168
+ * to be inserted into the table
169
+ * @param {Partial<CreateTableOptions>} options - Additional options (backwards compatibility)
170
+ */
171
+ abstract createTable(name: string, data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>): Promise<Table>;
172
+ /**
173
+ * Creates a new Table and initialize it with new data.
174
+ * @param {string} name - The name of the table.
175
+ * @param {Record<string, unknown>[] | TableLike} data - Non-empty Array of Records
176
+ * to be inserted into the table
177
+ * @param {string[]} namespace - The namespace to create the table in (defaults to root namespace)
178
+ * @param {Partial<CreateTableOptions>} options - Additional options
179
+ */
180
+ abstract createTable(name: string, data: Record<string, unknown>[] | TableLike, namespace?: string[], options?: Partial<CreateTableOptions>): Promise<Table>;
181
+ /**
182
+ * Creates a new empty Table
183
+ * @param {string} name - The name of the table.
184
+ * @param {Schema} schema - The schema of the table
185
+ * @param {Partial<CreateTableOptions>} options - Additional options (backwards compatibility)
186
+ */
187
+ abstract createEmptyTable(name: string, schema: import("./arrow").SchemaLike, options?: Partial<CreateTableOptions>): Promise<Table>;
188
+ /**
189
+ * Creates a new empty Table
190
+ * @param {string} name - The name of the table.
191
+ * @param {Schema} schema - The schema of the table
192
+ * @param {string[]} namespace - The namespace to create the table in (defaults to root namespace)
193
+ * @param {Partial<CreateTableOptions>} options - Additional options
194
+ */
195
+ abstract createEmptyTable(name: string, schema: import("./arrow").SchemaLike, namespace?: string[], options?: Partial<CreateTableOptions>): Promise<Table>;
196
+ /**
197
+ * Drop an existing table.
198
+ * @param {string} name The name of the table to drop.
199
+ * @param {string[]} namespace The namespace of the table (defaults to root namespace).
200
+ */
201
+ abstract dropTable(name: string, namespace?: string[]): Promise<void>;
202
+ /**
203
+ * Drop all tables in the database.
204
+ * @param {string[]} namespace The namespace to drop tables from (defaults to root namespace).
205
+ */
206
+ abstract dropAllTables(namespace?: string[]): Promise<void>;
207
+ /**
208
+ * Clone a table from a source table.
209
+ *
210
+ * A shallow clone creates a new table that shares the underlying data files
211
+ * with the source table but has its own independent manifest. This allows
212
+ * both the source and cloned tables to evolve independently while initially
213
+ * sharing the same data, deletion, and index files.
214
+ *
215
+ * @param {string} targetTableName - The name of the target table to create.
216
+ * @param {string} sourceUri - The URI of the source table to clone from.
217
+ * @param {object} options - Clone options.
218
+ * @param {string[]} options.targetNamespace - The namespace for the target table (defaults to root namespace).
219
+ * @param {number} options.sourceVersion - The version of the source table to clone.
220
+ * @param {string} options.sourceTag - The tag of the source table to clone.
221
+ * @param {boolean} options.isShallow - Whether to perform a shallow clone (defaults to true).
222
+ */
223
+ abstract cloneTable(targetTableName: string, sourceUri: string, options?: {
224
+ targetNamespace?: string[];
225
+ sourceVersion?: number;
226
+ sourceTag?: string;
227
+ isShallow?: boolean;
228
+ }): Promise<Table>;
229
+ }
230
+ /** @hideconstructor */
231
+ export declare class LocalConnection extends Connection {
232
+ readonly inner: LanceDbConnection;
233
+ /** @hidden */
234
+ constructor(inner: LanceDbConnection);
235
+ isOpen(): boolean;
236
+ close(): void;
237
+ display(): string;
238
+ tableNames(namespaceOrOptions?: string[] | Partial<TableNamesOptions>, options?: Partial<TableNamesOptions>): Promise<string[]>;
239
+ openTable(name: string, namespace?: string[], options?: Partial<OpenTableOptions>): Promise<Table>;
240
+ cloneTable(targetTableName: string, sourceUri: string, options?: {
241
+ targetNamespace?: string[];
242
+ sourceVersion?: number;
243
+ sourceTag?: string;
244
+ isShallow?: boolean;
245
+ }): Promise<Table>;
246
+ private getStorageOptions;
247
+ createTable(nameOrOptions: string | ({
248
+ name: string;
249
+ data: Data;
250
+ } & Partial<CreateTableOptions>), dataOrNamespace?: Record<string, unknown>[] | TableLike | string[], namespaceOrOptions?: string[] | Partial<CreateTableOptions>, options?: Partial<CreateTableOptions>): Promise<Table>;
251
+ private _createTableImpl;
252
+ createEmptyTable(name: string, schema: import("./arrow").SchemaLike, namespaceOrOptions?: string[] | Partial<CreateTableOptions>, options?: Partial<CreateTableOptions>): Promise<Table>;
253
+ dropTable(name: string, namespace?: string[]): Promise<void>;
254
+ dropAllTables(namespace?: string[]): Promise<void>;
255
+ }
256
+ /**
257
+ * Takes storage options and makes all the keys snake case.
258
+ */
259
+ export declare function cleanseStorageOptions(options?: Record<string, string>): Record<string, string> | undefined;
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.LocalConnection = exports.Connection = void 0;
6
+ exports.cleanseStorageOptions = cleanseStorageOptions;
7
+ const arrow_1 = require("./arrow");
8
+ const arrow_2 = require("./arrow");
9
+ const registry_1 = require("./embedding/registry");
10
+ const sanitize_1 = require("./sanitize");
11
+ const table_1 = require("./table");
12
+ /**
13
+ * A LanceDB Connection that allows you to open tables and create new ones.
14
+ *
15
+ * Connection could be local against filesystem or remote against a server.
16
+ *
17
+ * A Connection is intended to be a long lived object and may hold open
18
+ * resources such as HTTP connection pools. This is generally fine and
19
+ * a single connection should be shared if it is going to be used many
20
+ * times. However, if you are finished with a connection, you may call
21
+ * close to eagerly free these resources. Any call to a Connection
22
+ * method after it has been closed will result in an error.
23
+ *
24
+ * Closing a connection is optional. Connections will automatically
25
+ * be closed when they are garbage collected.
26
+ *
27
+ * Any created tables are independent and will continue to work even if
28
+ * the underlying connection has been closed.
29
+ * @hideconstructor
30
+ */
31
+ class Connection {
32
+ [Symbol.for("nodejs.util.inspect.custom")]() {
33
+ return this.display();
34
+ }
35
+ }
36
+ exports.Connection = Connection;
37
+ /** @hideconstructor */
38
+ class LocalConnection extends Connection {
39
+ inner;
40
+ /** @hidden */
41
+ constructor(inner) {
42
+ super();
43
+ this.inner = inner;
44
+ }
45
+ isOpen() {
46
+ return this.inner.isOpen();
47
+ }
48
+ close() {
49
+ this.inner.close();
50
+ }
51
+ display() {
52
+ return this.inner.display();
53
+ }
54
+ async tableNames(namespaceOrOptions, options) {
55
+ // Detect if first argument is namespace array or options object
56
+ let namespace;
57
+ let tableNamesOptions;
58
+ if (Array.isArray(namespaceOrOptions)) {
59
+ // First argument is namespace array
60
+ namespace = namespaceOrOptions;
61
+ tableNamesOptions = options;
62
+ }
63
+ else {
64
+ // First argument is options object (backwards compatibility)
65
+ namespace = undefined;
66
+ tableNamesOptions = namespaceOrOptions;
67
+ }
68
+ return this.inner.tableNames(namespace ?? [], tableNamesOptions?.startAfter, tableNamesOptions?.limit);
69
+ }
70
+ async openTable(name, namespace, options) {
71
+ const innerTable = await this.inner.openTable(name, namespace ?? [], cleanseStorageOptions(options?.storageOptions), options?.indexCacheSize);
72
+ return new table_1.LocalTable(innerTable);
73
+ }
74
+ async cloneTable(targetTableName, sourceUri, options) {
75
+ const innerTable = await this.inner.cloneTable(targetTableName, sourceUri, options?.targetNamespace ?? [], options?.sourceVersion ?? null, options?.sourceTag ?? null, options?.isShallow ?? true);
76
+ return new table_1.LocalTable(innerTable);
77
+ }
78
+ getStorageOptions(options) {
79
+ if (options?.dataStorageVersion !== undefined) {
80
+ if (options.storageOptions === undefined) {
81
+ options.storageOptions = {};
82
+ }
83
+ options.storageOptions["newTableDataStorageVersion"] =
84
+ options.dataStorageVersion;
85
+ }
86
+ if (options?.enableV2ManifestPaths !== undefined) {
87
+ if (options.storageOptions === undefined) {
88
+ options.storageOptions = {};
89
+ }
90
+ options.storageOptions["newTableEnableV2ManifestPaths"] =
91
+ options.enableV2ManifestPaths ? "true" : "false";
92
+ }
93
+ return cleanseStorageOptions(options?.storageOptions);
94
+ }
95
+ async createTable(nameOrOptions, dataOrNamespace, namespaceOrOptions, options) {
96
+ if (typeof nameOrOptions !== "string" && "name" in nameOrOptions) {
97
+ // First overload: createTable(options, namespace?)
98
+ const { name, data, ...createOptions } = nameOrOptions;
99
+ const namespace = dataOrNamespace;
100
+ return this._createTableImpl(name, data, namespace, createOptions);
101
+ }
102
+ // Second overload: createTable(name, data, namespace?, options?)
103
+ const name = nameOrOptions;
104
+ const data = dataOrNamespace;
105
+ // Detect if third argument is namespace array or options object
106
+ let namespace;
107
+ let createOptions;
108
+ if (Array.isArray(namespaceOrOptions)) {
109
+ // Third argument is namespace array
110
+ namespace = namespaceOrOptions;
111
+ createOptions = options;
112
+ }
113
+ else {
114
+ // Third argument is options object (backwards compatibility)
115
+ namespace = undefined;
116
+ createOptions = namespaceOrOptions;
117
+ }
118
+ return this._createTableImpl(name, data, namespace, createOptions);
119
+ }
120
+ async _createTableImpl(name, data, namespace, options) {
121
+ if (data === undefined) {
122
+ throw new Error("data is required");
123
+ }
124
+ const { buf, mode } = await parseTableData(data, options);
125
+ const storageOptions = this.getStorageOptions(options);
126
+ const innerTable = await this.inner.createTable(name, buf, mode, namespace ?? [], storageOptions);
127
+ return new table_1.LocalTable(innerTable);
128
+ }
129
+ async createEmptyTable(name, schema, namespaceOrOptions, options) {
130
+ // Detect if third argument is namespace array or options object
131
+ let namespace;
132
+ let createOptions;
133
+ if (Array.isArray(namespaceOrOptions)) {
134
+ // Third argument is namespace array
135
+ namespace = namespaceOrOptions;
136
+ createOptions = options;
137
+ }
138
+ else {
139
+ // Third argument is options object (backwards compatibility)
140
+ namespace = undefined;
141
+ createOptions = namespaceOrOptions;
142
+ }
143
+ let mode = createOptions?.mode ?? "create";
144
+ const existOk = createOptions?.existOk ?? false;
145
+ if (mode === "create" && existOk) {
146
+ mode = "exist_ok";
147
+ }
148
+ let metadata = undefined;
149
+ if (createOptions?.embeddingFunction !== undefined) {
150
+ const embeddingFunction = createOptions.embeddingFunction;
151
+ const registry = (0, registry_1.getRegistry)();
152
+ metadata = registry.getTableMetadata([embeddingFunction]);
153
+ }
154
+ const storageOptions = this.getStorageOptions(createOptions);
155
+ const table = (0, arrow_2.makeEmptyTable)(schema, metadata);
156
+ const buf = await (0, arrow_2.fromTableToBuffer)(table);
157
+ const innerTable = await this.inner.createEmptyTable(name, buf, mode, namespace ?? [], storageOptions);
158
+ return new table_1.LocalTable(innerTable);
159
+ }
160
+ async dropTable(name, namespace) {
161
+ return this.inner.dropTable(name, namespace ?? []);
162
+ }
163
+ async dropAllTables(namespace) {
164
+ return this.inner.dropAllTables(namespace ?? []);
165
+ }
166
+ }
167
+ exports.LocalConnection = LocalConnection;
168
+ /**
169
+ * Takes storage options and makes all the keys snake case.
170
+ */
171
+ function cleanseStorageOptions(options) {
172
+ if (options === undefined) {
173
+ return undefined;
174
+ }
175
+ const result = {};
176
+ for (const [key, value] of Object.entries(options)) {
177
+ if (value !== undefined) {
178
+ const newKey = camelToSnakeCase(key);
179
+ result[newKey] = value;
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+ /**
185
+ * Convert a string to snake case. It might already be snake case, in which case it is
186
+ * returned unchanged.
187
+ */
188
+ function camelToSnakeCase(camel) {
189
+ if (camel.includes("_")) {
190
+ // Assume if there is at least one underscore, it is already snake case
191
+ return camel;
192
+ }
193
+ if (camel.toLocaleUpperCase() === camel) {
194
+ // Assume if the string is all uppercase, it is already snake case
195
+ return camel;
196
+ }
197
+ let result = camel.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
198
+ if (result.startsWith("_")) {
199
+ result = result.slice(1);
200
+ }
201
+ return result;
202
+ }
203
+ async function parseTableData(data, options, streaming = false) {
204
+ let mode = options?.mode ?? "create";
205
+ const existOk = options?.existOk ?? false;
206
+ if (mode === "create" && existOk) {
207
+ mode = "exist_ok";
208
+ }
209
+ let table;
210
+ if ((0, arrow_1.isArrowTable)(data)) {
211
+ table = (0, sanitize_1.sanitizeTable)(data);
212
+ }
213
+ else {
214
+ table = (0, arrow_1.makeArrowTable)(data, options);
215
+ }
216
+ if (streaming) {
217
+ const buf = await (0, arrow_1.fromTableToStreamBuffer)(table, options?.embeddingFunction, options?.schema);
218
+ return { buf, mode };
219
+ }
220
+ else {
221
+ const buf = await (0, arrow_2.fromTableToBuffer)(table, options?.embeddingFunction, options?.schema);
222
+ return { buf, mode };
223
+ }
224
+ }
@@ -0,0 +1,103 @@
1
+ import "reflect-metadata";
2
+ import { DataType, Float, type IntoVector } from "../arrow";
3
+ /**
4
+ * Options for a given embedding function
5
+ */
6
+ export interface FunctionOptions {
7
+ [key: string]: any;
8
+ }
9
+ export interface EmbeddingFunctionConstructor<T extends EmbeddingFunction = EmbeddingFunction> {
10
+ new (modelOptions?: T["TOptions"]): T;
11
+ }
12
+ /**
13
+ * An embedding function that automatically creates vector representation for a given column.
14
+ *
15
+ * It's important subclasses pass the **original** options to the super constructor
16
+ * and then pass those options to `resolveVariables` to resolve any variables before
17
+ * using them.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * class MyEmbeddingFunction extends EmbeddingFunction {
22
+ * constructor(options: {model: string, timeout: number}) {
23
+ * super(optionsRaw);
24
+ * const options = this.resolveVariables(optionsRaw);
25
+ * this.model = options.model;
26
+ * this.timeout = options.timeout;
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ export declare abstract class EmbeddingFunction<T = any, M extends FunctionOptions = FunctionOptions> {
32
+ #private;
33
+ /**
34
+ * @ignore
35
+ * This is only used for associating the options type with the class for type checking
36
+ */
37
+ readonly TOptions: M;
38
+ /**
39
+ * Get the original arguments to the constructor, to serialize them so they
40
+ * can be used to recreate the embedding function later.
41
+ */
42
+ toJSON(): Record<string, any>;
43
+ constructor();
44
+ /**
45
+ * Provide a list of keys in the function options that should be treated as
46
+ * sensitive. If users pass raw values for these keys, they will be rejected.
47
+ */
48
+ protected getSensitiveKeys(): string[];
49
+ /**
50
+ * Apply variables to the config.
51
+ */
52
+ protected resolveVariables(config: Partial<M>): Partial<M>;
53
+ /**
54
+ * Optionally load any resources needed for the embedding function.
55
+ *
56
+ * This method is called after the embedding function has been initialized
57
+ * but before any embeddings are computed. It is useful for loading local models
58
+ * or other resources that are needed for the embedding function to work.
59
+ */
60
+ init?(): Promise<void>;
61
+ /**
62
+ * sourceField is used in combination with `LanceSchema` to provide a declarative data model
63
+ *
64
+ * @param optionsOrDatatype - The options for the field or the datatype
65
+ *
66
+ * @see {@link LanceSchema}
67
+ */
68
+ sourceField(optionsOrDatatype: Partial<FieldOptions> | DataType): [DataType, Map<string, EmbeddingFunction>];
69
+ /**
70
+ * vectorField is used in combination with `LanceSchema` to provide a declarative data model
71
+ *
72
+ * @param optionsOrDatatype - The options for the field
73
+ *
74
+ * @see {@link LanceSchema}
75
+ */
76
+ vectorField(optionsOrDatatype?: Partial<FieldOptions> | DataType): [DataType, Map<string, EmbeddingFunction>];
77
+ /** The number of dimensions of the embeddings */
78
+ ndims(): number | undefined;
79
+ /** The datatype of the embeddings */
80
+ abstract embeddingDataType(): Float;
81
+ /**
82
+ * Creates a vector representation for the given values.
83
+ */
84
+ abstract computeSourceEmbeddings(data: T[]): Promise<number[][] | Float32Array[] | Float64Array[]>;
85
+ /**
86
+ Compute the embeddings for a single query
87
+ */
88
+ computeQueryEmbeddings(data: T): Promise<Awaited<IntoVector>>;
89
+ }
90
+ /**
91
+ * an abstract class for implementing embedding functions that take text as input
92
+ */
93
+ export declare abstract class TextEmbeddingFunction<M extends FunctionOptions = FunctionOptions> extends EmbeddingFunction<string, M> {
94
+ abstract generateEmbeddings(texts: string[], ...args: any[]): Promise<number[][] | Float32Array[] | Float64Array[]>;
95
+ computeQueryEmbeddings(data: string): Promise<Awaited<IntoVector>>;
96
+ embeddingDataType(): Float;
97
+ sourceField(): [DataType, Map<string, EmbeddingFunction>];
98
+ computeSourceEmbeddings(data: string[]): Promise<number[][] | Float32Array[] | Float64Array[]>;
99
+ }
100
+ export interface FieldOptions<T extends DataType = DataType> {
101
+ datatype: T;
102
+ dims?: number;
103
+ }