Skip to content

Commit

Permalink
fix (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb authored Jan 23, 2024
1 parent cbcd463 commit 1016ea2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](https://github.com/aws-samples/bedrock-claude-chat/actions/workflows/test.yml/badge.svg)

> [!Tip]
> **🔔 RAG (Retrieval Augmented Generation) Feature released**. See [Release](https://github.com/aws-samples/bedrock-claude-chat/releases/tag/v0.4.0) for the detail.
> 🔔**RAG (Retrieval Augmented Generation) Feature released**. See [Release](https://github.com/aws-samples/bedrock-claude-chat/releases/tag/v0.4.0) for the detail.
> [!Warning]
> The current version (`v0.4.x`) has no compatibility with ex version (~`v0.3.0`) due to the change of DynamoDB table schema. **Please note that UPDATE (i.e. `cdk deploy`) FROM EX VERSION TO `v0.4.x` WILL DESTROY ALL OF EXISTING CONVERSATIONS.**
Expand Down
1 change: 1 addition & 0 deletions backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EMBEDDING_CONFIG = {
# DO NOT change `model_id` (currently other models are not supported)
"model_id": "cohere.embed-multilingual-v3",
# NOTE: consider that cohere allows up to 2048 tokens per request
"chunk_size": 1000,
"chunk_overlap": 200,
}
Expand Down
2 changes: 2 additions & 0 deletions backend/embedding/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def embed(
paragraph_separator=r"\n\n\n",
chunk_size=CHUNK_SIZE,
chunk_overlap=CHUNK_OVERLAP,
# Use length of text as token count for cohere-multilingual-v3
tokenizer=lambda text: [0] * len(text),
)
)
embedder = Embedder(verbose=True)
Expand Down
7 changes: 7 additions & 0 deletions backend/embedding/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ class Embedder:
def __init__(self, verbose=False):
self.verbose = verbose

def print_documents_summary(self, documents: list[Document]):
for i, d in enumerate(documents):
logger.info(f"{i}th document metadata: {d.metadata}")
logger.info(f"{i}th document content length: {len(d.page_content)}")
logger.info(f"{i}th document head of content: {d.page_content[:30]}")

def embed_documents(self, documents: list[Document]) -> list[list[float]]:
if self.verbose:
logger.info(f"Embedding {len(documents)} documents.")
self.print_documents_summary(documents)
embeddings = calculate_document_embeddings([d.page_content for d in documents])
if self.verbose:
logger.info("Done embedding.")
Expand Down
10 changes: 0 additions & 10 deletions docs/RAG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ You can configure some parameters (See [Configure RAG Parameters](./CONFIGURE_KN

We utilize [Unstructured](https://github.com/Unstructured-IO) for parsing documents and [Llamaindex](https://www.llamaindex.ai/) for splitting them into chunks. [Playwright](https://playwright.dev/) is used to render content whose `Content-Type` corresponds to `text/html`.

## Note

As described in this [blog](https://www.timescale.com/blog/nearest-neighbor-indexes-what-are-ivfflat-indexes-in-pgvector-and-how-do-they-work/), the pgvector index should be updated as the data evolves. To rebuild the index, execute following sql:

```
REINDEX INDEX CONCURRENTLY idx_items_embedding;
```

Please be aware that this sample does not include the execution of the above re-indexing. We recommend to add periodical runner for production environment.

## RAG by Amazon Kendra

If interested in RAG using [Amazon Kendra](https://aws.amazon.com/kendra/), also refer following samples:
Expand Down
10 changes: 0 additions & 10 deletions docs/RAG_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@

ドキュメントの解析には[Unstructured](https://github.com/Unstructured-IO)を、ドキュメントのチャンク分割には[Llamaindex](https://www.llamaindex.ai/)を使用しています。`Content-Type``text/html`のコンテンツのレンダリングには[Playwright](https://playwright.dev/)を使用しています。

## 留意事項

この[blog](https://www.timescale.com/blog/nearest-neighbor-indexes-what-are-ivfflat-indexes-in-pgvector-and-how-do-they-work/)に記載されているように、データが増加するにつれて pgvector インデックスを更新する必要があります。インデックスを再構築するには、次の SQL を実行します:

```
REINDEX INDEX CONCURRENTLY idx_items_embedding;
```

上記の再インデックスの実行はこのサンプルには含まれていないことに注意してください。本番環境では定期的な実行を追加することをお勧めします。

## Amazon Kendra による RAG

Amazon Kendra を使用した RAG に興味がある場合は、以下のサンプルも参照してください。
Expand Down
9 changes: 4 additions & 5 deletions docs/README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](https://github.com/aws-samples/bedrock-claude-chat/actions/workflows/test.yml/badge.svg)

> [!Tip]
> **🔔 RAG 機能をリリースしました。** 詳細は [Release](https://github.com/aws-samples/bedrock-claude-chat/releases/tag/v0.4.0) をご覧ください。
> 🔔**RAG 機能をリリースしました。** 詳細は [Release](https://github.com/aws-samples/bedrock-claude-chat/releases/tag/v0.4.0) をご覧ください。
> [!Warning]
> 現在のバージョン(v0.4.x)は、DynamoDB テーブルスキーマの変更のため、過去バージョン(~v0.3.0)とは互換性がありません。**以前のバージョンから v0.4.x へアップデートすると、既存の対話記録は全て破棄されますので注意が必要です。**
Expand All @@ -16,22 +16,21 @@

### ボットのカスタマイズ

外部のナレッジおよび具体的なインストラクションを組み合わせ、ボットをカスタマイズすることが可能です(外部のナレッジを利用した方法は[RAG](./RAG_ja.md)として知られています)。 なお、作成したボットはアプリケーションのユーザー間で共有することができます。
外部のナレッジおよび具体的なインストラクションを組み合わせ、ボットをカスタマイズすることが可能です(外部のナレッジを利用した方法は[RAG](./RAG_ja.md)として知られています)。なお、作成したボットはアプリケーションのユーザー間で共有することができます。

![](./imgs/bot_creation_ja.png)
![](./imgs/bot_chat_ja.png)

## 🚀 まずはお試し

- [Bedrock Model access](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess) > `Manage model access` > `Anthropic / Claude`, `Anthropic / Claude Instant`, `Cohere / Embed Multilingual`をチェックし、`Save changes`をクリックします
- [CloudShell](https://console.aws.amazon.com/cloudshell/home)を開きます

<details>
<summary>スクリーンショット</summary>

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

</details>
- [CloudShell](https://console.aws.amazon.com/cloudshell/home)を開きます

- 下記のコマンドでデプロイ実行します

Expand Down Expand Up @@ -103,7 +102,7 @@ AWS のマネージドサービスで構成した、インフラストラクチ

### 管理者用機能

- [] ユーザーの利用状況分析
- [ ] ユーザーの利用状況分析

## Deploy using CDK

Expand Down

0 comments on commit 1016ea2

Please sign in to comment.