Skip to content

Commit de7feb7

Browse files
authored
feat!: Adds vector index support in CfnSearchIndex (#155)
1 parent b01233d commit de7feb7

File tree

7 files changed

+282
-83
lines changed

7 files changed

+282
-83
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 18.18.2

API.md

Lines changed: 56 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/l1-resources/search-index.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,75 @@ interface AtlasStackProps {
88
readonly clusterName: string;
99
readonly collectionName: string;
1010
readonly dbName: string;
11-
readonly indexName: string;
11+
readonly indexNameSearch: string;
12+
readonly indexNameVector: string;
1213
}
1314

1415
export class CdkTestingStack extends cdk.Stack {
1516
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1617
super(scope, id, props);
17-
1818
const atlasProps = this.getContextProps();
19+
1920
const mySearchIndex = new CfnSearchIndex(this, 'MySearchIndex', {
20-
analyzer: 'lucene.standard',
21-
clusterName: atlasProps.clusterName,
22-
collectionName: atlasProps.collectionName,
23-
database: atlasProps.dbName,
24-
mappings: {
25-
fields: [
26-
"summary:string",
27-
"description:string",
28-
"minimum_nights:number"],
29-
dynamic: false,
30-
},
31-
name: atlasProps.indexName,
32-
profile: atlasProps.profile,
33-
projectId: atlasProps.projId,
34-
searchAnalyzer: 'lucene.standard'
35-
});
21+
profile: atlasProps.profile,
22+
projectId: atlasProps.projId,
23+
clusterName: atlasProps.clusterName,
24+
name: atlasProps.indexNameSearch,
25+
collectionName: atlasProps.collectionName,
26+
database: atlasProps.dbName,
27+
searchAnalyzer: 'lucene.standard',
28+
analyzer: 'lucene.standard',
29+
mappings: {
30+
fields: JSON.stringify({
31+
employees: {
32+
type: "string",
33+
analyzer: "lucene.whitespace",
34+
}
35+
}),
36+
dynamic: false,
37+
},
38+
});
3639

40+
const myVectorSearchIndex = new CfnSearchIndex(this, 'MyVectorSearchIndex', {
41+
profile: atlasProps.profile,
42+
projectId: atlasProps.projId,
43+
clusterName: atlasProps.clusterName,
44+
name: atlasProps.indexNameVector,
45+
collectionName: atlasProps.collectionName,
46+
database: atlasProps.dbName,
47+
type: 'vectorSearch',
48+
fields: JSON.stringify([
49+
{
50+
type: "vector",
51+
path: "plot_embedding",
52+
numDimensions: 1536,
53+
similarity: "euclidean"
54+
}
55+
]),
56+
});
3757
}
3858

3959
getContextProps(): AtlasStackProps {
4060
const projId = this.node.tryGetContext('projId');
41-
if (!projId){
61+
if (!projId) {
4262
throw "No context value specified for orgId. Please specify via the cdk context."
4363
}
44-
64+
4565
const profile = this.node.tryGetContext('profile') ?? 'default';
4666
const clusterName = this.node.tryGetContext('clusterName') ?? 'Cluster0';
4767
const collectionName = this.node.tryGetContext('collectionName') ?? 'listingsAndReviews';
4868
const dbName = this.node.tryGetContext('dbName') ?? 'sample_airbnb';
49-
const indexName = this.node.tryGetContext('indexName') ?? 'searchIndex';
69+
const indexNameSearch = this.node.tryGetContext('indexName') ?? 'searchIndex';
70+
const indexNameVector = this.node.tryGetContext('indexNameVector') ?? 'searchIndexVector';
5071

5172
return {
5273
projId,
5374
profile,
5475
clusterName,
5576
collectionName,
5677
dbName,
57-
indexName
78+
indexNameSearch,
79+
indexNameVector,
5880
}
5981
}
6082
}

