Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb committed Sep 5, 2024
2 parents b28571b + 711c932 commit a71d6f1
Show file tree
Hide file tree
Showing 35 changed files with 1,873 additions and 62 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

![](https://github.com/aws-samples/bedrock-claude-chat/actions/workflows/cdk.yml/badge.svg)

> [!Warning]
> A major update to v2 is planned soon. v2 will not be backward compatible with v1, and **existing RAG bots will no longer be usable.** For more details, please refer to the [migration guide](./docs/migration/V1_TO_V2.md).
> [!Warning]
> If you are using old version (e.g. `v0.4.x`) and wish to use the latest version, refer [migration guide](./docs/migration/V0_TO_V1.md). Without any care, **ALL DATA IN Aurora cluster WILL BE DESTROYED, and NO LONGER USERS CANNOT USE EXISTING BOTS WITH KNOWLEDGE AND CREATE NEW BOTS**.
Expand Down
1 change: 1 addition & 0 deletions backend/app/routes/schemas/bot_kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BedrockKnowledgeBaseInput(BaseSchema):
search_params: SearchParams
max_tokens: int | None = None
overlap_percentage: int | None = None
knowledge_base_id: str | None = None


class BedrockKnowledgeBaseOutput(BaseSchema):
Expand Down
4 changes: 4 additions & 0 deletions cdk/bin/bedrock-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const RDS_SCHEDULES: CronScheduleProps = app.node.tryGetContext("rdbSchedules");
const ENABLE_MISTRAL: boolean = app.node.tryGetContext("enableMistral");
const SELF_SIGN_UP_ENABLED: boolean =
app.node.tryGetContext("selfSignUpEnabled");
const ENABLE_KB: boolean = app.node.tryGetContext(
"useBedrockKnowledgeBaseForRag"
);

// container size of embedding ecs tasks
const EMBEDDING_CONTAINER_VCPU: number = app.node.tryGetContext(
Expand Down Expand Up @@ -81,6 +84,7 @@ const chat = new BedrockChatStack(app, `BedrockChatStack`, {
autoJoinUserGroups: AUTO_JOIN_USER_GROUPS,
rdsSchedules: RDS_SCHEDULES,
enableMistral: ENABLE_MISTRAL,
enableKB: ENABLE_KB,
embeddingContainerVcpu: EMBEDDING_CONTAINER_VCPU,
embeddingContainerMemory: EMBEDDING_CONTAINER_MEMORY,
selfSignUpEnabled: SELF_SIGN_UP_ENABLED,
Expand Down
3 changes: 2 additions & 1 deletion cdk/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
},
"embeddingContainerVcpu": 2048,
"embeddingContainerMemory": 4096,
"natgatewayCount": 2
"natgatewayCount": 2,
"useBedrockKnowledgeBaseForRag": false
}
}
3 changes: 3 additions & 0 deletions cdk/lib/bedrock-chat-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface BedrockChatStackProps extends StackProps {
readonly autoJoinUserGroups: string[];
readonly rdsSchedules: CronScheduleProps;
readonly enableMistral: boolean;
readonly enableKB: boolean;
readonly embeddingContainerVcpu: number;
readonly embeddingContainerMemory: number;
readonly selfSignUpEnabled: boolean;
Expand Down Expand Up @@ -145,6 +146,7 @@ export class BedrockChatStack extends cdk.Stack {
accessLogBucket,
webAclId: props.webAclId,
enableMistral: props.enableMistral,
enableKB: props.enableKB,
enableIpV6: props.enableIpV6,
});

Expand Down Expand Up @@ -212,6 +214,7 @@ export class BedrockChatStack extends cdk.Stack {
webSocketApiEndpoint: websocket.apiEndpoint,
userPoolDomainPrefix: props.userPoolDomainPrefix,
enableMistral: props.enableMistral,
enableKB: props.enableKB,
auth,
idp,
});
Expand Down
4 changes: 4 additions & 0 deletions cdk/lib/constructs/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { NagSuppressions } from "cdk-nag";
export interface FrontendProps {
readonly webAclId: string;
readonly enableMistral: boolean;
readonly enableKB: boolean;
readonly accessLogBucket?: IBucket;
readonly enableIpV6: boolean;
}
Expand Down Expand Up @@ -100,13 +101,15 @@ export class Frontend extends Construct {
webSocketApiEndpoint,
userPoolDomainPrefix,
enableMistral,
enableKB,
auth,
idp,
}: {
backendApiEndpoint: string;
webSocketApiEndpoint: string;
userPoolDomainPrefix: string;
enableMistral: boolean;
enableKB: boolean;
auth: Auth;
idp: Idp;
}) {
Expand All @@ -119,6 +122,7 @@ export class Frontend extends Construct {
VITE_APP_USER_POOL_ID: auth.userPool.userPoolId,
VITE_APP_USER_POOL_CLIENT_ID: auth.client.userPoolClientId,
VITE_APP_ENABLE_MISTRAL: enableMistral.toString(),
VITE_APP_ENABLE_KB: enableKB.toString(),
VITE_APP_REGION: region,
VITE_APP_USE_STREAMING: "true",
};
Expand Down
9 changes: 5 additions & 4 deletions cdk/package-lock.json

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

2 changes: 1 addition & 1 deletion cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@aws-prototyping-sdk/pdk-nag": "^0.19.68",
"@types/jest": "^29.5.3",
"@types/node": "20.4.2",
"aws-cdk": "2.147.3",
"aws-cdk": "2.148.1",
"jest": "^29.6.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand Down
5 changes: 5 additions & 0 deletions cdk/test/cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe("Bedrock Chat Stack Test", () => {
start: {},
},
enableMistral: false,
enableKB: false,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
Expand Down Expand Up @@ -98,6 +99,7 @@ describe("Bedrock Chat Stack Test", () => {
start: {},
},
enableMistral: false,
enableKB: false,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
Expand Down Expand Up @@ -148,6 +150,7 @@ describe("Bedrock Chat Stack Test", () => {
start: {},
},
enableMistral: false,
enableKB: false,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
Expand Down Expand Up @@ -197,6 +200,7 @@ describe("Scheduler Test", () => {
},
},
enableMistral: false,
enableKB: false,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
Expand Down Expand Up @@ -229,6 +233,7 @@ describe("Scheduler Test", () => {
start: {},
},
enableMistral: false,
enableKB: false,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
Expand Down
1 change: 0 additions & 1 deletion docs/AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ To develop your own custom tools for the Agent, follow these guidelines:

- Edit i18n files. Open [en/index.ts](../frontend/src/i18n/en/index.ts) and add your own `name` and `description` on `agent.tools`.
- Edit `xx/index.ts` as well. Where `xx` represents the country code you wish.
- Edit [formatDescription.ts](../frontend/src/features/agent/functions/formatDescription.ts) so that frontend app can refer to it correctly.

- Run `cdk deploy` to deploy your changes. This will make your custom tool available in the custom bot screen.

Expand Down
3 changes: 3 additions & 0 deletions docs/README_ja.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Bedrock Claude Chat

> [!Warning]
> 近々、v2 へのメジャーアップデートを予定しています。v1 とは後方互換性がなく、**既存の RAG ボットは使用できなくなる予定です。** 詳しくは[ガイド](./migration/V1_TO_V2.md)をご参照ください。
> [!Warning]
> 古いバージョン(v0.4.x 以前) を使用していて最新バージョンを使いたい場合は、[移行ガイド](./migration/V0_TO_V1.md)を参照してください。気をつけないと、Aurora クラスターのすべてのデータが破壊され、ユーザーはもはや既存の RAG ボットを利用できず、また新規にボットを作成できなくなります。
Expand Down
Binary file added docs/imgs/v1_to_v2_readonly_bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions docs/migration/V1_TO_V2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Migration Guide (v1 to v2)

## Overview

The v2 update introduces a significant change by replacing pgvector on Aurora Serverless and ECS-based embedding with [Amazon Bedrock Knowledge Bases](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base.html). This change is not backward compatible. If you want to continue using pgvector, avoid upgrading to v2. If you plan to transition, start by updating to v1.3.0 and enabling the Knowledge Bases option in cdk.json. This will make your existing bots read-only, allowing a gradual shift to the new system. Note that **upgrading to v2 will result in the deletion of all Aurora-related resources.** Future updates will focus exclusively on v2, with v1 being deprecated.

## Key Changes and Migration Steps

### v2 brings a major architectural shift

Replacement of pgvector and ECS Embedding: The previous system using pgvector on Aurora Serverless and ECS for embedding is replaced by Amazon Bedrock Knowledge Bases, which utilize an OpenSearch backend. This offers a fully managed solution, improving reliability and ease of maintenance.

### Migration Process

- Update to v1.3.0: Ensure you are using version 1.3.0 or later.
- Enable Knowledge Bases: Set `useBedrockKnowledgeBasesForRag` to `true` in [cdk.json](../../cdk/cdk.json). **Be aware that enabling Knowledge Bases will incur charges for both Aurora and Knowledge Bases.**
- Read-Only Mode: Once enabled, your existing pgvector-based bots become read-only, preventing further edits but allowing continued use.
- Re-create Bots: Open the bot creation screen and re-create your bots with the same definitions as those using pgvector, but now utilizing Knowledge Bases. **Note that some feature is not available on KnowledgeBases e.g. web crawling and youtube transcript.**

![](../imgs/v1_to_v2_readonly_bot.png)

- Upgrade to v2: Once you have successfully transitioned to using Knowledge Bases, proceed with the full upgrade to v2.

### Important Note

Migration of existing vector data from Aurora to the new Knowledge Bases is complex and not supported by this sample. If you rely on pgvector, consider staying with v1.
3 changes: 2 additions & 1 deletion frontend/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ VITE_APP_REDIRECT_SIGNIN_URL="http://localhost:5173/"
VITE_APP_REDIRECT_SIGNOUT_URL="http://localhost:5173/"
VITE_APP_COGNITO_DOMAIN=""
VITE_APP_USE_STREAMING="true"
VITE_APP_SOCIAL_PROVIDERS=""
VITE_APP_SOCIAL_PROVIDERS=""
VITE_APP_ENABLE_KB="false"
12 changes: 10 additions & 2 deletions frontend/src/@types/bot.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BedrockKnowledgeBase } from '../features/knowledgeBase/types';

export type BotKind = 'private' | 'mixed';

export type BotMeta = {
Expand Down Expand Up @@ -45,6 +47,7 @@ export type BotSyncStatus = 'QUEUED' | 'RUNNING' | 'SUCCEEDED' | 'FAILED';

export type BotListItem = BotMeta & {
available: boolean;
hasBedrockKnowledgeBase: boolean;
};

export type GenerationParams = {
Expand All @@ -69,11 +72,13 @@ export type BotDetails = BotMeta & {
syncStatusReason: string;
displayRetrievedChunks: boolean;
conversationQuickStarters: ConversationQuickStarter[];
bedrockKnowledgeBase: BedrockKnowledgeBase | null;
};

export type BotSummary = BotMeta & {
hasKnowledge: boolean;
hasAgent: boolean;
ownedAndHasBedrockKnowledgeBase: boolean;
conversationQuickStarters: ConversationQuickStarter[];
};

Expand All @@ -90,12 +95,13 @@ export type RegisterBotRequest = {
instruction: string;
agent: AgentInput;
description?: string;
embeddingParams?: EmdeddingParams;
embeddingParams?: EmdeddingParams | null;
generationParams?: GenerationParams;
searchParams?: SearchParams;
knowledge?: BotKnowledge;
displayRetrievedChunks: boolean;
conversationQuickStarters: ConversationQuickStarter[];
bedrockKnowledgeBase?: BedrockKnowledgeBase;
};

export type RegisterBotResponse = BotDetails;
Expand All @@ -105,12 +111,13 @@ export type UpdateBotRequest = {
instruction: string;
description?: string;
agent: AgentInput;
embeddingParams?: EmdeddingParams;
embeddingParams?: EmdeddingParams | null;
generationParams?: BotGenerationConfig;
searchParams?: SearchParams;
knowledge?: BotKnowledgeDiff;
displayRetrievedChunks: boolean;
conversationQuickStarters: ConversationQuickStarter[];
bedrockKnowledgeBase?: BedrockKnowledgeBase;
};

export type UpdateBotResponse = {
Expand All @@ -124,6 +131,7 @@ export type UpdateBotResponse = {
knowledge?: BotKnowledge;
displayRetrievedChunks: boolean;
conversationQuickStarters: ConversationQuickStarter[];
bedrockKnowledgeBase: BedrockKnowledgeBase;
};

export type UpdateBotPinnedRequest = {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/ChatListDrawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const bots: BotListItem[] = [
owned: false,
syncStatus: 'SUCCEEDED',
available: true,
hasBedrockKnowledgeBase: false,
},
{
id: '2',
Expand All @@ -38,6 +39,7 @@ const bots: BotListItem[] = [
owned: true,
syncStatus: 'SUCCEEDED',
available: true,
hasBedrockKnowledgeBase: false,
},
];

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/ListItemBot.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const bots: BotListItem[] = [
owned: false,
syncStatus: 'SUCCEEDED',
available: true,
hasBedrockKnowledgeBase: false,
},
{
id: '2',
Expand All @@ -34,6 +35,7 @@ const bots: BotListItem[] = [
owned: true,
syncStatus: 'SUCCEEDED',
available: true,
hasBedrockKnowledgeBase: false,
},
{
id: '3',
Expand All @@ -46,6 +48,7 @@ const bots: BotListItem[] = [
owned: false,
syncStatus: 'SUCCEEDED',
available: false,
hasBedrockKnowledgeBase: false,
},
{
id: '4',
Expand All @@ -58,6 +61,7 @@ const bots: BotListItem[] = [
owned: true,
syncStatus: 'SUCCEEDED',
available: false,
hasBedrockKnowledgeBase: false,
},
];

Expand Down
Loading

0 comments on commit a71d6f1

Please sign in to comment.