Skip to content

Commit 169bc69

Browse files
authored
fix(bedrock): fix default chunking strategy not deploying (#481)
1 parent f749463 commit 169bc69

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

apidocs/enums/bedrock.ChunkingStrategy.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ splitting them up such that each file corresponds to a chunk.
2525
**DEFAULT** = ``"DEFAULT"``
2626

2727
`FIXED_SIZE` with the default chunk size of 300 tokens and 20% overlap.
28+
If default is selected, chunk size and overlap set by the user will be
29+
ignored.
2830

2931
___
3032

src/cdk-lib/bedrock/s3-data-source.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export enum ChunkingStrategy {
3737
FIXED_SIZE = 'FIXED_SIZE',
3838
/**
3939
* `FIXED_SIZE` with the default chunk size of 300 tokens and 20% overlap.
40+
* If default is selected, chunk size and overlap set by the user will be
41+
* ignored.
4042
*/
4143
DEFAULT = 'DEFAULT',
4244
/**
@@ -202,8 +204,16 @@ function vectorIngestionConfiguration(
202204
},
203205
};
204206

205-
} else {
206-
return {};
207+
} else { // DEFAULT
208+
return {
209+
chunkingConfiguration: {
210+
chunkingStrategy: ChunkingStrategy.FIXED_SIZE,
211+
fixedSizeChunkingConfiguration: {
212+
maxTokens: CHUNKING_MAX_TOKENS,
213+
overlapPercentage: CHUNKING_OVERLAP,
214+
},
215+
},
216+
};
207217
}
208218

209219
}

test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cdk-lib/bedrock/s3-data-source.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ describe('S3 Data Source', () => {
6868
});
6969
});
7070

71+
test('Default chunking', () => {
72+
new bedrock.S3DataSource(stack, 'TestDataSource', {
73+
bucket,
74+
knowledgeBase: kb,
75+
dataSourceName: 'TestDataSource',
76+
chunkingStrategy: bedrock.ChunkingStrategy.DEFAULT,
77+
maxTokens: 1024,
78+
overlapPercentage: 20,
79+
});
80+
81+
Template.fromStack(stack).hasResourceProperties('AWS::Bedrock::DataSource', {
82+
83+
VectorIngestionConfiguration:
84+
{
85+
ChunkingConfiguration: {
86+
ChunkingStrategy: 'FIXED_SIZE',
87+
FixedSizeChunkingConfiguration: {
88+
MaxTokens: 300,
89+
OverlapPercentage: 20,
90+
},
91+
},
92+
},
93+
});
94+
});
95+
7196
test('No chunking', () => {
7297
new bedrock.S3DataSource(stack, 'TestDataSource', {
7398
bucket,

0 commit comments

Comments
 (0)