@hypermode/functions-as
Advanced tools
Comparing version 0.10.5 to 0.11.0-alpha1
@@ -71,2 +71,3 @@ import * as utils from "./utils"; | ||
export class CollectionSearchResultObject { | ||
namespace: string; | ||
key: string; | ||
@@ -77,3 +78,10 @@ text: string; | ||
constructor(key: string, text: string, distance: f64, score: f64) { | ||
constructor( | ||
namespace: string, | ||
key: string, | ||
text: string, | ||
distance: f64, | ||
score: f64, | ||
) { | ||
this.namespace = namespace; | ||
this.key = key; | ||
@@ -86,14 +94,61 @@ this.text = text; | ||
export class CollectionClassificationResult extends CollectionResult { | ||
searchMethod: string; | ||
labelsResult: CollectionClassificationLabelObject[]; | ||
cluster: CollectionClassificationResultObject[]; | ||
constructor( | ||
collection: string, | ||
status: CollectionStatus, | ||
error: string, | ||
searchMethod: string, | ||
labelsResult: CollectionClassificationLabelObject[], | ||
cluster: CollectionClassificationResultObject[], | ||
) { | ||
super(collection, status, error); | ||
this.searchMethod = searchMethod; | ||
this.labelsResult = labelsResult; | ||
this.cluster = cluster; | ||
} | ||
} | ||
export class CollectionClassificationLabelObject { | ||
label: string; | ||
confidence: f64; | ||
constructor(label: string, confidence: f64) { | ||
this.label = label; | ||
this.confidence = confidence; | ||
} | ||
} | ||
export class CollectionClassificationResultObject { | ||
key: string; | ||
labels: string[]; | ||
distance: f64; | ||
score: f64; | ||
constructor(key: string, labels: string[], distance: f64, score: f64) { | ||
this.key = key; | ||
this.labels = labels; | ||
this.distance = distance; | ||
this.score = score; | ||
} | ||
} | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "upsertToCollection") | ||
@external("hypermode", "upsertToCollection_v2") | ||
declare function hostUpsertToCollection( | ||
collection: string, | ||
key: string[], | ||
text: string[], | ||
namespace: string, | ||
keys: string[], | ||
texts: string[], | ||
labels: string[][], | ||
): CollectionMutationResult; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "deleteFromCollection") | ||
@external("hypermode", "deleteFromCollection_v2") | ||
declare function hostDeleteFromCollection( | ||
collection: string, | ||
namespace: string, | ||
key: string, | ||
@@ -103,5 +158,6 @@ ): CollectionMutationResult; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "searchCollection") | ||
@external("hypermode", "searchCollection_v2") | ||
declare function hostSearchCollection( | ||
collection: string, | ||
namespaces: string[], | ||
searchMethod: string, | ||
@@ -114,5 +170,15 @@ text: string, | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "recomputeSearchMethod") | ||
@external("hypermode", "nnClassifyCollection_v2") | ||
declare function hostNnClassifyCollection( | ||
collection: string, | ||
namespace: string, | ||
searchMethod: string, | ||
text: string, | ||
): CollectionClassificationResult; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "recomputeSearchMethod_v2") | ||
declare function hostRecomputeSearchMethod( | ||
collection: string, | ||
namespace: string, | ||
searchMethod: string, | ||
@@ -122,5 +188,6 @@ ): SearchMethodMutationResult; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "computeDistance") | ||
@external("hypermode", "computeDistance_v2") | ||
declare function hostComputeDistance( | ||
collection: string, | ||
namespace: string, | ||
searchMethod: string, | ||
@@ -132,5 +199,6 @@ key1: string, | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "getTextFromCollection") | ||
@external("hypermode", "getTextFromCollection_v2") | ||
declare function hostGetTextFromCollection( | ||
collection: string, | ||
namespace: string, | ||
key: string, | ||
@@ -140,7 +208,12 @@ ): string; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "getTextsFromCollection") | ||
@external("hypermode", "getTextsFromCollection_v2") | ||
declare function hostGetTextsFromCollection( | ||
collection: string, | ||
namespace: string, | ||
): Map<string, string>; | ||
// @ts-expect-error: decorator | ||
@external("hypermode", "getNamespacesFromCollection") | ||
declare function hostGetNamespacesFromCollection(collection: string): string[]; | ||
// add batch upsert | ||
@@ -151,2 +224,4 @@ export function upsertBatch( | ||
texts: string[], | ||
labelsArr: string[][] = [], | ||
namespace: string = "", | ||
): CollectionMutationResult { | ||
@@ -175,3 +250,10 @@ if (collection.length == 0) { | ||
} | ||
const result = hostUpsertToCollection(collection, keysArr, texts); | ||
const result = hostUpsertToCollection( | ||
collection, | ||
namespace, | ||
keysArr, | ||
texts, | ||
labelsArr, | ||
); | ||
if (utils.resultIsInvalid(result)) { | ||
@@ -195,2 +277,4 @@ console.error("Error upserting to Text index."); | ||
text: string, | ||
labels: string[] = [], | ||
namespace: string = "", | ||
): CollectionMutationResult { | ||
@@ -222,3 +306,11 @@ if (collection.length == 0) { | ||
const result = hostUpsertToCollection(collection, keys, texts); | ||
const labelsArr: string[][] = [labels]; | ||
const result = hostUpsertToCollection( | ||
collection, | ||
namespace, | ||
keys, | ||
texts, | ||
labelsArr, | ||
); | ||
if (utils.resultIsInvalid(result)) { | ||
@@ -240,2 +332,3 @@ console.error("Error upserting to Text index."); | ||
key: string, | ||
namespace: string = "", | ||
): CollectionMutationResult { | ||
@@ -260,3 +353,3 @@ if (collection.length == 0) { | ||
} | ||
const result = hostDeleteFromCollection(collection, key); | ||
const result = hostDeleteFromCollection(collection, namespace, key); | ||
if (utils.resultIsInvalid(result)) { | ||
@@ -283,2 +376,3 @@ console.error("Error deleting from Text index."); | ||
returnText: bool = false, | ||
namespaces: string[] = [], | ||
): CollectionSearchResult { | ||
@@ -297,2 +391,3 @@ if (text.length == 0) { | ||
collection, | ||
namespaces, | ||
searchMethod, | ||
@@ -316,5 +411,45 @@ text, | ||
// fetch embedders for collection & search method, run text through it and | ||
// classify Text index for similar Texts, return the result keys | ||
export function nnClassify( | ||
collection: string, | ||
searchMethod: string, | ||
text: string, | ||
namespace: string = "", | ||
): CollectionClassificationResult { | ||
if (text.length == 0) { | ||
console.error("Text is empty."); | ||
return new CollectionClassificationResult( | ||
collection, | ||
CollectionStatus.Error, | ||
"Text is empty.", | ||
searchMethod, | ||
[], | ||
[], | ||
); | ||
} | ||
const result = hostNnClassifyCollection( | ||
collection, | ||
namespace, | ||
searchMethod, | ||
text, | ||
); | ||
if (utils.resultIsInvalid(result)) { | ||
console.error("Error classifying Text index."); | ||
return new CollectionClassificationResult( | ||
collection, | ||
CollectionStatus.Error, | ||
"Error classifying Text index.", | ||
searchMethod, | ||
[], | ||
[], | ||
); | ||
} | ||
return result; | ||
} | ||
export function recomputeSearchMethod( | ||
collection: string, | ||
searchMethod: string, | ||
namespace: string = "", | ||
): SearchMethodMutationResult { | ||
@@ -341,3 +476,3 @@ if (collection.length == 0) { | ||
} | ||
const result = hostRecomputeSearchMethod(collection, searchMethod); | ||
const result = hostRecomputeSearchMethod(collection, namespace, searchMethod); | ||
if (utils.resultIsInvalid(result)) { | ||
@@ -364,4 +499,5 @@ console.error("Error recomputing Text index."); | ||
key2: string, | ||
namespace: string = "", | ||
): CollectionSearchResultObject { | ||
return computeDistance(collection, searchMethod, key1, key2); | ||
return computeDistance(collection, searchMethod, key1, key2, namespace); | ||
} | ||
@@ -374,23 +510,28 @@ | ||
key2: string, | ||
namespace: string = "", | ||
): CollectionSearchResultObject { | ||
if (collection.length == 0) { | ||
console.error("Collection is empty."); | ||
return new CollectionSearchResultObject("", "", 0.0, 0.0); | ||
return new CollectionSearchResultObject("", "", "", 0.0, 0.0); | ||
} | ||
if (searchMethod.length == 0) { | ||
console.error("Search method is empty."); | ||
return new CollectionSearchResultObject("", "", 0.0, 0.0); | ||
return new CollectionSearchResultObject("", "", "", 0.0, 0.0); | ||
} | ||
if (key1.length == 0) { | ||
console.error("Key1 is empty."); | ||
return new CollectionSearchResultObject("", "", 0.0, 0.0); | ||
return new CollectionSearchResultObject("", "", "", 0.0, 0.0); | ||
} | ||
if (key2.length == 0) { | ||
console.error("Key2 is empty."); | ||
return new CollectionSearchResultObject("", "", 0.0, 0.0); | ||
return new CollectionSearchResultObject("", "", "", 0.0, 0.0); | ||
} | ||
return hostComputeDistance(collection, searchMethod, key1, key2); | ||
return hostComputeDistance(collection, namespace, searchMethod, key1, key2); | ||
} | ||
export function getText(collection: string, key: string): string { | ||
export function getText( | ||
collection: string, | ||
key: string, | ||
namespace: string = "", | ||
): string { | ||
if (collection.length == 0) { | ||
@@ -404,6 +545,9 @@ console.error("Collection is empty."); | ||
} | ||
return hostGetTextFromCollection(collection, key); | ||
return hostGetTextFromCollection(collection, namespace, key); | ||
} | ||
export function getTexts(collection: string): Map<string, string> { | ||
export function getTexts( | ||
collection: string, | ||
namespace: string = "", | ||
): Map<string, string> { | ||
if (collection.length == 0) { | ||
@@ -413,3 +557,11 @@ console.error("Collection is empty."); | ||
} | ||
return hostGetTextsFromCollection(collection); | ||
return hostGetTextsFromCollection(collection, namespace); | ||
} | ||
export function getNamespaces(collection: string): string[] { | ||
if (collection.length == 0) { | ||
console.error("Collection is empty."); | ||
return []; | ||
} | ||
return hostGetNamespacesFromCollection(collection); | ||
} |
{ | ||
"name": "@hypermode/functions-as", | ||
"version": "0.10.5", | ||
"version": "0.11.0-alpha1", | ||
"description": "Hypermode library for AssemblyScript functions", | ||
@@ -19,18 +19,18 @@ "author": "Hypermode, Inc.", | ||
"@assemblyscript/wasi-shim": "^0.1.0", | ||
"@hypermode/models-as": "^0.2.2", | ||
"json-as": "^0.9.20", | ||
"@hypermode/models-as": "^0.2.3", | ||
"json-as": "^0.9.21", | ||
"xid-ts": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.8.0", | ||
"@eslint/js": "^9.9.0", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/node": "^20.14.13", | ||
"as-test": "^0.3.1", | ||
"@types/node": "^20.14.15", | ||
"as-test": "0.3.3", | ||
"assemblyscript": "^0.27.29", | ||
"assemblyscript-prettier": "^3.0.1", | ||
"eslint": "^9.8.0", | ||
"eslint": "^9.9.0", | ||
"prettier": "^3.3.3", | ||
"semver": "^7.6.3", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^8.0.0", | ||
"typescript-eslint": "^8.1.0", | ||
"visitor-as": "^0.11.4" | ||
@@ -37,0 +37,0 @@ }, |
67388
2168
Updated@hypermode/models-as@^0.2.3
Updatedjson-as@^0.9.21