@lancedb/lancedb 0.7.0 → 0.8.0

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 (86) hide show
  1. package/dist/arrow.d.ts +5 -3
  2. package/dist/arrow.js +1 -1
  3. package/dist/embedding/embedding_function.d.ts +4 -3
  4. package/dist/embedding/index.d.ts +1 -0
  5. package/dist/embedding/index.js +1 -0
  6. package/dist/embedding/registry.d.ts +9 -7
  7. package/dist/embedding/registry.js +24 -6
  8. package/dist/embedding/transformers.d.ts +37 -0
  9. package/dist/embedding/transformers.js +147 -0
  10. package/dist/query.js +15 -9
  11. package/dist/remote/client.d.ts +1 -1
  12. package/dist/remote/client.js +6 -8
  13. package/dist/remote/connection.d.ts +2 -3
  14. package/dist/remote/connection.js +2 -2
  15. package/dist/table.d.ts +3 -0
  16. package/dist/table.js +1 -1
  17. package/package.json +17 -14
  18. package/Cargo.toml +0 -28
  19. package/biome.json +0 -158
  20. package/build.rs +0 -5
  21. package/dist/native.d.ts +0 -208
  22. package/examples/ann_indexes.ts +0 -49
  23. package/examples/basic.ts +0 -149
  24. package/examples/embedding.ts +0 -83
  25. package/examples/filtering.ts +0 -34
  26. package/examples/jsconfig.json +0 -27
  27. package/examples/package-lock.json +0 -79
  28. package/examples/package.json +0 -18
  29. package/examples/search.ts +0 -37
  30. package/jest.config.js +0 -7
  31. package/lancedb/arrow.ts +0 -947
  32. package/lancedb/connection.ts +0 -333
  33. package/lancedb/embedding/embedding_function.ts +0 -194
  34. package/lancedb/embedding/index.ts +0 -113
  35. package/lancedb/embedding/openai.ts +0 -113
  36. package/lancedb/embedding/registry.ts +0 -188
  37. package/lancedb/index.ts +0 -142
  38. package/lancedb/indices.ts +0 -203
  39. package/lancedb/merge.ts +0 -70
  40. package/lancedb/query.ts +0 -507
  41. package/lancedb/remote/client.ts +0 -221
  42. package/lancedb/remote/connection.ts +0 -201
  43. package/lancedb/remote/index.ts +0 -3
  44. package/lancedb/remote/table.ts +0 -226
  45. package/lancedb/sanitize.ts +0 -588
  46. package/lancedb/table.ts +0 -669
  47. package/lancedb/util.ts +0 -69
  48. package/native.d.ts +0 -208
  49. package/nodejs-artifacts/arrow.d.ts +0 -250
  50. package/nodejs-artifacts/arrow.js +0 -768
  51. package/nodejs-artifacts/connection.d.ts +0 -171
  52. package/nodejs-artifacts/connection.js +0 -135
  53. package/nodejs-artifacts/embedding/embedding_function.d.ts +0 -79
  54. package/nodejs-artifacts/embedding/embedding_function.js +0 -112
  55. package/nodejs-artifacts/embedding/index.d.ts +0 -28
  56. package/nodejs-artifacts/embedding/index.js +0 -114
  57. package/nodejs-artifacts/embedding/openai.d.ts +0 -18
  58. package/nodejs-artifacts/embedding/openai.js +0 -105
  59. package/nodejs-artifacts/embedding/registry.d.ts +0 -53
  60. package/nodejs-artifacts/embedding/registry.js +0 -127
  61. package/nodejs-artifacts/index.d.ts +0 -55
  62. package/nodejs-artifacts/index.js +0 -57
  63. package/nodejs-artifacts/indices.d.ts +0 -165
  64. package/nodejs-artifacts/indices.js +0 -71
  65. package/nodejs-artifacts/merge.d.ts +0 -54
  66. package/nodejs-artifacts/merge.js +0 -64
  67. package/nodejs-artifacts/native.d.ts +0 -208
  68. package/nodejs-artifacts/native.js +0 -330
  69. package/nodejs-artifacts/query.d.ts +0 -283
  70. package/nodejs-artifacts/query.js +0 -448
  71. package/nodejs-artifacts/remote/client.d.ts +0 -28
  72. package/nodejs-artifacts/remote/client.js +0 -172
  73. package/nodejs-artifacts/remote/connection.d.ts +0 -25
  74. package/nodejs-artifacts/remote/connection.js +0 -110
  75. package/nodejs-artifacts/remote/index.d.ts +0 -3
  76. package/nodejs-artifacts/remote/index.js +0 -9
  77. package/nodejs-artifacts/remote/table.d.ts +0 -42
  78. package/nodejs-artifacts/remote/table.js +0 -179
  79. package/nodejs-artifacts/sanitize.d.ts +0 -31
  80. package/nodejs-artifacts/sanitize.js +0 -436
  81. package/nodejs-artifacts/table.d.ts +0 -395
  82. package/nodejs-artifacts/table.js +0 -230
  83. package/nodejs-artifacts/util.d.ts +0 -14
  84. package/nodejs-artifacts/util.js +0 -65
  85. package/tsconfig.json +0 -25
  86. package/typedoc.json +0 -10
