Repository: awslabs/generative-ai-cdk-constructs (ts)

Issue:
(bedrock): bedrock.ChunkingStrategy.DEFAULT doesn't deploy
### Describe the bug

using version 0.1.157, deploying bedrock datasource returns error: Resource handler returned message: "Cannot invoke "software.amazon.bedrock.datasource.ChunkingConfiguration.getChunkingStrategy()" because "modelChunkingConfiguration" is null"

### Expected Behavior

deploy successful

### Current Behavior

returns error complaining no ChunkingConfiguration

### Reproduction Steps

 this.dataSource = new bedrock.S3DataSource(this, 'DataSource', {
      bucket: this.knowledgeBaseBucket,
      knowledgeBase: this.knowledgeBase,
      dataSourceName: 'mydatasource',
      chunkingStrategy: bedrock.ChunkingStrategy.DEFAULT,
      maxTokens: 1000,
      overlapPercentage: 10,
    });

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.139.0 (build 2699ffd)

### Framework Version

_No response_

### Node.js Version

v20.12.2

### OS

Linux

### Language

Typescript

### Language Version

_No response_

### Region experiencing the issue

us-west-2

### Code modification

no

### Other information

_No response_

### Service quota

- [X] I have reviewed the service quotas for this construct

Pull request description:
fix(bedrock): fix default chunking strategy not deploying
Fixes #476

- Fix non deploying data source where chunking strategy is set to DEFAULT
- Add test to cover the use case
- Updated documentation
- Tested by deploying a sample stack

---
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.


Patch:
diff --git a/apidocs/enums/bedrock.ChunkingStrategy.md b/apidocs/enums/bedrock.ChunkingStrategy.md
index 1acd09d..ab31bdd 100644
--- a/apidocs/enums/bedrock.ChunkingStrategy.md
+++ b/apidocs/enums/bedrock.ChunkingStrategy.md
@@ -25,6 +25,8 @@ splitting them up such that each file corresponds to a chunk.
 • **DEFAULT** = ``"DEFAULT"``
 
 `FIXED_SIZE` with the default chunk size of 300 tokens and 20% overlap.
+If default is selected, chunk size and overlap set by the user will be
+ignored.
 
 ___
 
diff --git a/src/cdk-lib/bedrock/s3-data-source.ts b/src/cdk-lib/bedrock/s3-data-source.ts
index 619d2a2..569250d 100644
--- a/src/cdk-lib/bedrock/s3-data-source.ts
+++ b/src/cdk-lib/bedrock/s3-data-source.ts
@@ -37,6 +37,8 @@ export enum ChunkingStrategy {
   FIXED_SIZE = 'FIXED_SIZE',
   /**
    * `FIXED_SIZE` with the default chunk size of 300 tokens and 20% overlap.
+   * If default is selected, chunk size and overlap set by the user will be
+   * ignored.
    */
   DEFAULT = 'DEFAULT',
   /**
@@ -202,8 +204,16 @@ function vectorIngestionConfiguration(
       },
     };
 
-  } else {
-    return {};
+  } else { // DEFAULT
+    return {
+      chunkingConfiguration: {
+        chunkingStrategy: ChunkingStrategy.FIXED_SIZE,
+        fixedSizeChunkingConfiguration: {
+          maxTokens: CHUNKING_MAX_TOKENS,
+          overlapPercentage: CHUNKING_OVERLAP,
+        },
+      },
+    };
   }
 
 }


Test patch:
diff --git a/test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap b/test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap
index ca6f9b1..0479f63 100644
--- a/test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap
+++ b/test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap
@@ -323,7 +323,15 @@ exports[`Bedrock Agents Agent matches snapshot 1`] = `
           ],
         },
         "Name": "test-docs",
-        "VectorIngestionConfiguration": {},
+        "VectorIngestionConfiguration": {
+          "ChunkingConfiguration": {
+            "ChunkingStrategy": "FIXED_SIZE",
+            "FixedSizeChunkingConfiguration": {
+              "MaxTokens": 300,
+              "OverlapPercentage": 20,
+            },
+          },
+        },
       },
       "Type": "AWS::Bedrock::DataSource",
     },
diff --git a/test/cdk-lib/bedrock/s3-data-source.test.ts b/test/cdk-lib/bedrock/s3-data-source.test.ts
index c385954..7a1e2b8 100644
--- a/test/cdk-lib/bedrock/s3-data-source.test.ts
+++ b/test/cdk-lib/bedrock/s3-data-source.test.ts
@@ -68,6 +68,31 @@ describe('S3 Data Source', () => {
     });
   });
 
+  test('Default chunking', () => {
+    new bedrock.S3DataSource(stack, 'TestDataSource', {
+      bucket,
+      knowledgeBase: kb,
+      dataSourceName: 'TestDataSource',
+      chunkingStrategy: bedrock.ChunkingStrategy.DEFAULT,
+      maxTokens: 1024,
+      overlapPercentage: 20,
+    });
+
+    Template.fromStack(stack).hasResourceProperties('AWS::Bedrock::DataSource', {
+
+      VectorIngestionConfiguration:
+       {
+         ChunkingConfiguration: {
+           ChunkingStrategy: 'FIXED_SIZE',
+           FixedSizeChunkingConfiguration: {
+             MaxTokens: 300,
+             OverlapPercentage: 20,
+           },
+         },
+       },
+    });
+  });
+
   test('No chunking', () => {
     new bedrock.S3DataSource(stack, 'TestDataSource', {
       bucket,