src/l1-resources/search-index/README.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
The official [MongoDB Atlas](https://www.mongodb.com/) AWS CDK resource for Node.js.
44

5-
> AWS CDK [L1 construct] and data structures for the [AWS CloudFormation Registry] type `MongoDB::Atlas::SearchIndex` v1.0.0.
5+
> AWS CDK [L1 construct] and data structures for the [AWS CloudFormation Registry] type `MongoDB::Atlas::SearchIndex` v3.0.0.
66
77
[L1 construct]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
88
[AWS CloudFormation Registry]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html
99

1010
## Description
1111

12-
Returns, adds, edits, and removes Atlas Search indexes. Also returns and updates user-defined analyzers.
12+
Returns, adds, edits, and removes Atlas indexes for Search or Vector search. Also returns and updates user-defined analyzers. It requires CFN resource `MongoDB::Atlas::SearchIndex` >= 3.0.0.
1313

1414
## MongoDB Atlas API Docs
1515

@@ -42,29 +42,49 @@ You can find more information about activating this type in the [AWS CloudFormat
4242
import { CfnSearchIndex } from 'awscdk-resources-mongodbatlas';
4343

4444
const mySearchIndex = new CfnSearchIndex(this, 'MySearchIndex', {
45-
analyzer: 'lucene.standard',
46-
clusterName: atlasProps.clusterName,
47-
collectionName: atlasProps.collectionName,
48-
database: atlasProps.dbName,
49-
mappings: {
50-
fields: [
51-
"summary:string",
52-
"description:string",
53-
"minimum_nights:number"],
54-
dynamic: false,
55-
},
56-
name: atlasProps.indexName,
57-
profile: atlasProps.profile,
58-
projectId: atlasProps.projId,
59-
searchAnalyzer: 'lucene.standard'
60-
});
45+
profile: atlasProps.profile,
46+
projectId: atlasProps.projId,
47+
clusterName: atlasProps.clusterName,
48+
name: atlasProps.indexNameSearch,
49+
collectionName: atlasProps.collectionName,
50+
database: atlasProps.dbName,
51+
searchAnalyzer: 'lucene.standard',
52+
analyzer: 'lucene.standard',
53+
mappings: {
54+
fields: JSON.stringify({
55+
employees: {
56+
type: "string",
57+
analyzer: "lucene.whitespace",
58+
}
59+
}),
60+
dynamic: false,
61+
},
62+
});
63+
64+
const myVectorSearchIndex = new CfnSearchIndex(this, 'MyVectorSearchIndex', {
65+
profile: atlasProps.profile,
66+
projectId: atlasProps.projId,
67+
clusterName: atlasProps.clusterName,
68+
name: atlasProps.indexNameVector,
69+
collectionName: atlasProps.collectionName,
70+
database: atlasProps.dbName,
71+
type: 'vectorSearch',
72+
fields: JSON.stringify([
73+
{
74+
type: "vector",
75+
path: "plot_embedding",
76+
numDimensions: 1536,
77+
similarity: "euclidean"
78+
}
79+
]),
80+
});
6181
```
6282

6383
## Feedback
6484

6585
This library is auto-generated and published to all supported programming languages by the [cdklabs/cdk-cloudformation] project based on the API schema published for `MongoDB::Atlas::SearchIndex`.
6686

67-
* Issues related to this generated library should be [reported here](https://github.com/cdklabs/cdk-cloudformation/issues/new?title=Issue+with+%40cdk-cloudformation%2Fmongodb-atlas-searchindex+v1.0.0).
87+
* Issues related to this generated library should be [reported here](https://github.com/cdklabs/cdk-cloudformation/issues/new?title=Issue+with+%40cdk-cloudformation%2Fmongodb-atlas-searchindex+v3.0.0).
6888
* Issues related to `MongoDB::Atlas::SearchIndex` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
6989
* Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
7090

0 commit comments

Comments
 (0)