@@ -1,171 +0,0 @@
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.github.io/lancedb/guides/storage/
28
- */
29
- storageOptions?: Record<string, string>;
30
- /**
31
- * If true then data files will be written with the legacy format
32
- *
33
- * The default is true while the new format is in beta
34
- */
35
- useLegacyFormat?: boolean;
36
- schema?: SchemaLike;
37
- embeddingFunction?: EmbeddingFunctionConfig;
38
- }
39
- export interface OpenTableOptions {
40
- /**
41
- * Configuration for object storage.
42
- *
43
- * Options already set on the connection will be inherited by the table,
44
- * but can be overridden here.
45
- *
46
- * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
47
- */
48
- storageOptions?: Record<string, string>;
49
- /**
50
- * Set the size of the index cache, specified as a number of entries
51
- *
52
- * The exact meaning of an "entry" will depend on the type of index:
53
- * - IVF: there is one entry for each IVF partition
54
- * - BTREE: there is one entry for the entire index
55
- *
56
- * This cache applies to the entire opened table, across all indices.
57
- * Setting this value higher will increase performance on larger datasets
58
- * at the expense of more RAM
59
- */
60
- indexCacheSize?: number;
61
- }
62
- export interface TableNamesOptions {
63
- /**
64
- * If present, only return names that come lexicographically after the
65
- * supplied value.
66
- *
67
- * This can be combined with limit to implement pagination by setting this to
68
- * the last table name from the previous page.
69
- */
70
- startAfter?: string;
71
- /** An optional limit to the number of results to return. */
72
- limit?: number;
73
- }
74
- /**
75
- * A LanceDB Connection that allows you to open tables and create new ones.
76
- *
77
- * Connection could be local against filesystem or remote against a server.
78
- *
79
- * A Connection is intended to be a long lived object and may hold open
80
- * resources such as HTTP connection pools. This is generally fine and
81
- * a single connection should be shared if it is going to be used many
82
- * times. However, if you are finished with a connection, you may call
83
- * close to eagerly free these resources. Any call to a Connection
84
- * method after it has been closed will result in an error.
85
- *
86
- * Closing a connection is optional. Connections will automatically
87
- * be closed when they are garbage collected.
88
- *
89
- * Any created tables are independent and will continue to work even if
90
- * the underlying connection has been closed.
91
- */
92
- export declare abstract class Connection {
93
- /**
94
- * Return true if the connection has not been closed
95
- */
96
- abstract isOpen(): boolean;
97
- /**
98
- * Close the connection, releasing any underlying resources.
99
- *
100
- * It is safe to call this method multiple times.
101
- *
102
- * Any attempt to use the connection after it is closed will result in an error.
103
- */
104
- abstract close(): void;
105
- /**
106
- * Return a brief description of the connection
107
- */
108
- abstract display(): string;
109
- /**
110
- * List all the table names in this database.
111
- *
112
- * Tables will be returned in lexicographical order.
113
- * @param {Partial<TableNamesOptions>} options - options to control the
114
- * paging / start point
115
- *
116
- */
117
- abstract tableNames(options?: Partial<TableNamesOptions>): Promise<string[]>;
118
- /**
119
- * Open a table in the database.
120
- * @param {string} name - The name of the table
121
- */
122
- abstract openTable(name: string, options?: Partial<OpenTableOptions>): Promise<Table>;
123
- /**
124
- * Creates a new Table and initialize it with new data.
125
- * @param {object} options - The options object.
126
- * @param {string} options.name - The name of the table.
127
- * @param {Data} options.data - Non-empty Array of Records to be inserted into the table
128
- *
129
- */
130
- abstract createTable(options: {
131
- name: string;
132
- data: Data;
133
- } & Partial<CreateTableOptions>): Promise<Table>;
134
- /**
135
- * Creates a new Table and initialize it with new data.
136
- * @param {string} name - The name of the table.
137
- * @param {Record<string, unknown>[] | TableLike} data - Non-empty Array of Records
138
- * to be inserted into the table
139
- */
140
- abstract createTable(name: string, data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>): Promise<Table>;
141
- /**
142
- * Creates a new empty Table
143
- * @param {string} name - The name of the table.
144
- * @param {Schema} schema - The schema of the table
145
- */
146
- abstract createEmptyTable(name: string, schema: import("./arrow").SchemaLike, options?: Partial<CreateTableOptions>): Promise<Table>;
147
- /**
148
- * Drop an existing table.
149
- * @param {string} name The name of the table to drop.
150
- */
151
- abstract dropTable(name: string): Promise<void>;
152
- }
153
- export declare class LocalConnection extends Connection {
154
- readonly inner: LanceDbConnection;
155
- constructor(inner: LanceDbConnection);
156
- isOpen(): boolean;
157
- close(): void;
158
- display(): string;
159
- tableNames(options?: Partial<TableNamesOptions>): Promise<string[]>;
160
- openTable(name: string, options?: Partial<OpenTableOptions>): Promise<Table>;
161
- createTable(nameOrOptions: string | ({
162
- name: string;
163
- data: Data;
164
- } & Partial<CreateTableOptions>), data?: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>): Promise<Table>;
165
- createEmptyTable(name: string, schema: import("./arrow").SchemaLike, options?: Partial<CreateTableOptions>): Promise<Table>;
166
- dropTable(name: string): Promise<void>;
167
- }
168
- /**
169
- * Takes storage options and makes all the keys snake case.
170
- */
171
- export declare function cleanseStorageOptions(options?: Record<string, string>): Record<string, string> | undefined;
@@ -1,135 +0,0 @@
1
- "use strict";
2
- // Copyright 2024 Lance Developers.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.cleanseStorageOptions = exports.LocalConnection = exports.Connection = void 0;
17
- const arrow_1 = require("./arrow");
18
- const registry_1 = require("./embedding/registry");
19
- const table_1 = require("./table");
20
- /**
21
- * A LanceDB Connection that allows you to open tables and create new ones.
22
- *
23
- * Connection could be local against filesystem or remote against a server.
24
- *
25
- * A Connection is intended to be a long lived object and may hold open
26
- * resources such as HTTP connection pools. This is generally fine and
27
- * a single connection should be shared if it is going to be used many
28
- * times. However, if you are finished with a connection, you may call
29
- * close to eagerly free these resources. Any call to a Connection
30
- * method after it has been closed will result in an error.
31
- *
32
- * Closing a connection is optional. Connections will automatically
33
- * be closed when they are garbage collected.
34
- *
35
- * Any created tables are independent and will continue to work even if
36
- * the underlying connection has been closed.
37
- */
38
- class Connection {
39
- [Symbol.for("nodejs.util.inspect.custom")]() {
40
- return this.display();
41
- }
42
- }
43
- exports.Connection = Connection;
44
- class LocalConnection extends Connection {
45
- inner;
46
- constructor(inner) {
47
- super();
48
- this.inner = inner;
49
- }
50
- isOpen() {
51
- return this.inner.isOpen();
52
- }
53
- close() {
54
- this.inner.close();
55
- }
56
- display() {
57
- return this.inner.display();
58
- }
59
- async tableNames(options) {
60
- return this.inner.tableNames(options?.startAfter, options?.limit);
61
- }
62
- async openTable(name, options) {
63
- const innerTable = await this.inner.openTable(name, cleanseStorageOptions(options?.storageOptions), options?.indexCacheSize);
64
- return new table_1.LocalTable(innerTable);
65
- }
66
- async createTable(nameOrOptions, data, options) {
67
- if (typeof nameOrOptions !== "string" && "name" in nameOrOptions) {
68
- const { name, data, ...options } = nameOrOptions;
69
- return this.createTable(name, data, options);
70
- }
71
- if (data === undefined) {
72
- throw new Error("data is required");
73
- }
74
- const { buf, mode } = await table_1.Table.parseTableData(data, options);
75
- const innerTable = await this.inner.createTable(nameOrOptions, buf, mode, cleanseStorageOptions(options?.storageOptions), options?.useLegacyFormat);
76
- return new table_1.LocalTable(innerTable);
77
- }
78
- async createEmptyTable(name, schema, options) {
79
- let mode = options?.mode ?? "create";
80
- const existOk = options?.existOk ?? false;
81
- if (mode === "create" && existOk) {
82
- mode = "exist_ok";
83
- }
84
- let metadata = undefined;
85
- if (options?.embeddingFunction !== undefined) {
86
- const embeddingFunction = options.embeddingFunction;
87
- const registry = (0, registry_1.getRegistry)();
88
- metadata = registry.getTableMetadata([embeddingFunction]);
89
- }
90
- const table = (0, arrow_1.makeEmptyTable)(schema, metadata);
91
- const buf = await (0, arrow_1.fromTableToBuffer)(table);
92
- const innerTable = await this.inner.createEmptyTable(name, buf, mode, cleanseStorageOptions(options?.storageOptions), options?.useLegacyFormat);
93
- return new table_1.LocalTable(innerTable);
94
- }
95
- async dropTable(name) {
96
- return this.inner.dropTable(name);
97
- }
98
- }
99
- exports.LocalConnection = LocalConnection;
100
- /**
101
- * Takes storage options and makes all the keys snake case.
102
- */
103
- function cleanseStorageOptions(options) {
104
- if (options === undefined) {
105
- return undefined;
106
- }
107
- const result = {};
108
- for (const [key, value] of Object.entries(options)) {
109
- if (value !== undefined) {
110
- const newKey = camelToSnakeCase(key);
111
- result[newKey] = value;
112
- }
113
- }
114
- return result;
115
- }
116
- exports.cleanseStorageOptions = cleanseStorageOptions;
117
- /**
118
- * Convert a string to snake case. It might already be snake case, in which case it is
119
- * returned unchanged.
120
- */
121
- function camelToSnakeCase(camel) {
122
- if (camel.includes("_")) {
123
- // Assume if there is at least one underscore, it is already snake case
124
- return camel;
125
- }
126
- if (camel.toLocaleUpperCase() === camel) {
127
- // Assume if the string is all uppercase, it is already snake case
128
- return camel;
129
- }
130
- let result = camel.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
131
- if (result.startsWith("_")) {
132
- result = result.slice(1);
133
- }
134
- return result;
135
- }
@@ -1,79 +0,0 @@
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
- export declare abstract class EmbeddingFunction<T = any, M extends FunctionOptions = FunctionOptions> {
16
- /**
17
- * @ignore
18
- * This is only used for associating the options type with the class for type checking
19
- */
20
- readonly TOptions: M;
21
- /**
22
- * Convert the embedding function to a JSON object
23
- * It is used to serialize the embedding function to the schema
24
- * It's important that any object returned by this method contains all the necessary
25
- * information to recreate the embedding function
26
- *
27
- * It should return the same object that was passed to the constructor
28
- * If it does not, the embedding function will not be able to be recreated, or could be recreated incorrectly
29
- *
30
- * @example
31
- * ```ts
32
- * class MyEmbeddingFunction extends EmbeddingFunction {
33
- * constructor(options: {model: string, timeout: number}) {
34
- * super();
35
- * this.model = options.model;
36
- * this.timeout = options.timeout;
37
- * }
38
- * toJSON() {
39
- * return {
40
- * model: this.model,
41
- * timeout: this.timeout,
42
- * };
43
- * }
44
- * ```
45
- */
46
- abstract toJSON(): Partial<M>;
47
- /**
48
- * sourceField is used in combination with `LanceSchema` to provide a declarative data model
49
- *
50
- * @param optionsOrDatatype - The options for the field or the datatype
51
- *
52
- * @see {@link lancedb.LanceSchema}
53
- */
54
- sourceField(optionsOrDatatype: Partial<FieldOptions> | DataType): [DataType, Map<string, EmbeddingFunction>];
55
- /**
56
- * vectorField is used in combination with `LanceSchema` to provide a declarative data model
57
- *
58
- * @param options - The options for the field
59
- *
60
- * @see {@link lancedb.LanceSchema}
61
- */
62
- vectorField(optionsOrDatatype?: Partial<FieldOptions> | DataType): [DataType, Map<string, EmbeddingFunction>];
63
- /** The number of dimensions of the embeddings */
64
- ndims(): number | undefined;
65
- /** The datatype of the embeddings */
66
- abstract embeddingDataType(): Float;
67
- /**
68
- * Creates a vector representation for the given values.
69
- */
70
- abstract computeSourceEmbeddings(data: T[]): Promise<number[][] | Float32Array[] | Float64Array[]>;
71
- /**
72
- Compute the embeddings for a single query
73
- */
74
- computeQueryEmbeddings(data: T): Promise<Awaited<IntoVector>>;
75
- }
76
- export interface FieldOptions<T extends DataType = DataType> {
77
- datatype: T;
78
- dims?: number;
79
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
- // Copyright 2024 Lance Developers.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.EmbeddingFunction = void 0;
17
- require("reflect-metadata");
18
- const arrow_1 = require("../arrow");
19
- const sanitize_1 = require("../sanitize");
20
- /**
21
- * An embedding function that automatically creates vector representation for a given column.
22
- */
23
- class EmbeddingFunction {
24
- /**
25
- * @ignore
26
- * This is only used for associating the options type with the class for type checking
27
- */
28
- // biome-ignore lint/style/useNamingConvention: we want to keep the name as it is
29
- TOptions;
30
- /**
31
- * sourceField is used in combination with `LanceSchema` to provide a declarative data model
32
- *
33
- * @param optionsOrDatatype - The options for the field or the datatype
34
- *
35
- * @see {@link lancedb.LanceSchema}
36
- */
37
- sourceField(optionsOrDatatype) {
38
- let datatype = (0, arrow_1.isDataType)(optionsOrDatatype)
39
- ? optionsOrDatatype
40
- : optionsOrDatatype?.datatype;
41
- if (!datatype) {
42
- throw new Error("Datatype is required");
43
- }
44
- datatype = (0, sanitize_1.sanitizeType)(datatype);
45
- const metadata = new Map();
46
- metadata.set("source_column_for", this);
47
- return [datatype, metadata];
48
- }
49
- /**
50
- * vectorField is used in combination with `LanceSchema` to provide a declarative data model
51
- *
52
- * @param options - The options for the field
53
- *
54
- * @see {@link lancedb.LanceSchema}
55
- */
56
- vectorField(optionsOrDatatype) {
57
- let dtype;
58
- let vectorType;
59
- let dims = this.ndims();
60
- // `func.vectorField(new Float32())`
61
- if ((0, arrow_1.isDataType)(optionsOrDatatype)) {
62
- dtype = optionsOrDatatype;
63
- }
64
- else {
65
- // `func.vectorField({
66
- // datatype: new Float32(),
67
- // dims: 10
68
- // })`
69
- dims = dims ?? optionsOrDatatype?.dims;
70
- dtype = optionsOrDatatype?.datatype;
71
- }
72
- if (dtype !== undefined) {
73
- // `func.vectorField(new FixedSizeList(dims, new Field("item", new Float32(), true)))`
74
- // or `func.vectorField({datatype: new FixedSizeList(dims, new Field("item", new Float32(), true))})`
75
- if ((0, arrow_1.isFixedSizeList)(dtype)) {
76
- vectorType = dtype;
77
- // `func.vectorField(new Float32())`
78
- // or `func.vectorField({datatype: new Float32()})`
79
- }
80
- else if ((0, arrow_1.isFloat)(dtype)) {
81
- // No `ndims` impl and no `{dims: n}` provided;
82
- if (dims === undefined) {
83
- throw new Error("ndims is required for vector field");
84
- }
85
- vectorType = (0, arrow_1.newVectorType)(dims, dtype);
86
- }
87
- else {
88
- throw new Error("Expected FixedSizeList or Float as datatype for vector field");
89
- }
90
- }
91
- else {
92
- if (dims === undefined) {
93
- throw new Error("ndims is required for vector field");
94
- }
95
- vectorType = new arrow_1.FixedSizeList(dims, new arrow_1.Field("item", new arrow_1.Float32(), true));
96
- }
97
- const metadata = new Map();
98
- metadata.set("vector_column_for", this);
99
- return [vectorType, metadata];
100
- }
101
- /** The number of dimensions of the embeddings */
102
- ndims() {
103
- return undefined;
104
- }
105
- /**
106
- Compute the embeddings for a single query
107
- */
108
- async computeQueryEmbeddings(data) {
109
- return this.computeSourceEmbeddings([data]).then((embeddings) => embeddings[0]);
110
- }
111
- }
112
- exports.EmbeddingFunction = EmbeddingFunction;
@@ -1,28 +0,0 @@
1
- import { Schema } from "../arrow";
2
- import { EmbeddingFunction } from "./embedding_function";
3
- export { EmbeddingFunction } from "./embedding_function";
4
- export * from "./openai";
5
- export * from "./registry";
6
- /**
7
- * Create a schema with embedding functions.
8
- *
9
- * @param fields
10
- * @returns Schema
11
- * @example
12
- * ```ts
13
- * class MyEmbeddingFunction extends EmbeddingFunction {
14
- * // ...
15
- * }
16
- * const func = new MyEmbeddingFunction();
17
- * const schema = LanceSchema({
18
- * id: new Int32(),
19
- * text: func.sourceField(new Utf8()),
20
- * vector: func.vectorField(),
21
- * // optional: specify the datatype and/or dimensions
22
- * vector2: func.vectorField({ datatype: new Float32(), dims: 3}),
23
- * });
24
- *
25
- * const table = await db.createTable("my_table", data, { schema });
26
- * ```
27
- */
28
- export declare function LanceSchema(fields: Record<string, [object, Map<string, EmbeddingFunction>] | object>): Schema;
@@ -1,114 +0,0 @@
1
- "use strict";
2
- // Copyright 2023 Lance Developers.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- var desc = Object.getOwnPropertyDescriptor(m, k);
18
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
20
- }
21
- Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.LanceSchema = exports.EmbeddingFunction = void 0;
31
- const arrow_1 = require("../arrow");
32
- const arrow_2 = require("../arrow");
33
- const sanitize_1 = require("../sanitize");
34
- const registry_1 = require("./registry");
35
- var embedding_function_1 = require("./embedding_function");
36
- Object.defineProperty(exports, "EmbeddingFunction", { enumerable: true, get: function () { return embedding_function_1.EmbeddingFunction; } });
37
- // We need to explicitly export '*' so that the `register` decorator actually registers the class.
38
- __exportStar(require("./openai"), exports);
39
- __exportStar(require("./registry"), exports);
40
- /**
41
- * Create a schema with embedding functions.
42
- *
43
- * @param fields
44
- * @returns Schema
45
- * @example
46
- * ```ts
47
- * class MyEmbeddingFunction extends EmbeddingFunction {
48
- * // ...
49
- * }
50
- * const func = new MyEmbeddingFunction();
51
- * const schema = LanceSchema({
52
- * id: new Int32(),
53
- * text: func.sourceField(new Utf8()),
54
- * vector: func.vectorField(),
55
- * // optional: specify the datatype and/or dimensions
56
- * vector2: func.vectorField({ datatype: new Float32(), dims: 3}),
57
- * });
58
- *
59
- * const table = await db.createTable("my_table", data, { schema });
60
- * ```
61
- */
62
- function LanceSchema(fields) {
63
- const arrowFields = [];
64
- const embeddingFunctions = new Map();
65
- Object.entries(fields).forEach(([key, value]) => {
66
- if ((0, arrow_2.isDataType)(value)) {
67
- arrowFields.push(new arrow_1.Field(key, (0, sanitize_1.sanitizeType)(value), true));
68
- }
69
- else {
70
- const [dtype, metadata] = value;
71
- arrowFields.push(new arrow_1.Field(key, (0, sanitize_1.sanitizeType)(dtype), true));
72
- parseEmbeddingFunctions(embeddingFunctions, key, metadata);
73
- }
74
- });
75
- const registry = (0, registry_1.getRegistry)();
76
- const metadata = registry.getTableMetadata(Array.from(embeddingFunctions.values()));
77
- const schema = new arrow_1.Schema(arrowFields, metadata);
78
- return schema;
79
- }
80
- exports.LanceSchema = LanceSchema;
81
- function parseEmbeddingFunctions(embeddingFunctions, key, metadata) {
82
- if (metadata.has("source_column_for")) {
83
- const embedFunction = metadata.get("source_column_for");
84
- const current = embeddingFunctions.get(embedFunction);
85
- if (current !== undefined) {
86
- embeddingFunctions.set(embedFunction, {
87
- ...current,
88
- sourceColumn: key,
89
- });
90
- }
91
- else {
92
- embeddingFunctions.set(embedFunction, {
93
- sourceColumn: key,
94
- function: embedFunction,
95
- });
96
- }
97
- }
98
- else if (metadata.has("vector_column_for")) {
99
- const embedFunction = metadata.get("vector_column_for");
100
- const current = embeddingFunctions.get(embedFunction);
101
- if (current !== undefined) {
102
- embeddingFunctions.set(embedFunction, {
103
- ...current,
104
- vectorColumn: key,
105
- });
106
- }
107
- else {
108
- embeddingFunctions.set(embedFunction, {
109
- vectorColumn: key,
110
- function: embedFunction,
111
- });
112
- }
113
- }
114
- }
@@ -1,18 +0,0 @@
1
- import { type EmbeddingCreateParams } from "openai/resources";
2
- import { Float } from "../arrow";
3
- import { EmbeddingFunction } from "./embedding_function";
4
- export type OpenAIOptions = {
5
- apiKey: string;
6
- model: EmbeddingCreateParams["model"];
7
- };
8
- export declare class OpenAIEmbeddingFunction extends EmbeddingFunction<string, Partial<OpenAIOptions>> {
9
- #private;
10
- constructor(options?: Partial<OpenAIOptions>);
11
- toJSON(): {
12
- model: (string & {}) | "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large";
13
- };
14
- ndims(): number;
15
- embeddingDataType(): Float;
16
- computeSourceEmbeddings(data: string[]): Promise<number[][]>;
17
- computeQueryEmbeddings(data: string): Promise<number[]>;
18
- }