Skip to content

Commit

Permalink
Merge pull request #619 from toco8/feat/rag-knowledge-base
Browse files Browse the repository at this point in the history
Knowledge Bases for Amazon Bedrockのデータソース対応と脚注付与方法の改善
  • Loading branch information
tbrand committed Aug 30, 2024
2 parents 4ef5d14 + 7dd52c1 commit 91bd159
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/web/src/hooks/useRagKnowledgeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const convertS3UriToUrl = (s3Uri: string, region: string): string => {
const result = /^s3:\/\/(?<bucketName>.+?)\/(?<prefix>.+)/.exec(s3Uri);

if (!result) {
return '';
return s3Uri;
}

const groups = result?.groups as {
Expand Down Expand Up @@ -96,16 +96,14 @@ const useRagKnowledgeBase = (id: string) => {
// Knowledge Base のみを利用する場合は本来不要な処理
const retrievedItemsKendraFormat: RetrieveResultItem[] =
retrievedItems.data.retrievalResults!.map((r, idx) => {
const docFile = (r.location?.s3Location?.uri ?? '').split('/').pop();
const sourceUri =
r.metadata?.['x-amz-bedrock-kb-source-uri']?.toString() ?? '';

return {
Content: r.content?.text ?? '',
DocumentId: `${idx}`,
DocumentTitle: docFile,
DocumentURI: convertS3UriToUrl(
r.location?.s3Location?.uri ?? '',
modelRegion
),
DocumentTitle: sourceUri.split('/').pop(),
DocumentURI: convertS3UriToUrl(sourceUri, modelRegion),
};
});

Expand Down

0 comments on commit 91bd159

Please sign in to comment.