oblaka-iac 0.0.7 → 0.0.8
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/package.json +1 -1
- package/src/resources/index.ts +3 -0
- package/src/resources/vectorize.ts +71 -0
- package/src/types.ts +1 -0
package/package.json
CHANGED
package/src/resources/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { DurableObjectDestroyer } from './do'
|
|
|
5
5
|
import { KVNamespaceDestroyer } from './kv'
|
|
6
6
|
import { QueueDestroyer } from './queues'
|
|
7
7
|
import { R2BucketDestroyer } from './r2'
|
|
8
|
+
import { VectorizeIndexDestroyer } from './vectorize'
|
|
8
9
|
import { WorkerDestroyer } from './worker'
|
|
9
10
|
import { WorkflowDestroyer } from './workflow'
|
|
10
11
|
|
|
@@ -18,6 +19,7 @@ export * from './kv'
|
|
|
18
19
|
export * from './queues'
|
|
19
20
|
export * from './r2'
|
|
20
21
|
export * from './service-reference'
|
|
22
|
+
export * from './vectorize'
|
|
21
23
|
export * from './version-metadata'
|
|
22
24
|
export * from './worker'
|
|
23
25
|
export * from './workflow'
|
|
@@ -31,5 +33,6 @@ export const destroyers: Destroyers = {
|
|
|
31
33
|
queue: QueueDestroyer,
|
|
32
34
|
r2_bucket: R2BucketDestroyer,
|
|
33
35
|
workflow: WorkflowDestroyer,
|
|
36
|
+
vectorize_index: VectorizeIndexDestroyer,
|
|
34
37
|
worker: WorkerDestroyer,
|
|
35
38
|
} satisfies Record<ResourceKind, ResourceDestroyer<any>>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { BindableResource, Config, Context, ResourceDestroyer } from '../types'
|
|
2
|
+
|
|
3
|
+
export type VectorizeMetric = 'cosine' | 'euclidean' | 'dot-product'
|
|
4
|
+
|
|
5
|
+
export interface VectorizeIndexState {
|
|
6
|
+
name: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class VectorizeIndex implements BindableResource<VectorizeIndexState> {
|
|
10
|
+
constructor(
|
|
11
|
+
public readonly options: {
|
|
12
|
+
name: string
|
|
13
|
+
config: {
|
|
14
|
+
dimensions: number
|
|
15
|
+
metric: VectorizeMetric
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
getId() {
|
|
21
|
+
return {
|
|
22
|
+
resource: 'vectorize_index' as const,
|
|
23
|
+
id: this.options.name,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
configureBinding(args: { config: Config; binding: string; state?: VectorizeIndexState; env: string }): Config {
|
|
28
|
+
return {
|
|
29
|
+
...args.config,
|
|
30
|
+
vectorize: [
|
|
31
|
+
...args.config?.vectorize ?? [],
|
|
32
|
+
{
|
|
33
|
+
binding: args.binding,
|
|
34
|
+
index_name: args.state?.name || this.options.name,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async apply(args: { state?: VectorizeIndexState; context: Context; dryRun: boolean }): Promise<VectorizeIndexState> {
|
|
41
|
+
if (args.state) {
|
|
42
|
+
return args.state
|
|
43
|
+
}
|
|
44
|
+
const remoteName = `${args.context.env}-${this.options.name}`
|
|
45
|
+
|
|
46
|
+
if (args.dryRun) {
|
|
47
|
+
return {
|
|
48
|
+
name: remoteName,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await args.context.client.fetch({
|
|
53
|
+
url: `/vectorize/v2/indexes`,
|
|
54
|
+
method: 'POST',
|
|
55
|
+
body: {
|
|
56
|
+
name: remoteName,
|
|
57
|
+
config: this.options.config,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
return {
|
|
61
|
+
name: remoteName,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const VectorizeIndexDestroyer: ResourceDestroyer<VectorizeIndexState> = async (args): Promise<void> => {
|
|
67
|
+
await args.context.client.fetch({
|
|
68
|
+
url: `/vectorize/v2/indexes/${args.state.name}`,
|
|
69
|
+
method: 'DELETE',
|
|
70
|
+
})
|
|
71
|
+
}
|