logo
Menu
Dolly, Miley, or Beyonce? I asked the new Chat With Your Document feature in Amazon Bedrock.

Dolly, Miley, or Beyonce? I asked the new Chat With Your Document feature in Amazon Bedrock.

In this article, I detail how the new Chat With Your Document feature in Knowledge Bases for Amazon Bedrock helped me learn more about music from the 70s.

Veliswa Boya
Amazon Employee
Published May 2, 2024
The revival of Dolly Parton's original song from the 70s Jolene, first by Miley Cyrus, and most recently by Beyonce, had me curious to learn more about music from this era that still has so much influence on what we listen to today.
Recently, Amazon Web Services (AWS) announced a new feature that gives the ability to chat with your document with zero setup in Knowledge Bases for Amazon Bedrock. With the chat with your document feature you can securely ask questions on a single document, make an analysis, or create a summary without the overhead of setting up a vector database, ingesting data, or retraining a model, making it effortless to bring own data to generative AI. All you need to do is provide a relevant data file as input and choose your Foundation Model (FM) to get started.

Things to know about chat with document

  • You can ask questions on a single document with zero setup.
  • Supported file formats are .pdf, .md, .txt, .docx, .html, .csv, .xls, and .xlsx.
  • File size must not exceed 10 MB and contains no more than 20,000 tokens.
  • Chat with your document either in the Amazon Bedrock console, or the Amazon Bedrock RetrieveAndGenerate API (SDK).
  • Select the document for your chat either from an S3 bucket, or your local device.
  • Anthropic's Claude 3 Sonnet is the only model currently available in this functionality.
  • A text-heavy file, that is much smaller than 10MB, can potentially breach the token limit.
  • Your document or its data won't be stored after use.

How I got started

So, I asked Claude 3 Sonnet in Amazon Bedrock Chat Playground for a list of Top 100 songs from the 70s, then uploaded this list in .docx format to an S3 bucket and asked it a couple of questions using the AWS SDK.
I could have used any Text model besides Claude 3 Sonnet here. Jurassic-2 Ultra gave me similar results, and Command Light gave me a very different list as it seemed to consult a different chart than Claude 3 Sonnet and Jurassic-2 Ultra. In the end, it's based on personal preference that I went with the list from Claude 3 Sonnet. Also note that you need access to the models before you can use the models, whether in the Playground or chat with document.
Here are the steps I followed and the relevant code for each step:
1. Imported the Python libraries
1
2
3
4
5
6
7
import boto3

bedrock_client = boto3.client(service_name='bedrock-agent-runtime')
s3 = boto3.client('s3')

session = boto3.session.Session()
region = session.region_name
2. Set up the call to the RetrieveAndGenerate API.
Instead of local device, this setup is for a document that's located in an S3 bucket so I provide the document S3 URI.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def retrieveAndGenerate(input_text, sourceType, model_id, region, document_s3_uri=None, data=None, identifier=None):
model_arn = f'arn:aws:bedrock:{region}::foundation-model/{model_id}'

return bedrock_client.retrieve_and_generate(
input={'text': input_text},
retrieveAndGenerateConfiguration={
'type': 'EXTERNAL_SOURCES',
'externalSourcesConfiguration': {
'modelArn': model_arn,
'sources': [
{
"sourceType": sourceType,
"s3Location": {
"uri": document_s3_uri
}
}
]
}
}
)
3. Start to chat with my document.
1
2
model_id = "anthropic.claude-3-sonnet-20240229-v1:0" # Replace with your modelID
document_uri = "s3://musiccharts/songlist.docx" # Replace with your S3 URI
1
2
3
response = retrieveAndGenerate(input_text="Who sang Jolene?", sourceType="S3", model_id=model_id, region=region, document_s3_uri=document_uri)
generated_text = response['output']['text']
print(generated_text)
Here's the list of top 100 songs I retrieved earlier.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Here is a list of 100 top songs from the 1970s:

