@moss-dev/moss-web 1.0.1 → 1.2.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.
- package/README.md +85 -4
- package/dist/auth/authenticator.interface.d.ts +8 -0
- package/dist/auth/authenticator.interface.js +1 -0
- package/dist/auth/caching.authenticator.d.ts +11 -0
- package/dist/auth/caching.authenticator.js +35 -0
- package/dist/client.d.ts +43 -6
- package/dist/client.js +212 -75
- package/dist/embedder.d.ts +13 -11
- package/dist/embedder.js +86 -66
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/model-artifact-ownership.d.ts +18 -0
- package/dist/model-artifact-ownership.js +106 -0
- package/dist/model-config.d.ts +3 -0
- package/dist/model-config.js +8 -0
- package/dist/model-delivery.d.ts +61 -0
- package/dist/model-delivery.js +279 -0
- package/dist/sha256.d.ts +14 -0
- package/dist/sha256.js +152 -0
- package/dist/types.d.ts +19 -1
- package/dist/wasm-runtime-capability.d.ts +14 -0
- package/dist/wasm-runtime-capability.js +68 -0
- package/package.json +7 -7
- package/dist/query-model.d.ts +0 -9
- package/dist/query-model.js +0 -17
package/dist/sha256.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 helpers for verifying downloaded model artifacts.
|
|
3
|
+
*
|
|
4
|
+
* Web Crypto is preferred, but `crypto.subtle` only exists in secure
|
|
5
|
+
* contexts (HTTPS or localhost). Apps served over plain HTTP on a LAN or
|
|
6
|
+
* intranet host would otherwise lose model loading entirely, so a pure-JS
|
|
7
|
+
* implementation backs it up. Verification is never skipped, and the
|
|
8
|
+
* fallback hashes the model bytes in place without a padded full copy.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
11
|
+
/** Incremental SHA-256 over disjoint views. Does not concatenate the parts. */
|
|
12
|
+
export declare function sha256HexParts(parts: Uint8Array[]): Promise<string>;
|
|
13
|
+
/** Pure-JS SHA-256 (FIPS 180-4). Exported for direct testing. */
|
|
14
|
+
export declare function sha256FallbackHex(bytes: Uint8Array): Promise<string>;
|
package/dist/sha256.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 helpers for verifying downloaded model artifacts.
|
|
3
|
+
*
|
|
4
|
+
* Web Crypto is preferred, but `crypto.subtle` only exists in secure
|
|
5
|
+
* contexts (HTTPS or localhost). Apps served over plain HTTP on a LAN or
|
|
6
|
+
* intranet host would otherwise lose model loading entirely, so a pure-JS
|
|
7
|
+
* implementation backs it up. Verification is never skipped, and the
|
|
8
|
+
* fallback hashes the model bytes in place without a padded full copy.
|
|
9
|
+
*/
|
|
10
|
+
export async function sha256Hex(bytes) {
|
|
11
|
+
const subtle = globalThis.crypto?.subtle;
|
|
12
|
+
if (subtle) {
|
|
13
|
+
// `digest` accepts an ArrayBufferView and respects its offset/length,
|
|
14
|
+
// so the bytes are hashed in place without an extra full-size copy.
|
|
15
|
+
// Only a SharedArrayBuffer-backed view (which Web Crypto rejects)
|
|
16
|
+
// needs a copy first.
|
|
17
|
+
const input = bytes.buffer instanceof ArrayBuffer
|
|
18
|
+
? bytes
|
|
19
|
+
: bytes.slice();
|
|
20
|
+
const digest = new Uint8Array(await subtle.digest("SHA-256", input));
|
|
21
|
+
return toHex(digest);
|
|
22
|
+
}
|
|
23
|
+
return sha256FallbackHex(bytes);
|
|
24
|
+
}
|
|
25
|
+
/** Incremental SHA-256 over disjoint views. Does not concatenate the parts. */
|
|
26
|
+
export async function sha256HexParts(parts) {
|
|
27
|
+
const h = new Uint32Array(INITIAL_HASH);
|
|
28
|
+
const w = new Uint32Array(64);
|
|
29
|
+
const remainder = new Uint8Array(64);
|
|
30
|
+
let remainderLen = 0;
|
|
31
|
+
let totalLength = 0;
|
|
32
|
+
let blocks = 0;
|
|
33
|
+
const blocksPerSlice = 16384;
|
|
34
|
+
const compressBlock = async (view, offset) => {
|
|
35
|
+
compress(h, w, view, offset);
|
|
36
|
+
blocks += 1;
|
|
37
|
+
if (blocks % blocksPerSlice === 0) {
|
|
38
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (const part of parts) {
|
|
42
|
+
totalLength += part.length;
|
|
43
|
+
let offset = 0;
|
|
44
|
+
if (remainderLen > 0) {
|
|
45
|
+
const need = 64 - remainderLen;
|
|
46
|
+
if (part.length < need) {
|
|
47
|
+
remainder.set(part, remainderLen);
|
|
48
|
+
remainderLen += part.length;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
remainder.set(part.subarray(0, need), remainderLen);
|
|
52
|
+
await compressBlock(new DataView(remainder.buffer), 0);
|
|
53
|
+
remainderLen = 0;
|
|
54
|
+
offset = need;
|
|
55
|
+
}
|
|
56
|
+
const remaining = part.length - offset;
|
|
57
|
+
const fullBlocks = Math.floor(remaining / 64);
|
|
58
|
+
if (fullBlocks > 0) {
|
|
59
|
+
const data = new DataView(part.buffer, part.byteOffset + offset, fullBlocks * 64);
|
|
60
|
+
for (let block = 0; block < fullBlocks; block++) {
|
|
61
|
+
await compressBlock(data, block * 64);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const tail = offset + fullBlocks * 64;
|
|
65
|
+
remainderLen = part.length - tail;
|
|
66
|
+
if (remainderLen > 0) {
|
|
67
|
+
remainder.set(part.subarray(tail));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const padded = new Uint8Array(remainderLen + 8 >= 64 ? 128 : 64);
|
|
71
|
+
padded.set(remainder.subarray(0, remainderLen));
|
|
72
|
+
padded[remainderLen] = 0x80;
|
|
73
|
+
const paddedView = new DataView(padded.buffer);
|
|
74
|
+
const bitLength = totalLength * 8;
|
|
75
|
+
paddedView.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296), false);
|
|
76
|
+
paddedView.setUint32(padded.length - 4, bitLength >>> 0, false);
|
|
77
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
78
|
+
compress(h, w, paddedView, offset);
|
|
79
|
+
}
|
|
80
|
+
const digest = new Uint8Array(32);
|
|
81
|
+
const digestView = new DataView(digest.buffer);
|
|
82
|
+
for (let i = 0; i < 8; i++)
|
|
83
|
+
digestView.setUint32(i * 4, h[i], false);
|
|
84
|
+
return toHex(digest);
|
|
85
|
+
}
|
|
86
|
+
/** Pure-JS SHA-256 (FIPS 180-4). Exported for direct testing. */
|
|
87
|
+
export async function sha256FallbackHex(bytes) {
|
|
88
|
+
return sha256HexParts([bytes]);
|
|
89
|
+
}
|
|
90
|
+
function compress(h, w, data, offset) {
|
|
91
|
+
for (let i = 0; i < 16; i++)
|
|
92
|
+
w[i] = data.getUint32(offset + i * 4, false);
|
|
93
|
+
for (let i = 16; i < 64; i++) {
|
|
94
|
+
const x = w[i - 15];
|
|
95
|
+
const y = w[i - 2];
|
|
96
|
+
const s0 = (rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3)) >>> 0;
|
|
97
|
+
const s1 = (rotr(y, 17) ^ rotr(y, 19) ^ (y >>> 10)) >>> 0;
|
|
98
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
|
|
99
|
+
}
|
|
100
|
+
let a = h[0];
|
|
101
|
+
let b = h[1];
|
|
102
|
+
let c = h[2];
|
|
103
|
+
let d = h[3];
|
|
104
|
+
let e = h[4];
|
|
105
|
+
let f = h[5];
|
|
106
|
+
let g = h[6];
|
|
107
|
+
let hh = h[7];
|
|
108
|
+
for (let i = 0; i < 64; i++) {
|
|
109
|
+
const s1 = (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) >>> 0;
|
|
110
|
+
const ch = ((e & f) ^ (~e & g)) >>> 0;
|
|
111
|
+
const t1 = (hh + s1 + ch + ROUND_CONSTANTS[i] + w[i]) >>> 0;
|
|
112
|
+
const s0 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) >>> 0;
|
|
113
|
+
const maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0;
|
|
114
|
+
const t2 = (s0 + maj) >>> 0;
|
|
115
|
+
hh = g;
|
|
116
|
+
g = f;
|
|
117
|
+
f = e;
|
|
118
|
+
e = (d + t1) >>> 0;
|
|
119
|
+
d = c;
|
|
120
|
+
c = b;
|
|
121
|
+
b = a;
|
|
122
|
+
a = (t1 + t2) >>> 0;
|
|
123
|
+
}
|
|
124
|
+
h[0] = (h[0] + a) >>> 0;
|
|
125
|
+
h[1] = (h[1] + b) >>> 0;
|
|
126
|
+
h[2] = (h[2] + c) >>> 0;
|
|
127
|
+
h[3] = (h[3] + d) >>> 0;
|
|
128
|
+
h[4] = (h[4] + e) >>> 0;
|
|
129
|
+
h[5] = (h[5] + f) >>> 0;
|
|
130
|
+
h[6] = (h[6] + g) >>> 0;
|
|
131
|
+
h[7] = (h[7] + hh) >>> 0;
|
|
132
|
+
}
|
|
133
|
+
function rotr(value, bits) {
|
|
134
|
+
return ((value >>> bits) | (value << (32 - bits))) >>> 0;
|
|
135
|
+
}
|
|
136
|
+
function toHex(digest) {
|
|
137
|
+
return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
138
|
+
}
|
|
139
|
+
const INITIAL_HASH = [
|
|
140
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
141
|
+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
142
|
+
];
|
|
143
|
+
const ROUND_CONSTANTS = new Uint32Array([
|
|
144
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
145
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
146
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
147
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
148
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
149
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
150
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
151
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
152
|
+
]);
|
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface MossClientOptions {
|
|
|
4
4
|
model?: MossModel;
|
|
5
5
|
wasmUrl?: string;
|
|
6
6
|
onnxWasmPath?: string;
|
|
7
|
+
modelArtifactOrigin?: string;
|
|
7
8
|
}
|
|
8
9
|
export interface ModelRef {
|
|
9
10
|
id: string;
|
|
@@ -18,12 +19,21 @@ export interface IndexInfo {
|
|
|
18
19
|
createdAt?: string;
|
|
19
20
|
updatedAt?: string;
|
|
20
21
|
model: ModelRef;
|
|
22
|
+
modelArtifactVersion?: string;
|
|
23
|
+
manifestSha256?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ModelArtifactIdentity {
|
|
26
|
+
modelId: MossModel;
|
|
27
|
+
version: string;
|
|
28
|
+
manifestSha256: string;
|
|
21
29
|
}
|
|
22
30
|
export interface QueryResultDocumentInfo {
|
|
23
31
|
id: string;
|
|
24
32
|
text: string;
|
|
25
33
|
metadata?: Record<string, string>;
|
|
26
34
|
score: number;
|
|
35
|
+
/** Source index. Set on multi-index results; absent for single-index. */
|
|
36
|
+
indexName?: string;
|
|
27
37
|
}
|
|
28
38
|
export interface SearchResult {
|
|
29
39
|
docs: QueryResultDocumentInfo[];
|
|
@@ -68,6 +78,9 @@ export interface RefreshResult {
|
|
|
68
78
|
previousUpdatedAt: string;
|
|
69
79
|
newUpdatedAt: string;
|
|
70
80
|
wasUpdated: boolean;
|
|
81
|
+
modelId?: string;
|
|
82
|
+
modelArtifactVersion?: string;
|
|
83
|
+
manifestSha256?: string;
|
|
71
84
|
}
|
|
72
85
|
export interface DocumentInfo {
|
|
73
86
|
id: string;
|
|
@@ -94,7 +107,7 @@ export interface ParseFileInput {
|
|
|
94
107
|
contentType: string;
|
|
95
108
|
}
|
|
96
109
|
export type JobStatus = "pending_upload" | "uploading" | "building" | "completed" | "failed";
|
|
97
|
-
export type JobPhase = "downloading" | "deserializing" | "generating_embeddings" | "building_index" | "uploading" | "cleanup" | "waiting_for_parser" | "parsing" | "parsing_complete" | "queued";
|
|
110
|
+
export type JobPhase = "downloading" | "deserializing" | "generating_embeddings" | "building_index" | "uploading" | "cleanup" | "waiting_for_parser" | "parsing" | "parsing_complete" | "queued" | "crawling" | "parsing_documents";
|
|
98
111
|
export interface JobProgress {
|
|
99
112
|
jobId: string;
|
|
100
113
|
status: JobStatus;
|
|
@@ -118,4 +131,9 @@ export interface LoadIndexOptions {
|
|
|
118
131
|
autoRefresh?: boolean;
|
|
119
132
|
pollingIntervalInSeconds?: number;
|
|
120
133
|
}
|
|
134
|
+
/** Outcome of a bulk load. Indexes that succeed are kept even if others fail. */
|
|
135
|
+
export interface LoadIndexesResult {
|
|
136
|
+
loaded: string[];
|
|
137
|
+
failed: Record<string, string>;
|
|
138
|
+
}
|
|
121
139
|
export type ISODate = string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MetadataFilter, ModelArtifactIdentity, SearchResult } from "./types.js";
|
|
2
|
+
export interface ProvenanceAwareIndexManager {
|
|
3
|
+
queryWithModelIdentity(indexName: string, query: string, embedding: Float32Array, modelId: string, modelArtifactVersion: string, manifestSha256: string, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined): Promise<SearchResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare function provenanceAwareIndexManager(manager: unknown): ProvenanceAwareIndexManager | null;
|
|
6
|
+
export declare function requireProvenanceAwareIndexManager(manager: unknown): ProvenanceAwareIndexManager;
|
|
7
|
+
export interface MultiIndexIndexManager {
|
|
8
|
+
queryMultiIndex(indexNames: string[], query: string, embedding: Float32Array, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined): Promise<SearchResult>;
|
|
9
|
+
queryMultiIndexWithModelIdentity(indexNames: string[], query: string, embedding: Float32Array, modelId: string, modelArtifactVersion: string, manifestSha256: string, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined): Promise<SearchResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare function multiIndexIndexManager(manager: unknown): MultiIndexIndexManager | null;
|
|
12
|
+
export declare function requireMultiIndexIndexManager(manager: unknown): MultiIndexIndexManager;
|
|
13
|
+
export declare function exactModelArtifactIdentity(modelId: string, version?: string, manifestSha256?: string): ModelArtifactIdentity | null;
|
|
14
|
+
export declare function queryWithResolvedModelIdentity(manager: unknown, identity: ModelArtifactIdentity | null, indexName: string, query: string, embedding: Float32Array, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined): Promise<SearchResult>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export function provenanceAwareIndexManager(manager) {
|
|
2
|
+
if (typeof manager !== "object"
|
|
3
|
+
|| manager === null
|
|
4
|
+
|| typeof manager.queryWithModelIdentity !== "function") {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return manager;
|
|
8
|
+
}
|
|
9
|
+
export function requireProvenanceAwareIndexManager(manager) {
|
|
10
|
+
const capable = provenanceAwareIndexManager(manager);
|
|
11
|
+
if (!capable) {
|
|
12
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot bind text inference to an exact model artifact; use queryWithEmbedding");
|
|
13
|
+
}
|
|
14
|
+
return capable;
|
|
15
|
+
}
|
|
16
|
+
const MULTI_INDEX_METHODS = [
|
|
17
|
+
"queryMultiIndex",
|
|
18
|
+
"queryMultiIndexWithModelIdentity",
|
|
19
|
+
];
|
|
20
|
+
export function multiIndexIndexManager(manager) {
|
|
21
|
+
if (typeof manager !== "object" || manager === null)
|
|
22
|
+
return null;
|
|
23
|
+
const candidate = manager;
|
|
24
|
+
for (const method of MULTI_INDEX_METHODS) {
|
|
25
|
+
if (typeof candidate[method] !== "function")
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return manager;
|
|
29
|
+
}
|
|
30
|
+
export function requireMultiIndexIndexManager(manager) {
|
|
31
|
+
const capable = multiIndexIndexManager(manager);
|
|
32
|
+
if (!capable) {
|
|
33
|
+
throw new Error("The installed @moss-dev/moss-wasm does not support multi-index operations (queryMultiIndex). Upgrade @moss-dev/moss-wasm.");
|
|
34
|
+
}
|
|
35
|
+
return capable;
|
|
36
|
+
}
|
|
37
|
+
export function exactModelArtifactIdentity(modelId, version, manifestSha256) {
|
|
38
|
+
if (modelId === "custom")
|
|
39
|
+
return null;
|
|
40
|
+
if (modelId !== "moss-minilm" && modelId !== "moss-mediumlm") {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!version
|
|
44
|
+
|| !manifestSha256
|
|
45
|
+
|| version.trim() !== version
|
|
46
|
+
|| version === "."
|
|
47
|
+
|| version === ".."
|
|
48
|
+
|| /[\\/?#%\u0000-\u001f\u007f]/.test(version)
|
|
49
|
+
|| !/^[0-9a-f]{64}$/.test(manifestSha256)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return { modelId, version, manifestSha256 };
|
|
53
|
+
}
|
|
54
|
+
export function queryWithResolvedModelIdentity(manager, identity, indexName, query, embedding, topK, alpha, filter) {
|
|
55
|
+
if (identity) {
|
|
56
|
+
const capable = provenanceAwareIndexManager(manager);
|
|
57
|
+
if (!capable) {
|
|
58
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot bind this foundation query embedding to its exact model artifact identity");
|
|
59
|
+
}
|
|
60
|
+
return capable.queryWithModelIdentity(indexName, query, embedding, identity.modelId, identity.version, identity.manifestSha256, topK, alpha, filter);
|
|
61
|
+
}
|
|
62
|
+
if (typeof manager !== "object"
|
|
63
|
+
|| manager === null
|
|
64
|
+
|| typeof manager.query !== "function") {
|
|
65
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot query this index");
|
|
66
|
+
}
|
|
67
|
+
return manager.query(indexName, query, embedding, topK, alpha, filter);
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moss-dev/moss-web",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Moss browser SDK — in-browser semantic search powered by WASM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"clean": "rm -rf dist",
|
|
23
23
|
"prepack": "npm run clean && npm run build",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"samples": "npx vite",
|
|
25
|
+
"test": "npm run build && node --test"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@moss-dev/moss-wasm": "0.
|
|
29
|
-
"onnxruntime-web": "^1.
|
|
28
|
+
"@moss-dev/moss-wasm": "0.15.0",
|
|
29
|
+
"onnxruntime-web": "^1.27.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typescript": "^
|
|
33
|
-
"vite": "^8.
|
|
32
|
+
"typescript": "^6.0.3",
|
|
33
|
+
"vite": "^8.1.3"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"moss",
|
package/dist/query-model.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MossModel } from "./types";
|
|
2
|
-
export declare const SUPPORTED_MODELS: readonly MossModel[];
|
|
3
|
-
export declare function isSupportedModel(id: string): id is MossModel;
|
|
4
|
-
/**
|
|
5
|
-
* Pick the embedding model for a query. The loaded index's model wins when
|
|
6
|
-
* known; a missing model id falls back to the configured client model.
|
|
7
|
-
* A known-but-unsupported model has no browser embedder and cannot be queried.
|
|
8
|
-
*/
|
|
9
|
-
export declare function resolveQueryModel(indexModelId: string | null | undefined, configuredModel: MossModel): MossModel;
|
package/dist/query-model.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const SUPPORTED_MODELS = ["moss-minilm", "moss-mediumlm"];
|
|
2
|
-
export function isSupportedModel(id) {
|
|
3
|
-
return SUPPORTED_MODELS.includes(id);
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Pick the embedding model for a query. The loaded index's model wins when
|
|
7
|
-
* known; a missing model id falls back to the configured client model.
|
|
8
|
-
* A known-but-unsupported model has no browser embedder and cannot be queried.
|
|
9
|
-
*/
|
|
10
|
-
export function resolveQueryModel(indexModelId, configuredModel) {
|
|
11
|
-
if (indexModelId == null || indexModelId === "")
|
|
12
|
-
return configuredModel;
|
|
13
|
-
if (isSupportedModel(indexModelId))
|
|
14
|
-
return indexModelId;
|
|
15
|
-
throw new Error(`Index was built with model "${indexModelId}", which has no browser embedder. ` +
|
|
16
|
-
`Query this index through the Moss service SDK instead.`);
|
|
17
|
-
}
|