sst 3.0.1-7 → 3.0.1-9
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/resource.d.ts +0 -3
- package/dist/resource.js +10 -4
- package/dist/vector-client.d.ts +126 -0
- package/dist/vector-client.js +38 -0
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/resource.d.ts
CHANGED
package/dist/resource.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const $SST_LINKS = {};
|
|
2
|
+
export const Resource = new Proxy({}, {
|
|
2
3
|
get(target, prop) {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
// Read from environment first
|
|
5
|
+
const envName = `SST_RESOURCE_${prop}`;
|
|
6
|
+
if (process.env[envName]) {
|
|
7
|
+
return JSON.parse(process.env[envName]);
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
if (prop in $SST_LINKS) {
|
|
10
|
+
return $SST_LINKS[prop];
|
|
11
|
+
}
|
|
12
|
+
throw new Error(`"${prop}" is not linked`);
|
|
7
13
|
},
|
|
8
14
|
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export type IngestEvent = {
|
|
2
|
+
/**
|
|
3
|
+
* The external ID of the event.
|
|
4
|
+
* If the external ID already exists, the embedding and metadata will be updated.
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* {
|
|
8
|
+
* externalId: "37043bc3-2166-437d-bbf8-a2238d7a5796"
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
externalId: string;
|
|
12
|
+
/**
|
|
13
|
+
* The text used to generate the embedding vector.
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* {
|
|
17
|
+
* text: "This is an example text.",
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
text: string;
|
|
22
|
+
/**
|
|
23
|
+
* The base64 representation of the image used to generate the embedding vector.
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* {
|
|
27
|
+
* image: await fs.readFile("./file.jpg").toString("base64"),
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
image?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Additional metadata for the event in JSON format.
|
|
34
|
+
* This metadata will be used to filter the retrieval of events.
|
|
35
|
+
* @example
|
|
36
|
+
* ```js
|
|
37
|
+
* {
|
|
38
|
+
* metadata: {
|
|
39
|
+
* key1: "value1",
|
|
40
|
+
* key2: "value2"
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
metadata: any;
|
|
46
|
+
};
|
|
47
|
+
export type RetrieveEvent = {
|
|
48
|
+
/**
|
|
49
|
+
* The prompt used to retrieve events.
|
|
50
|
+
* @example
|
|
51
|
+
* ```js
|
|
52
|
+
* {
|
|
53
|
+
* prompt: "This is an example text.",
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
prompt: string;
|
|
58
|
+
/**
|
|
59
|
+
* The metadata used to filter the retrieval of events.
|
|
60
|
+
* Only events with metadata that match the provided fields will be returned.
|
|
61
|
+
* @example
|
|
62
|
+
* ```js
|
|
63
|
+
* {
|
|
64
|
+
* metadata: {
|
|
65
|
+
* type: "movie",
|
|
66
|
+
* name: "Spiderman",
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
* This will match event with metadata:
|
|
71
|
+
* {
|
|
72
|
+
* type: "movie",
|
|
73
|
+
* name: "Spiderman",
|
|
74
|
+
* release: "2001",
|
|
75
|
+
* }
|
|
76
|
+
* But this will not match event with metadata:
|
|
77
|
+
* {
|
|
78
|
+
* type: "book",
|
|
79
|
+
* name: "Spiderman",
|
|
80
|
+
* release: "1962",
|
|
81
|
+
* }
|
|
82
|
+
*/
|
|
83
|
+
metadata: any;
|
|
84
|
+
/**
|
|
85
|
+
* The threshold of similarity between the prompt and the retrieved events.
|
|
86
|
+
* Only events with a similarity score higher than the threshold will be returned.
|
|
87
|
+
* Expected value is between 0 and 1.
|
|
88
|
+
* - 0 means the prompt and the retrieved events are completely different.
|
|
89
|
+
* - 1 means the prompt and the retrieved events are identical.
|
|
90
|
+
* @default 0
|
|
91
|
+
* @example
|
|
92
|
+
* ```js
|
|
93
|
+
* {
|
|
94
|
+
* threshold: 0.5,
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
threshold?: number;
|
|
99
|
+
/**
|
|
100
|
+
* The number of results to return.
|
|
101
|
+
* @default 10
|
|
102
|
+
* @example
|
|
103
|
+
* ```js
|
|
104
|
+
* {
|
|
105
|
+
* count: 10,
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
count?: number;
|
|
110
|
+
};
|
|
111
|
+
export type RemoveEvent = {
|
|
112
|
+
/**
|
|
113
|
+
* The external ID of the event to remove.
|
|
114
|
+
* @example
|
|
115
|
+
* ```js
|
|
116
|
+
* {
|
|
117
|
+
* externalId: "37043bc3-2166-437d-bbf8-a2238d7a5796"
|
|
118
|
+
* }
|
|
119
|
+
*/
|
|
120
|
+
externalId: string;
|
|
121
|
+
};
|
|
122
|
+
export declare const VectorClient: (name: string) => {
|
|
123
|
+
ingest: (event: IngestEvent) => Promise<any>;
|
|
124
|
+
retrieve: (event: RetrieveEvent) => Promise<any>;
|
|
125
|
+
delete: (event: RemoveEvent) => Promise<any>;
|
|
126
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LambdaClient, InvokeCommand, } from "@aws-sdk/client-lambda";
|
|
2
|
+
import { Resource } from "./resource.js";
|
|
3
|
+
const lambda = new LambdaClient();
|
|
4
|
+
export const VectorClient = (name) => {
|
|
5
|
+
return {
|
|
6
|
+
ingest: async (event) => {
|
|
7
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
8
|
+
FunctionName: Resource[name].ingestorFunctionName,
|
|
9
|
+
Payload: JSON.stringify(event),
|
|
10
|
+
}));
|
|
11
|
+
return parsePayload(ret, "Failed to ingest into the vector db");
|
|
12
|
+
},
|
|
13
|
+
retrieve: async (event) => {
|
|
14
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
15
|
+
FunctionName: Resource[name].retrieverFunctionName,
|
|
16
|
+
Payload: JSON.stringify(event),
|
|
17
|
+
}));
|
|
18
|
+
return parsePayload(ret, "Failed to retrieve from the vector db");
|
|
19
|
+
},
|
|
20
|
+
delete: async (event) => {
|
|
21
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
22
|
+
FunctionName: Resource[name].removerFunctionName,
|
|
23
|
+
Payload: JSON.stringify(event),
|
|
24
|
+
}));
|
|
25
|
+
return parsePayload(ret, "Failed to remove from the vector db");
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
function parsePayload(output, message) {
|
|
30
|
+
const payload = JSON.parse(Buffer.from(output.Payload).toString());
|
|
31
|
+
// Set cause to the payload so that it can be logged in CloudWatch
|
|
32
|
+
if (output.FunctionError) {
|
|
33
|
+
const e = new Error(message);
|
|
34
|
+
e.cause = payload;
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
return payload;
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "3.0.1-
|
|
5
|
+
"version": "3.0.1-9",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/index.js",
|
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@aws-sdk/client-lambda": "3.478.0"
|
|
21
|
+
},
|
|
19
22
|
"scripts": {
|
|
20
23
|
"build": "tsc",
|
|
24
|
+
"dev": "tsc -w",
|
|
21
25
|
"release": "pnpm build && pnpm version prerelease && pnpm publish --no-git-checks --tag=ion --access=public"
|
|
22
26
|
}
|
|
23
27
|
}
|