@@ -81,12 +81,50 @@ export class CollectionSearchResultObject {
81
81
}
82
82
}
83
83
84
+ export class CollectionClassificationResult extends CollectionResult {
85
+ searchMethod : string ;
86
+ label : string ;
87
+ labelsResult : string [ ] ;
88
+ cluster : CollectionClassificationResultObject [ ] ;
89
+
90
+ constructor (
91
+ collection : string ,
92
+ status : CollectionStatus ,
93
+ error : string ,
94
+ searchMethod : string ,
95
+ label : string ,
96
+ labelsResult : string [ ] ,
97
+ cluster : CollectionClassificationResultObject [ ] ,
98
+ ) {
99
+ super ( collection , status , error ) ;
100
+ this . searchMethod = searchMethod ;
101
+ this . label = label ;
102
+ this . labelsResult = labelsResult ;
103
+ this . cluster = cluster ;
104
+ }
105
+ }
106
+
107
+ export class CollectionClassificationResultObject {
108
+ key : string ;
109
+ label : string ;
110
+ distance : f64 ;
111
+ score : f64 ;
112
+
113
+ constructor ( key : string , label : string , distance : f64 , score : f64 ) {
114
+ this . key = key ;
115
+ this . label = label ;
116
+ this . distance = distance ;
117
+ this . score = score ;
118
+ }
119
+ }
120
+
84
121
// @ts -expect-error: decorator
85
122
@external ( "hypermode" , "upsertToCollection" )
86
123
declare function hostUpsertToCollection (
87
124
collection : string ,
88
- key : string [ ] ,
89
- text : string [ ] ,
125
+ keys : string [ ] ,
126
+ texts : string [ ] ,
127
+ labels : string [ ] ,
90
128
) : CollectionMutationResult ;
91
129
92
130
// @ts -expect-error: decorator
@@ -106,6 +144,14 @@ declare function hostSearchCollection(
106
144
returnText : bool ,
107
145
) : CollectionSearchResult ;
108
146
147
+ // @ts -expect-error: decorator
148
+ @external ( "hypermode" , "zsClassifyCollection" )
149
+ declare function hostZSClassifyCollection (
150
+ collection : string ,
151
+ searchMethod : string ,
152
+ text : string ,
153
+ ) : CollectionClassificationResult ;
154
+
109
155
// @ts -expect-error: decorator
110
156
@external ( "hypermode" , "recomputeSearchMethod" )
111
157
declare function hostRecomputeSearchMethod (
@@ -140,6 +186,7 @@ export function upsertBatch(
140
186
collection : string ,
141
187
keys : string [ ] | null ,
142
188
texts : string [ ] ,
189
+ labels : string [ ] = [ ] ,
143
190
) : CollectionMutationResult {
144
191
if ( collection . length == 0 ) {
145
192
console . error ( "Collection is empty." ) ;
@@ -163,7 +210,8 @@ export function upsertBatch(
163
210
if ( keys != null ) {
164
211
keysArr = keys ;
165
212
}
166
- const result = hostUpsertToCollection ( collection , keysArr , texts ) ;
213
+
214
+ const result = hostUpsertToCollection ( collection , keysArr , texts , labels ) ;
167
215
if ( utils . resultIsInvalid ( result ) ) {
168
216
console . error ( "Error upserting to Text index." ) ;
169
217
return new CollectionMutationResult (
@@ -182,6 +230,7 @@ export function upsert(
182
230
collection : string ,
183
231
key : string | null ,
184
232
text : string ,
233
+ label : string = "" ,
185
234
) : CollectionMutationResult {
186
235
if ( collection . length == 0 ) {
187
236
console . error ( "Collection is empty." ) ;
@@ -208,7 +257,12 @@ export function upsert(
208
257
209
258
const texts : string [ ] = [ text ] ;
210
259
211
- const result = hostUpsertToCollection ( collection , keys , texts ) ;
260
+ const labels : string [ ] = [ ] ;
261
+ if ( label !== "" ) {
262
+ labels . push ( label ) ;
263
+ }
264
+
265
+ const result = hostUpsertToCollection ( collection , keys , texts , labels ) ;
212
266
if ( utils . resultIsInvalid ( result ) ) {
213
267
console . error ( "Error upserting to Text index." ) ;
214
268
return new CollectionMutationResult (
@@ -297,6 +351,41 @@ export function search(
297
351
return result ;
298
352
}
299
353
354
+ // fetch embedders for collection & search method, run text through it and
355
+ // classify Text index for similar Texts, return the result keys
356
+ export function zsClassify (
357
+ collection : string ,
358
+ searchMethod : string ,
359
+ text : string ,
360
+ ) : CollectionClassificationResult {
361
+ if ( text . length == 0 ) {
362
+ console . error ( "Text is empty." ) ;
363
+ return new CollectionClassificationResult (
364
+ collection ,
365
+ CollectionStatus . Error ,
366
+ "Text is empty." ,
367
+ searchMethod ,
368
+ "" ,
369
+ [ ] ,
370
+ [ ] ,
371
+ ) ;
372
+ }
373
+ const result = hostZSClassifyCollection ( collection , searchMethod , text ) ;
374
+ if ( utils . resultIsInvalid ( result ) ) {
375
+ console . error ( "Error classifying Text index." ) ;
376
+ return new CollectionClassificationResult (
377
+ collection ,
378
+ CollectionStatus . Error ,
379
+ "Error classifying Text index." ,
380
+ searchMethod ,
381
+ "" ,
382
+ [ ] ,
383
+ [ ] ,
384
+ ) ;
385
+ }
386
+ return result ;
387
+ }
388
+
300
389
export function recomputeSearchMethod (
301
390
collection : string ,
302
391
searchMethod : string ,
0 commit comments