@lancedb/lancedb 0.38.0-beta.0 → 0.38.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow.d.ts +4 -1
- package/dist/arrow.js +35 -282
- package/dist/arrow_type.d.ts +9 -0
- package/dist/arrow_type.js +29 -0
- package/dist/connection.d.ts +96 -2
- package/dist/connection.js +23 -0
- package/dist/embedding/index.d.ts +11 -1
- package/dist/embedding/index.js +24 -17
- package/dist/embedding/openai.js +3 -15
- package/dist/embedding/registry.d.ts +21 -1
- package/dist/embedding/registry.js +76 -20
- package/dist/embedding/transformers.js +3 -15
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -1
- package/dist/materialized_view.d.ts +69 -0
- package/dist/materialized_view.js +112 -0
- package/dist/native.d.ts +115 -1
- package/dist/native.js +52 -52
- package/dist/query.d.ts +38 -2
- package/dist/query.js +154 -101
- package/dist/sanitize.js +10 -4
- package/dist/schema.d.ts +16 -0
- package/dist/schema.js +387 -0
- package/dist/table.d.ts +156 -23
- package/dist/table.js +55 -15
- package/package.json +10 -10
package/dist/embedding/index.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
-
};
|
|
18
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.TextEmbeddingFunction = exports.EmbeddingFunction = void 0;
|
|
5
|
+
exports.register = exports.parseEmbeddingMetadata = exports.EmbeddingFunctionRegistry = exports.TextEmbeddingFunction = exports.EmbeddingFunction = void 0;
|
|
6
|
+
exports.getRegistry = getRegistry;
|
|
20
7
|
exports.LanceSchema = LanceSchema;
|
|
21
8
|
const arrow_1 = require("../arrow");
|
|
22
9
|
const sanitize_1 = require("../sanitize");
|
|
@@ -24,7 +11,27 @@ const registry_1 = require("./registry");
|
|
|
24
11
|
var embedding_function_1 = require("./embedding_function");
|
|
25
12
|
Object.defineProperty(exports, "EmbeddingFunction", { enumerable: true, get: function () { return embedding_function_1.EmbeddingFunction; } });
|
|
26
13
|
Object.defineProperty(exports, "TextEmbeddingFunction", { enumerable: true, get: function () { return embedding_function_1.TextEmbeddingFunction; } });
|
|
27
|
-
|
|
14
|
+
var registry_2 = require("./registry");
|
|
15
|
+
Object.defineProperty(exports, "EmbeddingFunctionRegistry", { enumerable: true, get: function () { return registry_2.EmbeddingFunctionRegistry; } });
|
|
16
|
+
Object.defineProperty(exports, "parseEmbeddingMetadata", { enumerable: true, get: function () { return registry_2.parseEmbeddingMetadata; } });
|
|
17
|
+
Object.defineProperty(exports, "register", { enumerable: true, get: function () { return registry_2.register; } });
|
|
18
|
+
function initializeBuiltInProviders() {
|
|
19
|
+
const { OpenAIEmbeddingFunction } = require("./openai");
|
|
20
|
+
const { TransformersEmbeddingFunction } = require("./transformers");
|
|
21
|
+
(0, registry_1.registerBuiltIn)("openai", OpenAIEmbeddingFunction);
|
|
22
|
+
(0, registry_1.registerBuiltIn)("huggingface", TransformersEmbeddingFunction);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the global embedding function registry.
|
|
26
|
+
*
|
|
27
|
+
* LanceDB built-in providers are initialized when this public API is first
|
|
28
|
+
* used, so importing the root package does not change automatic search
|
|
29
|
+
* selection for tables without embedding metadata.
|
|
30
|
+
*/
|
|
31
|
+
function getRegistry() {
|
|
32
|
+
initializeBuiltInProviders();
|
|
33
|
+
return (0, registry_1.getRegistry)();
|
|
34
|
+
}
|
|
28
35
|
/**
|
|
29
36
|
* Create a schema with embedding functions.
|
|
30
37
|
*
|
|
@@ -60,7 +67,7 @@ function LanceSchema(fields) {
|
|
|
60
67
|
arrowFields.push(new arrow_1.Field(key, (0, sanitize_1.sanitizeType)(value), true));
|
|
61
68
|
}
|
|
62
69
|
});
|
|
63
|
-
const registry =
|
|
70
|
+
const registry = getRegistry();
|
|
64
71
|
const metadata = registry.getTableMetadata(Array.from(embeddingFunctions.values()));
|
|
65
72
|
const schema = new arrow_1.Schema(arrowFields, metadata);
|
|
66
73
|
return schema;
|
package/dist/embedding/openai.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
4
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
-
};
|
|
10
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
-
};
|
|
13
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
5
|
exports.OpenAIEmbeddingFunction = void 0;
|
|
15
6
|
const arrow_1 = require("../arrow");
|
|
16
7
|
const embedding_function_1 = require("./embedding_function");
|
|
17
8
|
const registry_1 = require("./registry");
|
|
18
|
-
|
|
9
|
+
class OpenAIEmbeddingFunction extends embedding_function_1.EmbeddingFunction {
|
|
19
10
|
#openai;
|
|
20
11
|
#modelName;
|
|
21
12
|
constructor(optionsRaw = {
|
|
@@ -85,9 +76,6 @@ let OpenAIEmbeddingFunction = class OpenAIEmbeddingFunction extends embedding_fu
|
|
|
85
76
|
});
|
|
86
77
|
return response.data[0].embedding;
|
|
87
78
|
}
|
|
88
|
-
}
|
|
79
|
+
}
|
|
89
80
|
exports.OpenAIEmbeddingFunction = OpenAIEmbeddingFunction;
|
|
90
|
-
|
|
91
|
-
(0, registry_1.register)("openai"),
|
|
92
|
-
__metadata("design:paramtypes", [Object])
|
|
93
|
-
], OpenAIEmbeddingFunction);
|
|
81
|
+
(0, registry_1.registerBuiltIn)("openai", OpenAIEmbeddingFunction);
|
|
@@ -23,6 +23,8 @@ export declare class EmbeddingFunctionRegistry {
|
|
|
23
23
|
* @throws Error if the function is already registered
|
|
24
24
|
*/
|
|
25
25
|
register<T extends EmbeddingFunctionConstructor = EmbeddingFunctionConstructor>(this: EmbeddingFunctionRegistry, alias?: string): (ctor: T) => any;
|
|
26
|
+
/** @ignore */
|
|
27
|
+
setBuiltIn<T extends EmbeddingFunctionConstructor = EmbeddingFunctionConstructor>(name: string, ctor: T): T;
|
|
26
28
|
get<T extends EmbeddingFunction<unknown>>(name: string): EmbeddingFunctionCreate<T> | undefined;
|
|
27
29
|
/**
|
|
28
30
|
* reset the registry to the initial state
|
|
@@ -31,7 +33,7 @@ export declare class EmbeddingFunctionRegistry {
|
|
|
31
33
|
/**
|
|
32
34
|
* @ignore
|
|
33
35
|
*/
|
|
34
|
-
parseFunctions(this: EmbeddingFunctionRegistry, metadata: Map<string, string>): Promise<Map<string,
|
|
36
|
+
parseFunctions(this: EmbeddingFunctionRegistry, metadata: Map<string, string>): Promise<Map<string, ResolvedEmbeddingFunctionConfig>>;
|
|
35
37
|
functionToMetadata(conf: EmbeddingFunctionConfig): Record<string, any>;
|
|
36
38
|
getTableMetadata(functions: EmbeddingFunctionConfig[]): Map<string, string>;
|
|
37
39
|
/**
|
|
@@ -58,6 +60,8 @@ export declare class EmbeddingFunctionRegistry {
|
|
|
58
60
|
getVar(name: string): string | undefined;
|
|
59
61
|
}
|
|
60
62
|
export declare function register(name?: string): (ctor: EmbeddingFunctionConstructor<EmbeddingFunction<any, import("./embedding_function").FunctionOptions>>) => any;
|
|
63
|
+
/** @ignore */
|
|
64
|
+
export declare function registerBuiltIn<T extends EmbeddingFunctionConstructor = EmbeddingFunctionConstructor>(name: string, ctor: T): T;
|
|
61
65
|
/**
|
|
62
66
|
* Utility function to get the global instance of the registry
|
|
63
67
|
* @returns `EmbeddingFunctionRegistry` The global instance of the registry
|
|
@@ -72,3 +76,19 @@ export interface EmbeddingFunctionConfig {
|
|
|
72
76
|
vectorColumn?: string;
|
|
73
77
|
function: EmbeddingFunction;
|
|
74
78
|
}
|
|
79
|
+
/** An [EmbeddingFunctionConfig] read back from table metadata, where the
|
|
80
|
+
* vector column is always recorded. */
|
|
81
|
+
export type ResolvedEmbeddingFunctionConfig = EmbeddingFunctionConfig & {
|
|
82
|
+
vectorColumn: string;
|
|
83
|
+
};
|
|
84
|
+
/** One entry of the `embedding_functions` schema metadata, with the column
|
|
85
|
+
* keys normalized across the bindings' spellings. */
|
|
86
|
+
export type EmbeddingMetadataEntry = {
|
|
87
|
+
name: string;
|
|
88
|
+
sourceColumn: string;
|
|
89
|
+
vectorColumn: string;
|
|
90
|
+
model: EmbeddingFunction["TOptions"];
|
|
91
|
+
};
|
|
92
|
+
/** The single parser for `embedding_functions` schema metadata: every reader
|
|
93
|
+
* goes through here, so the wire contract cannot fork between them. */
|
|
94
|
+
export declare function parseEmbeddingMetadata(json: string): EmbeddingMetadataEntry[];
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.EmbeddingFunctionRegistry = void 0;
|
|
6
6
|
exports.register = register;
|
|
7
|
+
exports.registerBuiltIn = registerBuiltIn;
|
|
7
8
|
exports.getRegistry = getRegistry;
|
|
9
|
+
exports.parseEmbeddingMetadata = parseEmbeddingMetadata;
|
|
8
10
|
require("reflect-metadata");
|
|
11
|
+
const builtInFunctionsKey = Symbol.for("@lancedb/lancedb::embedding-built-in-functions::v1");
|
|
9
12
|
/**
|
|
10
13
|
* This is a singleton class used to register embedding functions
|
|
11
14
|
* and fetch them by name. It also handles serializing and deserializing.
|
|
@@ -39,6 +42,12 @@ class EmbeddingFunctionRegistry {
|
|
|
39
42
|
return ctor;
|
|
40
43
|
};
|
|
41
44
|
}
|
|
45
|
+
/** @ignore */
|
|
46
|
+
setBuiltIn(name, ctor) {
|
|
47
|
+
this.#functions.set(name, ctor);
|
|
48
|
+
Reflect.defineMetadata("lancedb::embedding::name", name, ctor);
|
|
49
|
+
return ctor;
|
|
50
|
+
}
|
|
42
51
|
/**
|
|
43
52
|
* Fetch an embedding function by name
|
|
44
53
|
* @param name The name of the function
|
|
@@ -72,6 +81,7 @@ class EmbeddingFunctionRegistry {
|
|
|
72
81
|
*/
|
|
73
82
|
reset() {
|
|
74
83
|
this.#functions.clear();
|
|
84
|
+
getBuiltInFunctions(this).clear();
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
87
|
* @ignore
|
|
@@ -80,25 +90,21 @@ class EmbeddingFunctionRegistry {
|
|
|
80
90
|
if (!metadata.has("embedding_functions")) {
|
|
81
91
|
return new Map();
|
|
82
92
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
];
|
|
99
|
-
}));
|
|
100
|
-
return new Map(items);
|
|
101
|
-
}
|
|
93
|
+
const entries = parseEmbeddingMetadata(metadata.get("embedding_functions"));
|
|
94
|
+
const items = await Promise.all(entries.map(async (f) => {
|
|
95
|
+
const fn = this.get(f.name);
|
|
96
|
+
if (!fn) {
|
|
97
|
+
throw new Error(`Function "${f.name}" not found in registry`);
|
|
98
|
+
}
|
|
99
|
+
const func = await fn.create(f.model);
|
|
100
|
+
return {
|
|
101
|
+
sourceColumn: f.sourceColumn,
|
|
102
|
+
vectorColumn: f.vectorColumn,
|
|
103
|
+
function: func,
|
|
104
|
+
};
|
|
105
|
+
}));
|
|
106
|
+
// Keyed by output column: one function may serve several columns.
|
|
107
|
+
return new Map(items.map((config) => [config.vectorColumn, config]));
|
|
102
108
|
}
|
|
103
109
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
104
110
|
functionToMetadata(conf) {
|
|
@@ -148,10 +154,42 @@ class EmbeddingFunctionRegistry {
|
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
exports.EmbeddingFunctionRegistry = EmbeddingFunctionRegistry;
|
|
151
|
-
|
|
157
|
+
function getBuiltInFunctions(registry) {
|
|
158
|
+
const registryWithBuiltIns = registry;
|
|
159
|
+
let builtInFunctions = registryWithBuiltIns[builtInFunctionsKey];
|
|
160
|
+
if (builtInFunctions === undefined) {
|
|
161
|
+
builtInFunctions = new Set();
|
|
162
|
+
registryWithBuiltIns[builtInFunctionsKey] = builtInFunctions;
|
|
163
|
+
}
|
|
164
|
+
return builtInFunctions;
|
|
165
|
+
}
|
|
166
|
+
// Server bundlers can load the side-effect embedding entry points and the public
|
|
167
|
+
// embedding API from separate module graphs. Keep their registry shared.
|
|
168
|
+
const registryKey = Symbol.for("@lancedb/lancedb::embedding-function-registry::v1");
|
|
169
|
+
const registryGlobal = globalThis;
|
|
170
|
+
function getGlobalRegistry() {
|
|
171
|
+
const existingRegistry = registryGlobal[registryKey];
|
|
172
|
+
if (existingRegistry !== undefined) {
|
|
173
|
+
return existingRegistry;
|
|
174
|
+
}
|
|
175
|
+
const registry = new EmbeddingFunctionRegistry();
|
|
176
|
+
registryGlobal[registryKey] = registry;
|
|
177
|
+
return registry;
|
|
178
|
+
}
|
|
179
|
+
const _REGISTRY = getGlobalRegistry();
|
|
152
180
|
function register(name) {
|
|
153
181
|
return _REGISTRY.register(name);
|
|
154
182
|
}
|
|
183
|
+
/** @ignore */
|
|
184
|
+
function registerBuiltIn(name, ctor) {
|
|
185
|
+
const builtInFunctions = getBuiltInFunctions(_REGISTRY);
|
|
186
|
+
if (builtInFunctions.has(name)) {
|
|
187
|
+
return _REGISTRY.setBuiltIn(name, ctor);
|
|
188
|
+
}
|
|
189
|
+
_REGISTRY.register(name)(ctor);
|
|
190
|
+
builtInFunctions.add(name);
|
|
191
|
+
return ctor;
|
|
192
|
+
}
|
|
155
193
|
/**
|
|
156
194
|
* Utility function to get the global instance of the registry
|
|
157
195
|
* @returns `EmbeddingFunctionRegistry` The global instance of the registry
|
|
@@ -163,3 +201,21 @@ function register(name) {
|
|
|
163
201
|
function getRegistry() {
|
|
164
202
|
return _REGISTRY;
|
|
165
203
|
}
|
|
204
|
+
/** The single parser for `embedding_functions` schema metadata: every reader
|
|
205
|
+
* goes through here, so the wire contract cannot fork between them. */
|
|
206
|
+
function parseEmbeddingMetadata(json) {
|
|
207
|
+
const entries = JSON.parse(json);
|
|
208
|
+
const seen = new Set();
|
|
209
|
+
return entries.map((f) => {
|
|
210
|
+
const sourceColumn = f.sourceColumn ?? f.source_column;
|
|
211
|
+
const vectorColumn = f.vectorColumn ?? f.vector_column;
|
|
212
|
+
if (sourceColumn === undefined || vectorColumn === undefined) {
|
|
213
|
+
throw new Error(`Embedding function "${f.name}" metadata names no source or vector column`);
|
|
214
|
+
}
|
|
215
|
+
if (seen.has(vectorColumn)) {
|
|
216
|
+
throw new Error(`Multiple embedding configs claim vector column "${vectorColumn}"`);
|
|
217
|
+
}
|
|
218
|
+
seen.add(vectorColumn);
|
|
219
|
+
return { name: f.name, sourceColumn, vectorColumn, model: f.model };
|
|
220
|
+
});
|
|
221
|
+
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
4
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
-
};
|
|
10
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
-
};
|
|
13
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
5
|
exports.TransformersEmbeddingFunction = void 0;
|
|
15
6
|
const arrow_1 = require("../arrow");
|
|
16
7
|
const embedding_function_1 = require("./embedding_function");
|
|
17
8
|
const registry_1 = require("./registry");
|
|
18
|
-
|
|
9
|
+
class TransformersEmbeddingFunction extends embedding_function_1.EmbeddingFunction {
|
|
19
10
|
#model;
|
|
20
11
|
#tokenizer;
|
|
21
12
|
#modelName;
|
|
@@ -108,12 +99,9 @@ let TransformersEmbeddingFunction = class TransformersEmbeddingFunction extends
|
|
|
108
99
|
async computeQueryEmbeddings(data) {
|
|
109
100
|
return (await this.computeSourceEmbeddings([data]))[0];
|
|
110
101
|
}
|
|
111
|
-
}
|
|
102
|
+
}
|
|
112
103
|
exports.TransformersEmbeddingFunction = TransformersEmbeddingFunction;
|
|
113
|
-
|
|
114
|
-
(0, registry_1.register)("huggingface"),
|
|
115
|
-
__metadata("design:paramtypes", [Object])
|
|
116
|
-
], TransformersEmbeddingFunction);
|
|
104
|
+
(0, registry_1.registerBuiltIn)("huggingface", TransformersEmbeddingFunction);
|
|
117
105
|
const tensorDiv = (src, divBy) => {
|
|
118
106
|
for (let i = 0; i < src.data.length; ++i) {
|
|
119
107
|
src.data[i] /= divBy;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,16 @@ import { ConnectNamespaceOptions, ConnectionOptions, Session } from "./native.js
|
|
|
3
3
|
import { HeaderProvider } from "./header";
|
|
4
4
|
import type { BaseTokenizer } from "./indices";
|
|
5
5
|
import type { FtsToken } from "./table";
|
|
6
|
+
export { MaterializedView, MaterializedViewDefinition, MaterializedViewSelect, } from "./materialized_view";
|
|
6
7
|
export { JsHeaderProvider as NativeJsHeaderProvider } from "./native.js";
|
|
7
8
|
export { instrumentLanceDbMetrics } from "./otel";
|
|
8
|
-
export { AddColumnsSql, ConnectionOptions, ConnectNamespaceOptions, IndexStatistics, IndexConfig, ClientConfig, TimeoutConfig, RetryConfig, TlsConfig, OptimizeStats, CompactionStats, RemovalStats, TableStatistics, FragmentStatistics, FragmentSummaryStats, Tags, TagContents, BranchContents, MergeResult, AddResult, AddColumnsResult, AlterColumnsResult, UpdateFieldMetadataResult, DeleteResult, DropColumnsResult, UpdateResult, SplitCalculatedOptions, SplitRandomOptions, SplitHashOptions, SplitSequentialOptions, ShuffleOptions, OAuthConfig as NativeOAuthConfig, } from "./native.js";
|
|
9
|
+
export { AddColumnsSql, ConnectionOptions, ConnectNamespaceOptions, IndexStatistics, IndexConfig, ClientConfig, TimeoutConfig, RetryConfig, TlsConfig, OptimizeStats, CompactionStats, RemovalStats, TableStatistics, FragmentStatistics, FragmentSummaryStats, Tags, TagContents, BranchContents, MergeResult, AddResult, AddColumnsResult, RefreshColumnResult, RefreshMaterializedViewResult, AlterColumnsResult, UpdateFieldMetadataResult, DeleteResult, DropColumnsResult, UpdateResult, SplitCalculatedOptions, SplitRandomOptions, SplitHashOptions, SplitSequentialOptions, ShuffleOptions, OAuthConfig as NativeOAuthConfig, } from "./native.js";
|
|
9
10
|
export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
|
|
10
|
-
export { Connection, CreateTableOptions, TableNamesOptions, OpenTableOptions, ListNamespacesOptions, CreateNamespaceOptions, DropNamespaceOptions, ListNamespacesResponse, CreateNamespaceResponse, DropNamespaceResponse, DescribeNamespaceResponse, RenameTableOptions, } from "./connection";
|
|
11
|
+
export { Connection, CreateTableOptions, TableNamesOptions, ListTablesOptions, OpenTableOptions, ListNamespacesOptions, CreateNamespaceOptions, DropNamespaceOptions, ListNamespacesResponse, ListTablesResponse, CreateNamespaceResponse, DropNamespaceResponse, DescribeNamespaceResponse, RenameTableOptions, } from "./connection";
|
|
11
12
|
export { Job, JobDescription, JobFailureInfo, JobInfo, Session, } from "./native.js";
|
|
12
|
-
export { ExecutableQuery, Query, QueryBase, VectorQuery, TakeQuery, AnalyzePlanDistributedMetrics, QueryExecutionOptions, ColumnOrdering, FullTextSearchOptions, RecordBatchIterator, FullTextQuery, MatchQuery, PhraseQuery, BoostQuery, MultiMatchQuery, BooleanQuery, FullTextQueryType, Operator, Occur, } from "./query";
|
|
13
|
+
export { AutoQuery, ExecutableQuery, Query, QueryBase, VectorQuery, TakeQuery, AnalyzePlanDistributedMetrics, QueryExecutionOptions, ColumnOrdering, FullTextSearchOptions, RecordBatchIterator, FullTextQuery, MatchQuery, PhraseQuery, BoostQuery, MultiMatchQuery, BooleanQuery, FullTextQueryType, Operator, Occur, } from "./query";
|
|
13
14
|
export { Index, IndexOptions, IvfPqOptions, IvfRqOptions, IvfFlatOptions, HnswPqOptions, HnswSqOptions, FtsOptions, BaseTokenizer, } from "./indices";
|
|
14
|
-
export { Table, Branches, BranchColumnSummary, BranchColumnChange, BranchIndexSummary, BranchRowCountSummary,
|
|
15
|
+
export { Table, Branches, BranchColumnSummary, BranchColumnChange, BranchIndexSummary, BranchRowCountSummary, CherryPickError, BranchDiff, CherryPickPreview, CherryPickResult, AddDataOptions, UpdateOptions, OptimizeOptions, Version, WriteProgress, FtsToken, TokenizeTableOptions, LsmWriteSpec, LsmStats, BucketStats, GenerationStats, MemtableStats, ColumnAlteration, FieldMetadataUpdate, } from "./table";
|
|
15
16
|
export { HeaderProvider, StaticHeaderProvider, OAuthHeaderProvider, TokenResponse, } from "./header";
|
|
16
17
|
export { OAuthConfig, OAuthFlowType } from "./oauth";
|
|
17
18
|
export { MergeInsertBuilder, WriteExecutionOptions } from "./merge";
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.packBits = exports.rerankers = exports.Scannable = exports.PermutationBuilder = exports.permutationBuilder = exports.embedding = exports.MergeInsertBuilder = exports.OAuthFlowType = exports.OAuthHeaderProvider = exports.StaticHeaderProvider = exports.HeaderProvider = exports.Branches = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.TakeQuery = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Session = exports.Job = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.BranchContents = exports.TagContents = exports.Tags = exports.instrumentLanceDbMetrics = exports.NativeJsHeaderProvider = void 0;
|
|
5
|
+
exports.packBits = exports.rerankers = exports.Scannable = exports.PermutationBuilder = exports.permutationBuilder = exports.embedding = exports.MergeInsertBuilder = exports.OAuthFlowType = exports.OAuthHeaderProvider = exports.StaticHeaderProvider = exports.HeaderProvider = exports.Branches = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.TakeQuery = exports.VectorQuery = exports.QueryBase = exports.Query = exports.AutoQuery = exports.Session = exports.Job = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.BranchContents = exports.TagContents = exports.Tags = exports.instrumentLanceDbMetrics = exports.NativeJsHeaderProvider = exports.MaterializedView = void 0;
|
|
6
6
|
exports.tokenize = tokenize;
|
|
7
7
|
exports.connect = connect;
|
|
8
8
|
exports.connectNamespace = connectNamespace;
|
|
9
9
|
const connection_1 = require("./connection");
|
|
10
10
|
const native_js_1 = require("./native.js");
|
|
11
11
|
// Re-export native header provider for use with connectWithHeaderProvider
|
|
12
|
+
var materialized_view_1 = require("./materialized_view");
|
|
13
|
+
Object.defineProperty(exports, "MaterializedView", { enumerable: true, get: function () { return materialized_view_1.MaterializedView; } });
|
|
12
14
|
var native_js_2 = require("./native.js");
|
|
13
15
|
Object.defineProperty(exports, "NativeJsHeaderProvider", { enumerable: true, get: function () { return native_js_2.JsHeaderProvider; } });
|
|
14
16
|
// OpenTelemetry metrics bridge. Only the high-level entry point is public; the
|
|
@@ -30,6 +32,7 @@ var native_js_4 = require("./native.js");
|
|
|
30
32
|
Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return native_js_4.Job; } });
|
|
31
33
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return native_js_4.Session; } });
|
|
32
34
|
var query_1 = require("./query");
|
|
35
|
+
Object.defineProperty(exports, "AutoQuery", { enumerable: true, get: function () { return query_1.AutoQuery; } });
|
|
33
36
|
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
|
34
37
|
Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
|
|
35
38
|
Object.defineProperty(exports, "VectorQuery", { enumerable: true, get: function () { return query_1.VectorQuery; } });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RefreshMaterializedViewResult } from "./native";
|
|
2
|
+
import { Table } from "./table";
|
|
3
|
+
/** Schema metadata key holding a materialized view's definition. */
|
|
4
|
+
export declare const DEFINITION_META_KEY = "mv.definition";
|
|
5
|
+
/** The query that defines a materialized view. */
|
|
6
|
+
export interface MaterializedViewDefinition {
|
|
7
|
+
/** Name of the source table, in the same database as the view. */
|
|
8
|
+
sourceTable: string;
|
|
9
|
+
/** `[output column, SQL expression]` pairs, in view schema order. */
|
|
10
|
+
projections: [string, string][];
|
|
11
|
+
/** SQL predicate selecting the source rows the view holds. */
|
|
12
|
+
filter?: string;
|
|
13
|
+
/** Cap on the number of rows the view holds. */
|
|
14
|
+
limit?: number;
|
|
15
|
+
/** Source columns the projections and filter read. */
|
|
16
|
+
inputs: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The view's columns: column names, `[alias, SQL expression]` pairs, or a
|
|
20
|
+
* record of the same. A bare name projects itself.
|
|
21
|
+
*/
|
|
22
|
+
export type MaterializedViewSelect = (string | [string, string])[] | Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* @internal Reject a numeric option N-API would otherwise silently coerce:
|
|
25
|
+
* `Infinity` reaches Rust as 0, `1.5` as 1.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateNonNegativeInteger(value: number | undefined, name: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* @internal Normalize a select argument into `[alias, expression]` pairs.
|
|
30
|
+
* A bare name projects itself and is quoted, so any valid column name works;
|
|
31
|
+
* pair and record entries are kept verbatim because their right side is an
|
|
32
|
+
* expression.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeSelect(select?: MaterializedViewSelect): [string, string][] | undefined;
|
|
35
|
+
/** @internal Parse a definition off a table's stored schema metadata. */
|
|
36
|
+
export declare function definitionFromMetadata(metadata: Map<string, string>, name: string): MaterializedViewDefinition;
|
|
37
|
+
/**
|
|
38
|
+
* A handle on a materialized view: its table plus its definition.
|
|
39
|
+
*
|
|
40
|
+
* Obtained from {@link Connection#createMaterializedView} or
|
|
41
|
+
* {@link Connection#openMaterializedView}. The view is a normal table --
|
|
42
|
+
* queries, indexes and search all apply through {@link MaterializedView#table}
|
|
43
|
+
* -- whose contents are maintained by {@link MaterializedView#refresh}.
|
|
44
|
+
*/
|
|
45
|
+
export declare class MaterializedView {
|
|
46
|
+
private readonly inner;
|
|
47
|
+
constructor(table: Table);
|
|
48
|
+
get name(): string;
|
|
49
|
+
/** The view, as the table it is. */
|
|
50
|
+
table(): Table;
|
|
51
|
+
/** The query that defines the view, read from its stored schema. */
|
|
52
|
+
definition(): Promise<MaterializedViewDefinition>;
|
|
53
|
+
/**
|
|
54
|
+
* Recompute the view from its source.
|
|
55
|
+
*
|
|
56
|
+
* The refresh is incremental when the source's changes can be reconciled
|
|
57
|
+
* into the view -- rows added, changed or removed since the last one --
|
|
58
|
+
* and otherwise rebuilds. `full` forces a rebuild; `sourceVersion`
|
|
59
|
+
* refreshes to that source version instead of the latest.
|
|
60
|
+
*
|
|
61
|
+
* Concurrent refreshes of one view do not duplicate its rows. Two that
|
|
62
|
+
* plan the same source rows conflict on commit, and the loser throws
|
|
63
|
+
* rather than writing them a second time.
|
|
64
|
+
*/
|
|
65
|
+
refresh(options?: {
|
|
66
|
+
full?: boolean;
|
|
67
|
+
sourceVersion?: number;
|
|
68
|
+
}): Promise<RefreshMaterializedViewResult>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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.MaterializedView = exports.DEFINITION_META_KEY = void 0;
|
|
6
|
+
exports.validateNonNegativeInteger = validateNonNegativeInteger;
|
|
7
|
+
exports.normalizeSelect = normalizeSelect;
|
|
8
|
+
exports.definitionFromMetadata = definitionFromMetadata;
|
|
9
|
+
/** Schema metadata key holding a materialized view's definition. */
|
|
10
|
+
exports.DEFINITION_META_KEY = "mv.definition";
|
|
11
|
+
/**
|
|
12
|
+
* @internal Reject a numeric option N-API would otherwise silently coerce:
|
|
13
|
+
* `Infinity` reaches Rust as 0, `1.5` as 1.
|
|
14
|
+
*/
|
|
15
|
+
function validateNonNegativeInteger(value, name) {
|
|
16
|
+
if (value !== undefined && !(Number.isSafeInteger(value) && value >= 0)) {
|
|
17
|
+
throw new Error(`${name} must be a non-negative integer`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** @internal Quote a column name as a Lance SQL identifier (backticks). */
|
|
21
|
+
function quoteIdentifier(name) {
|
|
22
|
+
return "`" + name.replace(/`/g, "``") + "`";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @internal Normalize a select argument into `[alias, expression]` pairs.
|
|
26
|
+
* A bare name projects itself and is quoted, so any valid column name works;
|
|
27
|
+
* pair and record entries are kept verbatim because their right side is an
|
|
28
|
+
* expression.
|
|
29
|
+
*/
|
|
30
|
+
function normalizeSelect(select) {
|
|
31
|
+
if (select === undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(select)) {
|
|
35
|
+
return select.map((item) => typeof item === "string" ? [item, quoteIdentifier(item)] : item);
|
|
36
|
+
}
|
|
37
|
+
return Object.entries(select);
|
|
38
|
+
}
|
|
39
|
+
/** @internal Parse a definition off a table's stored schema metadata. */
|
|
40
|
+
function definitionFromMetadata(metadata, name) {
|
|
41
|
+
const raw = metadata.get(exports.DEFINITION_META_KEY);
|
|
42
|
+
if (raw === undefined) {
|
|
43
|
+
throw new Error(`Table '${name}' is not a materialized view`);
|
|
44
|
+
}
|
|
45
|
+
// biome-ignore lint/suspicious/noExplicitAny: raw JSON
|
|
46
|
+
const value = JSON.parse(raw);
|
|
47
|
+
if (value.kind !== "select") {
|
|
48
|
+
throw new Error(`materialized view '${name}' is defined by '${value.kind}', which this ` +
|
|
49
|
+
"version of lancedb cannot refresh");
|
|
50
|
+
}
|
|
51
|
+
const limit = value.limit ?? undefined;
|
|
52
|
+
// JSON.parse rounds integers past 2^53; every exact u64 parses to a safe
|
|
53
|
+
// integer and every rounded one does not, so this rejects precisely the
|
|
54
|
+
// values a number cannot carry.
|
|
55
|
+
if (limit !== undefined && !Number.isSafeInteger(limit)) {
|
|
56
|
+
throw new Error(`materialized view '${name}' has a stored limit too large to represent exactly`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
sourceTable: value.source_table,
|
|
60
|
+
// biome-ignore lint/suspicious/noExplicitAny: raw JSON
|
|
61
|
+
projections: (value.projections ?? []).map((p) => [
|
|
62
|
+
p.output,
|
|
63
|
+
p.expression,
|
|
64
|
+
]),
|
|
65
|
+
filter: value.filter ?? undefined,
|
|
66
|
+
limit,
|
|
67
|
+
inputs: value.inputs ?? [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A handle on a materialized view: its table plus its definition.
|
|
72
|
+
*
|
|
73
|
+
* Obtained from {@link Connection#createMaterializedView} or
|
|
74
|
+
* {@link Connection#openMaterializedView}. The view is a normal table --
|
|
75
|
+
* queries, indexes and search all apply through {@link MaterializedView#table}
|
|
76
|
+
* -- whose contents are maintained by {@link MaterializedView#refresh}.
|
|
77
|
+
*/
|
|
78
|
+
class MaterializedView {
|
|
79
|
+
inner;
|
|
80
|
+
constructor(table) {
|
|
81
|
+
this.inner = table;
|
|
82
|
+
}
|
|
83
|
+
get name() {
|
|
84
|
+
return this.inner.name;
|
|
85
|
+
}
|
|
86
|
+
/** The view, as the table it is. */
|
|
87
|
+
table() {
|
|
88
|
+
return this.inner;
|
|
89
|
+
}
|
|
90
|
+
/** The query that defines the view, read from its stored schema. */
|
|
91
|
+
async definition() {
|
|
92
|
+
const schema = await this.inner.schema();
|
|
93
|
+
return definitionFromMetadata(schema.metadata, this.name);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Recompute the view from its source.
|
|
97
|
+
*
|
|
98
|
+
* The refresh is incremental when the source's changes can be reconciled
|
|
99
|
+
* into the view -- rows added, changed or removed since the last one --
|
|
100
|
+
* and otherwise rebuilds. `full` forces a rebuild; `sourceVersion`
|
|
101
|
+
* refreshes to that source version instead of the latest.
|
|
102
|
+
*
|
|
103
|
+
* Concurrent refreshes of one view do not duplicate its rows. Two that
|
|
104
|
+
* plan the same source rows conflict on commit, and the loser throws
|
|
105
|
+
* rather than writing them a second time.
|
|
106
|
+
*/
|
|
107
|
+
async refresh(options) {
|
|
108
|
+
validateNonNegativeInteger(options?.sourceVersion, "sourceVersion");
|
|
109
|
+
return await this.inner.refreshMaterializedView(options?.full, options?.sourceVersion);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.MaterializedView = MaterializedView;
|