-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVectorIndex.ts
More file actions
66 lines (60 loc) · 1.56 KB
/
VectorIndex.ts
File metadata and controls
66 lines (60 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {Construct} from "constructs"
import {CfnCollection, CfnIndex} from "aws-cdk-lib/aws-opensearchserverless"
export interface VectorIndexProps {
readonly indexName: string
readonly collection: CfnCollection
readonly endpoint: string
}
export class VectorIndex extends Construct {
public readonly cfnIndex: CfnIndex
constructor(scope: Construct, id: string, props: VectorIndexProps) {
super(scope, id)
const indexMapping: CfnIndex.MappingsProperty = {
properties: {
"bedrock-knowledge-base-default-vector": {
type: "knn_vector",
dimension: 1024,
method: {
name: "hnsw",
engine: "faiss",
parameters: {},
spaceType: "l2"
}
},
"AMAZON_BEDROCK_METADATA": {
type: "text",
index: false
},
"AMAZON_BEDROCK_TEXT_CHUNK": {
type: "text",
index: true
},
"id": {
type: "text",
index: true
},
"x-amz-bedrock-kb-data-source-id": {
type: "text",
index: true
},
"x-amz-bedrock-kb-source-uri": {
type: "text",
index: true
}
}
}
const cfnIndex = new CfnIndex(this, "MyCfnIndex", {
collectionEndpoint: props.endpoint,
indexName: props.indexName,
mappings: indexMapping,
// the properties below are optional
settings: {
index: {
knn: true,
knnAlgoParamEfSearch: 512
}
}
})
this.cfnIndex = cfnIndex
}
}