Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 8c17ad2

Browse files
committed
runtime compatible changes
1 parent 1868df0 commit 8c17ad2

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/assembly/collections.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,48 +83,55 @@ export class CollectionSearchResultObject {
8383

8484
export class CollectionClassificationResult extends CollectionResult {
8585
searchMethod: string;
86-
label: string;
87-
labelsResult: string[];
86+
labelsResult: CollectionClassificationLabelObject[];
8887
cluster: CollectionClassificationResultObject[];
8988

9089
constructor(
9190
collection: string,
9291
status: CollectionStatus,
9392
error: string,
9493
searchMethod: string,
95-
label: string,
96-
labelsResult: string[],
94+
labelsResult: CollectionClassificationLabelObject[],
9795
cluster: CollectionClassificationResultObject[],
9896
) {
9997
super(collection, status, error);
10098
this.searchMethod = searchMethod;
101-
this.label = label;
10299
this.labelsResult = labelsResult;
103100
this.cluster = cluster;
104101
}
105102
}
106103

104+
export class CollectionClassificationLabelObject {
105+
label: string;
106+
confidence: f64;
107+
108+
constructor(label: string, confidence: f64) {
109+
this.label = label;
110+
this.confidence = confidence;
111+
}
112+
}
113+
107114
export class CollectionClassificationResultObject {
108115
key: string;
109-
label: string;
116+
labels: string[];
110117
distance: f64;
111118
score: f64;
112119

113-
constructor(key: string, label: string, distance: f64, score: f64) {
120+
constructor(key: string, labels: string[], distance: f64, score: f64) {
114121
this.key = key;
115-
this.label = label;
122+
this.labels = labels;
116123
this.distance = distance;
117124
this.score = score;
118125
}
119126
}
120127

121128
// @ts-expect-error: decorator
122-
@external("hypermode", "upsertToCollection")
129+
@external("hypermode", "upsertToCollection_v2")
123130
declare function hostUpsertToCollection(
124131
collection: string,
125132
keys: string[],
126133
texts: string[],
127-
labels: string[],
134+
labels: string[][],
128135
): CollectionMutationResult;
129136

130137
// @ts-expect-error: decorator
@@ -145,8 +152,8 @@ declare function hostSearchCollection(
145152
): CollectionSearchResult;
146153

147154
// @ts-expect-error: decorator
148-
@external("hypermode", "zsClassifyCollection")
149-
declare function hostZSClassifyCollection(
155+
@external("hypermode", "nnClassifyCollection")
156+
declare function hostNnClassifyCollection(
150157
collection: string,
151158
searchMethod: string,
152159
text: string,
@@ -186,7 +193,7 @@ export function upsertBatch(
186193
collection: string,
187194
keys: string[] | null,
188195
texts: string[],
189-
labels: string[] = [],
196+
labelsArr: string[][] = [],
190197
): CollectionMutationResult {
191198
if (collection.length == 0) {
192199
console.error("Collection is empty.");
@@ -211,7 +218,7 @@ export function upsertBatch(
211218
keysArr = keys;
212219
}
213220

214-
const result = hostUpsertToCollection(collection, keysArr, texts, labels);
221+
const result = hostUpsertToCollection(collection, keysArr, texts, labelsArr);
215222
if (utils.resultIsInvalid(result)) {
216223
console.error("Error upserting to Text index.");
217224
return new CollectionMutationResult(
@@ -230,7 +237,7 @@ export function upsert(
230237
collection: string,
231238
key: string | null,
232239
text: string,
233-
label: string = "",
240+
labels: string[] = [],
234241
): CollectionMutationResult {
235242
if (collection.length == 0) {
236243
console.error("Collection is empty.");
@@ -257,12 +264,12 @@ export function upsert(
257264

258265
const texts: string[] = [text];
259266

260-
const labels: string[] = [];
261-
if (label !== "") {
262-
labels.push(label);
267+
const labelsArr: string[][] = [];
268+
if (labels != null) {
269+
labelsArr.push(labels);
263270
}
264271

265-
const result = hostUpsertToCollection(collection, keys, texts, labels);
272+
const result = hostUpsertToCollection(collection, keys, texts, labelsArr);
266273
if (utils.resultIsInvalid(result)) {
267274
console.error("Error upserting to Text index.");
268275
return new CollectionMutationResult(
@@ -353,7 +360,7 @@ export function search(
353360

354361
// fetch embedders for collection & search method, run text through it and
355362
// classify Text index for similar Texts, return the result keys
356-
export function zsClassify(
363+
export function nnClassify(
357364
collection: string,
358365
searchMethod: string,
359366
text: string,
@@ -365,20 +372,18 @@ export function zsClassify(
365372
CollectionStatus.Error,
366373
"Text is empty.",
367374
searchMethod,
368-
"",
369375
[],
370376
[],
371377
);
372378
}
373-
const result = hostZSClassifyCollection(collection, searchMethod, text);
379+
const result = hostNnClassifyCollection(collection, searchMethod, text);
374380
if (utils.resultIsInvalid(result)) {
375381
console.error("Error classifying Text index.");
376382
return new CollectionClassificationResult(
377383
collection,
378384
CollectionStatus.Error,
379385
"Error classifying Text index.",
380386
searchMethod,
381-
"",
382387
[],
383388
[],
384389
);

0 commit comments

Comments
 (0)