1. Bohemian Rhapsody - Queen
2. Stairway to Heaven - Led Zeppelin
3. Hotel California - The Eagles
4. Sweet Home Alabama - Lynyrd Skynyrd
5. Imagine - John Lennon
6. Born to Run - Bruce Springsteen
7. Comfortably Numb - Pink Floyd
8. American Woman - The Guess Who
9. Hey Jude - The Beatles
10. Let It Be - The Beatles
11. Layla - Derek and the Dominos
12. Your Song - Elton John
13. Bridge Over Troubled Water - Simon & Garfunkel
14. Tiny Dancer - Elton John
15. Free Bird - Lynyrd Skynyrd
16. September - Earth, Wind & Fire
17. Dream On - Aerosmith
18. Roxanne - The Police
19. Dust in the Wind - Kansas
20. Hotel California - The Eagles
21. Don't Stop Me Now - Queen
22. Sweet Caroline - Neil Diamond
23. Born to Run - Bruce Springsteen
24. Go Your Own Way - Fleetwood Mac
25. You're So Vain - Carly Simon
26. We Are the Champions - Queen
27. Dream Weaver - Gary Wright
28. More Than a Feeling - Boston
29. Margaritaville - Jimmy Buffett
30. Smoke on the Water - Deep Purple
31. American Pie - Don McLean
32. Love Train - The O'Jays
33. Cat's in the Cradle - Harry Chapin
34. Take It Easy - The Eagles
35. Piano Man - Billy Joel
36. Reeling in the Years - Steely Dan
37. Money for Nothing - Dire Straits
38. Fooled Around and Fell in Love - Elvin Bishop
39. Dreams - Fleetwood Mac
40. We Will Rock You - Queen
41. I'll Have to Say I Love You in a Song - Jim Croce
42. The Night They Drove Old Dixie Down - The Band
43. Bennie and the Jets - Elton John
44. Who'll Stop the Rain - Creedence Clearwater Revival
45. You Ain't Seen Nothing Yet - Bachman-Turner Overdrive
46. I Shot the Sheriff - Eric Clapton
47. The Joker - Steve Miller Band
48. Eye of the Tiger - Survivor
49. Like a Rolling Stone - Bob Dylan
50. Me and Bobby McGee - Janis Joplin

51. Against the Wind - Bob Seger & The Silver Bullet Band
52. Ring My Bell - Anita Ward
53. Life Is a Highway - Rascal Flatts
54. Play That Funky Music - Wild Cherry
55. I Wish It Would Rain - The Temptations
56. I'll Be Around - The Spinners
57. Sunday Bloody Sunday - U2
58. Tonight's the Night (Gonna Be Alright) - Rod Stewart
59. Sir Duke - Stevie Wonder
60. Higher Ground - Stevie Wonder
61. Sweet Emotion - Aerosmith
62. Blinded By the Light - Manfred Mann's Earth Band
63. Kodachrome - Paul Simon
64. Piano Man - Billy Joel
65. I Want You to Want Me - Cheap Trick
66. Wake Up Everybody - Harold Melvin & The Blue Notes
67. The Way We Were - Barbra Streisand
68. We Are the World - USA for Africa
69. Love Will Keep Us Together - Captain & Tennille
70. Hungry Like the Wolf - Duran Duran
71. Bohemian Rhapsody - Queen
72. My Sharona - The Knack
73. Sail Away - Randy Newman
74. Hold Your Head Up - Argent
75. Heart of Glass - Blondie
76. Dancing Queen - ABBA
77. I Want You Back - The Jackson 5
78. ABC - The Jackson 5
79. Superstition - Stevie Wonder
80. Don't Leave Me This Way - Thelma Houston
81. September Morn - Neil Diamond
82. Baby I'm-a Want You - Bread
83. Wildfire - Michael Martin Murphey
84. Bad, Bad Leroy Brown - Jim Croce
85. Annie's Song - John Denver
86. Isn't She Lovely - Stevie Wonder
87. Shambala - Three Dog Night
88. Family Affair - Sly & The Family Stone
89. Tears of a Clown - Smokey Robinson & The Miracles
90. Fire and Rain - James Taylor
91. Thank You (Falettinme Be Mice Elf Agin) - Sly & The Family Stone
92. Could It Be Magic - Barry Manilow
93. Touch Me in the Morning - Diana Ross
94. How Deep Is Your Love - Bee Gees
95. Le Freak - Chic
96. Heart of Gold - Neil Young
97. Low Rider - War
98. It Keeps You Runnin' - The Doobie Brothers
99. Evergreen - Barbra Streisand
100. Use Ta Be My Girl - The O'Jays
Here are some of the questions I asked, and the corresponding answers, starting with the most obvious question :)
1
Who sang Jolene?
As mentioned at the beginning of this post, chat with your document uses your uploaded document to answer questions. This response is expected as interestingly enough, Dolly Parton's Jolene is not in the list of 100 top songs that Claude 3 Sonnet in Chat Playground gave me earlier.
Anyway, I want to learn more, so I go on and ask more questions.
1
Did the jackson 5 release any songs?

 I asked for some analysis.
1
Who appeared in the top 100 most times?
I asked for more analysis, and the result impressed me because I did not expect chat with your document to return any results on questions where the answer is not obvious.
1
What genres appeared in this list the most?
Ok, I could have gone on for a while, because this was a lot of fun!

Conclusion

In this post, we looked at how chat with your document lets you consult your own data (in the form of a single document) to answer questions, make an analysis, create a summary, without the overhead of setting up a vector database or ingesting data, making it effortless to bring own data to generative AI.
Based on my experiences when I started to play with this feature, chat with your document is not suitable for documents with a lot of text on them (for example, a Wikipedia page (for these, knowledge bases is more suitable)) as they can potentially breach the token limit.

Resources

Also don't forget to follow AWS Developers social profiles - YouTube, Twitter/X, LinkedIn, Instagram, and Twitch —to stay updated with the latest news and content!
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments