Skip to content

Commit

Permalink
fix(bedrock): fix default chunking strategy not deploying (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
krokoko authored May 29, 2024
1 parent f749463 commit 169bc69
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apidocs/enums/bedrock.ChunkingStrategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

___

Expand Down
14 changes: 12 additions & 2 deletions src/cdk-lib/bedrock/s3-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
/**
Expand Down Expand Up @@ -202,8 +204,16 @@ function vectorIngestionConfiguration(
},
};

} else {
return {};
} else { // DEFAULT
return {
chunkingConfiguration: {
chunkingStrategy: ChunkingStrategy.FIXED_SIZE,
fixedSizeChunkingConfiguration: {
maxTokens: CHUNKING_MAX_TOKENS,
overlapPercentage: CHUNKING_OVERLAP,
},
},
};
}

}
10 changes: 9 additions & 1 deletion test/cdk-lib/bedrock/__snapshots__/agent.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/cdk-lib/bedrock/s3-data-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 169bc69

Please sign in to comment.