AWS Builder Center
Building Enterprise RAG Applications with Amazon Bedrock and LlamaIndex

Building Enterprise RAG Applications with Amazon Bedrock and LlamaIndex

This technical tutorial demonstrates integrating Amazon Bedrock with LlamaIndex for enterprise RAG applications. It covers configuring Bedrock's Nova Pro LLM and Titan embedding models, processing documents, creating vector indices, and implementing three chat engine types. Using Einstein and Marie Curie biographies as examples, it shows practical implementations including temperature tuning, memory management, and a Streamlit web interface for interactive testing.

📝 App:  source 
This comprehensive tutorial, written based on the  LlamaIndex RAG for Science Community by Ojitha Hewa Kumanayaka,  demonstrates how to build production-ready Retrieval Augmented Generation (RAG) applications using Amazon Bedrock as an alternative to OpenAI models. The guide provides practical implementation patterns for integrating AWS's managed AI service with LlamaIndex, enabling organisations to leverage enterprise-grade AI capabilities while maintaining data governance and security requirements.
The tutorial covers the complete RAG pipeline, from document processing through conversational AI interfaces. You'll learn to configure Bedrock's embedding models (Amazon Titan) and language models (Amazon Nova Pro) within the LlamaIndex framework, creating applications that can intelligently retrieve and synthesise information from document collections.
Key technical implementations include:
  • Model Discovery and Configuration: Programmatic exploration of available Bedrock embedding and LLM models
  • Document Processing Pipeline: Text chunking, embedding generation, and vector index creation using Bedrock services
  • Advanced Chat Engine Patterns: Three distinct conversational AI architectures ranging from simple stateless interactions to sophisticated memory-managed dialogue systems
  • Performance Optimisation: Temperature tuning, memory buffer configuration, and token limit management
The examples use a curated collection of scientific biographies (Einstein, Marie Curie) to demonstrate real-world document processing scenarios. This allows for concrete testing of retrieval accuracy and response quality across different chat engine configurations.
The tutorial also showcases a complete Streamlit web application that provides an interactive interface for experimenting with different Bedrock configurations, making it practical for both development and demonstration purposes.
By the end of this guide, you'll have a working knowledge of how to migrate existing OpenAI-based RAG systems to Amazon Bedrock while gaining access to enhanced security features, cost optimization, and enterprise governance capabilities that AWS provides.
from IPython.display import Markdown, display
def in_md(md_txt):
md_formated_txt = f"""--- Response ---
{md_txt}
----
"""
display(Markdown(md_formated_txt))

Connecting to Amazon Bedrock

Amazon Bedrock is AWS's fully managed service that provides access to foundation models from leading AI companies through a single API. This notebook demonstrates how to integrate Bedrock's LLM and embedding models with LlamaIndex for RAG applications.
Key Benefits:
  • Enterprise-ready: Built-in security and governance
  • Multiple models: Access Claude, Llama, Titan, and Cohere models
  • Managed service: No infrastructure to maintain
  • Pay-per-use: Cost-effective scaling
This integration allows you to replace OpenAI models with Bedrock equivalents while maintaining the same RAG functionality demonstrated in the main Science Community chat notebook.

Discovering Available Bedrock Embedding Models

The following code demonstrates how to programmatically discover which embedding models are available through Amazon Bedrock. This is useful for understanding your options before selecting a specific model for your RAG application.
The  BedrockEmbedding.list_supported_models()  method returns a structured list of embedding models organized by provider (Amazon, Cohere, etc.), helping you choose the most appropriate model for your use case.
from llama_index.embeddings.bedrock import BedrockEmbedding
import json

supported_models = BedrockEmbedding.list_supported_models()
print(json.dumps(supported_models, indent=2))
{
"amazon": [
"amazon.titan-embed-text-v1",
"amazon.titan-embed-text-v2:0",
"amazon.titan-embed-g1-text-02"
],
"cohere": [
"cohere.embed-english-v3",
"cohere.embed-multilingual-v3"
]
}
from llama_index.core import get_response_synthesizer
from llama_index.llms.bedrock_converse import BedrockConverse
from llama_index.embeddings.bedrock import BedrockEmbedding
from llama_index.core import Settings

llm = BedrockConverse(model="amazon.nova-pro-v1:0",
temperature=0,
max_tokens=3000
)
Settings.llm = llm
# Basic embedding model setup
embed_model = BedrockEmbedding(
model_name="amazon.titan-embed-text-v2:0"
)
Settings.embed_model = embed_model

Setting Up Bedrock LLM and Embedding Models

This code initializes the core Bedrock components for our RAG system:
  • BedrockConverse LLM: Uses Amazon's Nova Pro model for text generation with controlled temperature (0) and token limit (3000)
  • BedrockEmbedding: Uses Amazon's Titan v2 embedding model to convert text into vector representations
  • LlamaIndex Settings: Configures these models globally so all LlamaIndex components use Bedrock instead of OpenAI
embed_model.get_text_embedding("hello world")
[-0.02060231938958168,
0.05661262199282646,
0.007168131414800882,
-0.009022098034620285,
...
-0.013906767591834068,
...]

Testing the Embedding Model

Above code tests our Bedrock embedding model by converting the simple text "hello world" into a vector representation. The output will be a list of numerical values (embeddings) that represent the semantic meaning of the text, confirming that our Bedrock embedding setup is working correctly.

Loading Documents

This code loads all documents from the  ./data  directory using LlamaIndex's  SimpleDirectoryReader . This will read the science community documents (Einstein, Marie Curie, friends, and meeting scenarios) and prepare them for processing in our RAG pipeline.
from llama_index.core import SimpleDirectoryReader
documents =SimpleDirectoryReader(
input_dir="./data").load_data()

Text Chunking and Node Creation

This code breaks down the loaded documents into smaller, manageable chunks using  TokenTextSplitter . Each chunk is limited to 1024 tokens with a 20-token overlap between chunks to maintain context continuity. The result is a collection of  TextNode  objects that will be used for embedding and retrieval.
from llama_index.core.node_parser import TokenTextSplitter

splittter = TokenTextSplitter(
chunk_size= 1024,
chunk_overlap=20
)
nodes = splittter.get_nodes_from_documents(documents)

Inspecting a Text Node

This code displays the structure and content of the first text node to help us understand how the document chunking worked. You'll see the node's metadata (file path, creation date, etc.), relationships to other nodes, and the actual text content from the Einstein biography.
import pprint

pprint.pprint(nodes[0], indent=2)
TextNode(id_='f8694ed0-fb97-4dd1-9074-836e8bc68c19', embedding=None, metadata={'file_path': '/Users/ojitha/GitHub/rag_llamaindex/Science_Community/data/AlbertEinstein.txt', 'file_name': 'AlbertEinstein.txt', 'file_type': 'text/plain', 'file_size': 8235, 'creation_date': '2025-09-12', 'last_modified_date': '2025-09-12'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='6932980f-08a2-4e0f-b4f5-fdf981dad1c6', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'file_path': '/Users/ojitha/GitHub/rag_llamaindex/Science_Community/data/AlbertEinstein.txt', 'file_name': 'AlbertEinstein.txt', 'file_type': 'text/plain', 'file_size': 8235, 'creation_date': '2025-09-12', 'last_modified_date': '2025-09-12'}, hash='ebbeab8f1fb4d45db4be9071d503bd1d253736c0a2213119e2ac3946f6f207d0'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='33de6b9a-59ba-44a8-ba57-668a3fdc98d8', node_type=<ObjectType.TEXT: '1'>, metadata={}, hash='7f6bac3350f6db083a409040284e8883997660c647b36ff4bb89c3fbe9b775f3')}, metadata_template='{key}: {value}', metadata_separator='\n', text='# Albert Einstein: A Biography\n\n## Early Life (1879-1896)\n\nAlbert Einstein was born on March 14, 1879, in Ulm, in the Kingdom of Württemberg in the German Empire. His parents were Hermann Einstein, a salesman and engineer, and Pauline Koch Einstein. When Albert was one year old, the family moved to Munich, where his father and uncle founded Elektrotechnische Fabrik J. Einstein & Cie, a company that manufactured electrical equipment.\n\nEinstein showed early signs of intellectual curiosity, though contrary to popular myth, he was not a poor student. He excelled in mathematics and physics from a young age. When he was five, his father gave him a compass, and Einstein was fascinated by the invisible forces that moved the needle—an experience he later described as pivotal in developing his scientific curiosity.\n\nIn 1894, Einstein\'s family moved to Italy for business reasons, but Albert remained in Munich to finish his education. However, he left school early and rejoined his family in Italy. He then applied to the Swiss Federal Polytechnic in Zurich but failed the entrance exam, though he scored exceptionally well in mathematics and physics. After completing his secondary education in Switzerland, he was accepted to the Polytechnic in 1896.\n\n## Education and Early Career (1896-1905)\n\nEinstein studied at the Swiss Federal Polytechnic from 1896 to 1900, where he met Mileva Marić, a fellow physics student who would later become his first wife. After graduating in 1900, Einstein struggled to find academic employment and worked various temporary jobs, including as a tutor and substitute teacher.\n\nIn 1902, he secured a position at the Swiss Patent Office in Bern, where he worked as a technical assistant examiner. This job provided him with financial stability and, perhaps more importantly, time to pursue his own scientific research. The work at the patent office also exposed him to practical applications of electromagnetic theory, which influenced his later work.\n\nEinstein earned his doctorate from the University of Zurich in 1905 with a dissertation titled "On a New Determination of Molecular Dimensions."\n\n## The Miracle Year (1905)\n\n1905 became known as Einstein\'s "Annus Mirabilis" (miracle year) because he published four groundbreaking papers that revolutionized physics:\n\n### 1. Photoelectric Effect\nEinstein\'s paper on the photoelectric effect explained how light could behave as particles (photons), providing crucial evidence for quantum theory. This work earned him the Nobel Prize in Physics in 1921.\n\n### 2. Brownian Motion\nHis explanation of Brownian motion provided empirical evidence for the existence of atoms and molecules, convincing skeptics of atomic theory.\n\n### 3. Special Theory of Relativity\nPerhaps his most famous contribution, special relativity introduced the concept that space and time are interwoven into spacetime, and that the speed of light is constant for all observers. This theory challenged Newton\'s absolute concepts of space and time.\n\n### 4. Mass-Energy Equivalence\nThe famous equation E=mc² emerged from his work on special relativity, showing that mass and energy are interchangeable.\n\n## Academic Career and General Relativity (1905-1915)\n\nFollowing his 1905 publications, Einstein gained recognition in the scientific community. He moved through various academic positions:\n\n- 1908: Lecturer at the University of Bern\n- 1909: Professor at the University of Zurich\n- 1911: Professor at Charles University in Prague\n- 1912: Professor at ETH Zurich\n- 1914: Director of the Kaiser Wilhelm Institute for Physics in Berlin\n\nDuring this period, Einstein worked on extending his special theory of relativity to include gravity. In 1915, he completed his General Theory of Relativity, which described gravity not as a force, but as a curvature of spacetime caused by mass and energy. This theory made several predictions that were later confirmed experimentally, including the bending of light around massive objects.\n\n## International Fame (1915-1933)\n\nEinstein\'s general relativity gained worldwide attention when Sir Arthur Eddington\'s 1919 solar eclipse expedition confirmed the theory\'s prediction that light would bend around the sun. Overnight, Einstein became an international celebrity and the face of modern science.\n\nDuring this period, Einstein made significant contributions to quantum mechanics, statistical mechanics, and cosmology, though he remained skeptical of quantum mechanics\' probabilistic interpretation, famously stating "God does not play dice with the universe."\n\n## Personal Life\n\nEinstein married Mileva Marić in 1903, and they had two sons: Hans Albert and Eduard. The couple also had a daughter, Lieserl, born before their marriage, whose fate remains unknown. Einstein and Mileva divorced in 1919.\n\nLater in 1919, Einstein married', mimetype='text/plain', start_char_idx=0, end_char_idx=4824, metadata_seperator='\n', text_template='{metadata_str}\n\n{content}')

Creating Vector Index

This code creates a  VectorStoreIndex  from our text nodes. The index will automatically use our Bedrock Titan embedding model (configured earlier) to convert each text chunk into vector embeddings and store them for efficient similarity-based retrieval during queries.
from llama_index.core import VectorStoreIndex

index = VectorStoreIndex(nodes)
q_engine = index.as_query_engine(similarity_top_k = 5)
response = q_engine.query("who are the scientists in these documents?")
response.response
'The scientists mentioned in the documents are Marie Curie, Albert Einstein, Paul Langevin, Max Planck, Henri Poincaré, Ernest Rutherford, Hendrik Lorentz, and Niels Bohr.'

Testing the RAG System

This code creates a query engine from our vector index and tests it with the question "who are the scientists in these documents?". The engine will retrieve the top 5 most similar text chunks and use our Bedrock Nova Pro LLM to generate a comprehensive answer based on the retrieved context.
in_md(response.response)
--- Response --- The scientists mentioned in the documents are Marie Curie, Albert Einstein, Paul Langevin, Max Planck, Henri Poincaré, Ernest Rutherford, Hendrik Lorentz, and Niels Bohr. ----

Checking Retrieved Source Nodes

This code displays the number of source nodes (text chunks) that were retrieved and used to generate the response. This helps verify that our query engine is working correctly and retrieving the expected number of relevant document chunks (should be 5 as configured).
len(response.source_nodes)
5

Creating Summary Index

This code creates a  SummaryIndex  as an alternative to the vector-based approach. Unlike vector search which retrieves similar chunks, the summary index processes all document nodes sequentially to generate comprehensive responses. This is useful for queries that require a complete overview of all documents rather than specific similarity matches.
from llama_index.core import SummaryIndex

summary_index = SummaryIndex(nodes)
s_engine = summary_index.as_query_engine()
summary = s_engine.query("Povide the summary")
in_md(summary.response)
--- Response --- In October 1911, during the first Solvay Conference in Brussels, Albert Einstein and Marie Curie met for the first time. Einstein, impressed by Curie's work on radioactivity, praised her dedication and methodical approach. Curie, in turn, admired Einstein's ability to visualize complex physical phenomena. They discussed both scientific topics and their shared experiences as outsiders in the scientific community. Their mutual respect and understanding grew over the years, culminating in a lasting friendship characterized by their shared dedication to scientific discovery. ----

Implementing Chat Engines with Bedrock

Now let's implement the different chat engine types using our Bedrock models, following the patterns used in the  sc_bedrock_app  Streamlit application. This section demonstrates practical implementations of each chat engine mode with AWS Bedrock.

🔄 Condense Question Chat Engine Implementation

The simplest chat engine that condenses conversation history into standalone questions. This approach is stateless and doesn't require explicit memory management.
# Create Condense Question Chat Engine
condense_engine = index.as_chat_engine("condense_question", verbose=True)

# Test with a question
response1 = condense_engine.chat("Tell me about Einstein's early life")
in_md(response1.response)
2025-09-15 09:59:40,281 - INFO - Querying with: Tell me about Einstein's early life

Querying with: Tell me about Einstein's early life
--- Response --- Albert Einstein was born on March 14, 1879, in Ulm, in the Kingdom of Württemberg in the German Empire. His parents were Hermann Einstein, a salesman and engineer, and Pauline Koch Einstein. When Albert was one year old, the family moved to Munich, where his father and uncle founded a company that manufactured electrical equipment. Einstein showed early signs of intellectual curiosity, particularly in mathematics and physics. He was fascinated by a compass given to him by his father at age five, which sparked his scientific curiosity.
In 1894, Einstein's family moved to Italy for business reasons, but Albert stayed in Munich to finish his education. However, he left school early and rejoined his family in Italy. He applied to the Swiss Federal Polytechnic in Zurich but failed the entrance exam, despite scoring exceptionally well in mathematics and physics. After completing his secondary education in Switzerland, he was accepted to the Polytechnic in 1896. ----
# Follow-up question to test conversation history condensation
response2 = condense_engine.chat("What about his education?")
in_md(response2.response)
2025-09-15 09:59:42,897 - INFO - Querying with: What was Albert Einstein's educational journey, particularly after his family moved to Italy and his initial failure to pass the entrance exam for the Swiss Federal Polytechnic in Zurich?

Querying with: What was Albert Einstein's educational journey, particularly after his family moved to Italy and his initial failure to pass the entrance exam for the Swiss Federal Polytechnic in Zurich?
--- Response --- After his family moved to Italy, Albert Einstein remained in Munich to finish his education but eventually left school early to rejoin his family. He applied to the Swiss Federal Polytechnic in Zurich but failed the entrance exam, despite scoring exceptionally well in mathematics and physics. After completing his secondary education in Switzerland, he was accepted to the Polytechnic in 1896. He studied there from 1896 to 1900, where he met Mileva Marić, a fellow physics student. After graduating in 1900, Einstein struggled to find academic employment and worked various temporary jobs before securing a position at the Swiss Patent Office in Bern in 1902. This job provided him with financial stability and time to pursue his own scientific research. He earned his doctorate from the University of Zurich in 1905 with a dissertation titled "On a New Determination of Molecular Dimensions." ----

💾 Context Chat Engine Implementation

The context chat engine uses explicit memory management to maintain conversation state. This implementation follows the pattern from the Streamlit application.
# Create Context Chat Engine with Memory Management
from llama_index.core.memory import ChatMemoryBuffer

# Configure memory with token limit (similar to Streamlit app)
context_memory = ChatMemoryBuffer.from_defaults(token_limit=3900)

# Create context chat engine with system prompt
context_engine = index.as_chat_engine(
chat_mode="context",
memory=context_memory,
system_prompt="You are familiar with biographies of Albert and Marie, as well as their professional and social friendships and relationships."
)

# Test the context engine
response3 = context_engine.chat("Tell me about Marie Curie's scientific achievements")
in_md(response3.response)
--- Response --- Marie Curie's scientific achievements are groundbreaking and have had a profound impact on multiple fields:
  1. Discovery of Radioactivity:
  • Marie Curie, along with her husband Pierre Curie and Henri Becquerel, discovered the phenomenon of radioactivity. This discovery revolutionized the field of physics and chemistry.
  1. Discovery of New Elements:
  • Marie Curie discovered two new elements: polonium and radium. These discoveries were made through her meticulous work in isolating these elements from uranium ores.
  1. Isolation of Pure Radium:
  • After discovering radium, Marie Curie dedicated years to isolating pure radium. In 1902, she succeeded in isolating one-tenth of a gram of pure radium chloride, proving the existence of the element and establishing its atomic weight.
  1. Nobel Prizes:
  • Marie Curie was the first woman to win a Nobel Prize and the only person to win Nobel Prizes in two different sciences. She shared the 1903 Nobel Prize in Physics with Pierre Curie and Henri Becquerel for their work on radioactivity. In 1911, she won the Nobel Prize in Chemistry for her discovery of radium and polonium and the isolation of pure radium.
  1. Medical Applications of Radioactivity:
  • During World War I, Marie Curie developed mobile X-ray units, known as "petites Curies," to help locate shrapnel and broken bones in soldiers. She also pioneered the use of radium and radon gas to sterilize infected tissue, laying the groundwork for nuclear medicine.
  1. Establishment of the Radium Institute:
  • Marie Curie founded the Radium Institute in Paris and Warsaw, which became leading centers for nuclear physics and chemistry research.
  1. Legacy in Science:
  • Marie Curie's techniques for isolating radioactive isotopes are still used today. Her research led directly to the development of X-ray technology, nuclear power, and cancer treatments. The element curium and the unit of radioactivity, the curie, are named in her honor.
  1. Breaking Social Barriers:
  • Beyond her scientific achievements, Marie Curie broke significant social barriers. She was the first woman to win a Nobel Prize, the first person to win Nobel Prizes in two different sciences, and the first female professor at the University of Paris. She opened doors for women in science and remains an inspiration to researchers worldwide.
Marie Curie's work not only advanced scientific knowledge but also demonstrated the importance of perseverance, intellectual curiosity, and the breaking of societal barriers in the pursuit of discovery. ----
# Follow-up question to test memory retention
response4 = context_engine.chat("How did she and Einstein interact professionally?")
in_md(response4.response)
--- Response --- Marie Curie and Albert Einstein interacted professionally in several significant ways, primarily through their shared participation in scientific conferences and their mutual respect for each other's work.
  1. First Solvay Conference (1911):
  • The first Solvay Conference in Brussels, held in October 1911, was the initial meeting point for Marie Curie and Albert Einstein. This conference brought together some of the greatest minds in physics to discuss the revolutionary concept of quantum theory. Both Curie and Einstein were prominent attendees, and their interaction at this conference marked the beginning of their professional relationship.
  • During the conference, Einstein approached Curie and expressed admiration for her work on radioactivity. Curie, in turn, showed interest in Einstein's theory of relativity and how it might affect radioactive decay.
  1. Intellectual Exchange:
  • Despite their different areas of expertise, Curie and Einstein found common ground in their discussions. They often sought each other out during breaks at conferences to discuss not only physics but also their shared concerns about the growing tensions in Europe. Both had faced challenges as outsiders in the scientific community—Curie as a woman and Einstein as a Jew—and they found understanding in each other's struggles.
  1. Support During Personal Crisis:
  • In 1911, Marie Curie faced a significant personal scandal involving her relationship with Paul Langevin. During this difficult time, Einstein wrote a supportive letter to Curie, expressing his admiration for her work and his disdain for the treatment she received in the press. This letter demonstrated Einstein's respect for Curie's scientific contributions and his support for her as a fellow scientist.
  1. Continued Professional Interaction:
  • Over the years, Curie and Einstein continued to interact professionally at various scientific conferences and meetings. Their mutual respect and admiration for each other's work remained strong. They both attended later Solvay Conferences, where they continued to engage with other leading scientists of their time.
  1. Correspondence and Later Meetings:
  • Although specific details of their correspondence are not extensively documented, it is known that Curie and Einstein maintained a professional relationship through letters and meetings. Their mutual respect endured, and they continued to influence each other's perspectives on scientific and social issues.
In summary, Marie Curie and Albert Einstein's professional interaction was marked by mutual respect, intellectual exchange, and support during challenging times. Their relationship exemplified the camaraderie and collaboration that can exist among great scientific minds, transcending their individual areas of expertise. ----

🔀 Condense Plus Context Chat Engine Implementation

The most sophisticated engine combining both condensation and context memory. This implementation demonstrates the advanced configuration options available in the Streamlit application.
# Create Condense Plus Context Chat Engine (hybrid approach)
from llama_index.core.memory import ChatMemoryBuffer

# Configure memory for the hybrid engine
hybrid_memory = ChatMemoryBuffer.from_defaults(token_limit=3900)

# Create custom LLM instance with specific temperature (as done in Streamlit app)
custom_llm = BedrockConverse(
model="amazon.nova-pro-v1:0",
temperature=0.1, # Lower temperature for more focused responses
max_tokens=3000
)

# Create the hybrid chat engine
hybrid_engine = index.as_chat_engine(
chat_mode="condense_plus_context",
memory=hybrid_memory,
llm=custom_llm,
context_prompt="You are familiar with biographies of Albert and Marie, as well as their professional and social friendships and relationships.",
verbose=True
)

# Test the hybrid engine
response5 = hybrid_engine.chat("Compare Einstein and Marie Curie's approaches to scientific research")
in_md(response5.response)
2025-09-15 09:59:51,884 - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2025-09-15 09:59:51,958 - INFO - Condensed question: Compare Einstein and Marie Curie's approaches to scientific research

Condensed question: Compare Einstein and Marie Curie's approaches to scientific research
--- Response --- Certainly! Albert Einstein and Marie Curie, two of the most influential scientists in history, had distinct yet complementary approaches to scientific research.

Marie Curie:

  1. Experimental Focus:
  • Curie's work was deeply rooted in experimental physics and chemistry. She is best known for her research on radioactivity, a term she coined.
  • Her approach involved meticulous laboratory work, including the isolation of radioactive elements like polonium and radium.
  1. Persistence and Tenacity:
  • Curie demonstrated extraordinary perseverance. She processed tons of pitchblende to extract a small amount of radium, showcasing her dedication to empirical research.
  1. Collaborative yet Independent:
  • While she collaborated with her husband Pierre Curie, especially in the early years, she also worked independently after his death, continuing her groundbreaking research.
  1. Practical Applications:
  • Curie was interested in the practical applications of her discoveries. Her work laid the groundwork for the development of X-rays in medical diagnostics.

Albert Einstein:

  1. Theoretical Focus:
  • Einstein’s contributions were primarily theoretical. His work on the photoelectric effect, special relativity, and general relativity revolutionized our understanding of physics.
  • He relied heavily on thought experiments and mathematical formulations rather than laboratory experiments.
  1. Imagination and Intuition:
  • Einstein’s approach was characterized by his remarkable imagination and intuitive grasp of physical principles. He often visualized physical scenarios to derive his theories.
  1. Solitude in Research:
  • Einstein preferred working alone or in small groups. His groundbreaking papers on relativity were developed through solitary contemplation and discussion with a few close colleagues.
  1. Broad Impact:
  • While Curie’s work had immediate practical applications, Einstein’s theories had a profound impact on the fundamental understanding of the universe, influencing fields far beyond physics, including philosophy and cosmology.

Comparison:

  • Methodology: Curie’s approach was experimental and hands-on, whereas Einstein’s was theoretical and conceptual.
  • Persistence: Both exhibited incredible perseverance, but Curie’s was manifest in her laboratory work, while Einstein’s was in his relentless pursuit of theoretical understanding.
  • Collaboration vs. Independence: Curie worked collaboratively, especially with her husband, while Einstein often worked in isolation.
  • Application: Curie’s discoveries had more immediate practical applications, whereas Einstein’s theories had long-term, profound implications for science and technology.
In summary, while Marie Curie and Albert Einstein approached scientific research from different angles—experimental vs. theoretical—both left indelible marks on the scientific community through their dedication, innovation, and groundbreaking discoveries. ----
# Follow-up question to test the hybrid approach
response6 = hybrid_engine.chat("What specific challenges did they both face as pioneering scientists?")
in_md(response6.response)
2025-09-15 09:59:57,644 - INFO - Condensed question: What specific challenges did Albert Einstein and Marie Curie both face as pioneering scientists?

Condensed question: What specific challenges did Albert Einstein and Marie Curie both face as pioneering scientists?
--- Response --- Both Marie Curie and Albert Einstein faced a multitude of challenges as pioneering scientists, though the nature of these challenges differed due to their unique contexts and the eras in which they worked.

Marie Curie:

  1. Gender Discrimination:
  • Curie faced significant gender bias in the male-dominated scientific community of the late 19th and early 20th centuries. Her achievements were often undervalued, and she struggled for recognition and funding.
  1. Limited Resources:
  • She worked with minimal resources. Her early research was conducted in a shed with inadequate equipment, and she had to process large quantities of pitchblende ore by hand to isolate radium.
  1. Health Risks:
  • Curie’s work with radioactive materials exposed her to significant health risks. The long-term effects of radiation led to her eventual death from aplastic anemia.
  1. Balancing Family and Career:
  • Curie had to balance her scientific career with family responsibilities. She was a mother of two while conducting her groundbreaking research.
  1. Academic Obstacles:
  • Despite her qualifications, Curie faced obstacles in gaining academic positions. She was the first woman to win a Nobel Prize and the first person to win two Nobel Prizes in different scientific fields, yet she encountered resistance in her academic career.

Albert Einstein:

  1. Initial Rejection:
  • Einstein’s early papers on relativity were met with skepticism and resistance from the established scientific community. His ideas challenged the Newtonian framework that had dominated physics for centuries.
  1. Isolation in Research:
  • Einstein often worked in isolation, which could be both a strength and a challenge. His unconventional approaches sometimes made it difficult for him to gain immediate acceptance for his theories.
  1. Political and Social Upheaval:
  • Einstein’s life spanned periods of significant political turmoil, including World War I, the rise of Nazism, and World War II. These events influenced his personal safety, academic freedom, and the reception of his work.
  1. Ethical Dilemmas:
  • Einstein faced ethical dilemmas, particularly regarding the application of his theories. His letter to President Roosevelt warning about the potential development of atomic weapons is a notable example.
  1. Public Scrutiny:
  • As his fame grew, Einstein became a public figure, subject to intense scrutiny and expectations. This fame sometimes distracted from his scientific work and put him in the spotlight for his political and social views.

Common Challenges:

  • Resistance to New Ideas: Both Curie and Einstein faced resistance from the scientific community to their revolutionary ideas.
  • Personal Sacrifices: They both made significant personal sacrifices—Curie in terms of health and family time, and Einstein in terms of personal safety and privacy.
  • Persistence Required: Both scientists needed extraordinary persistence to overcome the obstacles in their paths and achieve their groundbreaking discoveries.
In summary, while Curie and Einstein faced different specific challenges due to their gender, the nature of their work, and the times in which they lived, they both demonstrated remarkable resilience and dedication in the face of adversity. ----

Advanced Configuration Examples from Streamlit App

The  sc_bedrock_app  demonstrates several advanced configuration patterns. Let's explore some of these customization options:

Temperature Variation Testing

Different temperatures affect response creativity and focus. The Streamlit app allows users to adjust temperature from 0.0 to 1.0.
# Test different temperature settings (as available in Streamlit app)

# High creativity (temperature = 0.8)
creative_llm = BedrockConverse(
model="amazon.nova-pro-v1:0",
temperature=0.8,
max_tokens=3000
)

# Low temperature for focused responses (temperature = 0.1)
focused_llm = BedrockConverse(
model="amazon.nova-pro-v1:0",
temperature=0.1,
max_tokens=3000
)

# Create engines with different temperatures
creative_engine = index.as_chat_engine(
chat_mode="condense_question",
verbose=False
)

# Test the same question with different settings
test_question = "Describe Einstein's personality"

print("=== High Temperature Response (Creative) ===")
Settings.llm = creative_llm
creative_response = creative_engine.chat(test_question)
in_md(creative_response.response)
2025-09-15 10:00:03,701 - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2025-09-15 10:00:03,810 - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2025-09-15 10:00:03,938 - INFO - Querying with: Describe Einstein's personality

=== High Temperature Response (Creative) ===
--- Response --- Einstein was known for his distinctive appearance, including wild hair, casual dress, and pipe smoking. He had a quirky personality and was recognized for his pacifism, advocacy for civil rights, and outspoken opposition to racism and nationalism. ----
print("=== Low Temperature Response (Focused) ===")
Settings.llm = focused_llm
focused_response = creative_engine.chat(test_question)
in_md(focused_response.response)
=== Low Temperature Response (Focused) ===

2025-09-15 10:00:05,067 - INFO - Querying with: What were the distinctive characteristics and personality traits of Albert Einstein, including his appearance, beliefs, and social advocacy?
--- Response --- Albert Einstein was known for his distinctive appearance, which included wild hair, casual dress, and pipe smoking. He had a quirky personality and was recognized for his pacifism, advocacy for civil rights, and opposition to racism and nationalism. ----

Memory Token Limit Configuration

The Streamlit app allows users to configure memory token limits from 1000 to 8000 tokens. Let's demonstrate how this affects conversation retention.
# Demonstrate different memory configurations (as available in Streamlit app)

# Small memory buffer (1000 tokens)
small_memory = ChatMemoryBuffer.from_defaults(token_limit=1000)
small_memory_engine = index.as_chat_engine(
chat_mode="context",
memory=small_memory,
system_prompt="You are familiar with biographies of Albert and Marie."
)

# Large memory buffer (6000 tokens)
large_memory = ChatMemoryBuffer.from_defaults(token_limit=6000)
large_memory_engine = index.as_chat_engine(
chat_mode="context",
memory=large_memory,
system_prompt="You are familiar with biographies of Albert and Marie."
)

print("=== Testing Memory Retention ===")
print("Small Memory Engine (1000 tokens):")

# Have a conversation with small memory
small_memory_engine.chat("Tell me about Einstein's Nobel Prize")
small_memory_engine.chat("What was Marie Curie's first major discovery?")
small_memory_engine.chat("How did they both contribute to early quantum physics?")

# Test memory retention
small_response = small_memory_engine.chat("Summarize what we've discussed about both scientists")
in_md(small_response.response)
=== Testing Memory Retention ===
Small Memory Engine (1000 tokens):
--- Response --- Certainly! Here's a summary of the key points discussed about both Albert Einstein and Marie Curie:

Albert Einstein

  1. Theoretical Contributions:
  • Theory of Relativity: Revolutionized our understanding of space, time, and gravity.
  • Photoelectric Effect: Provided evidence for the quantum nature of light, earning him the Nobel Prize in Physics in 1921.
  • Quantization of Energy: Contributed to the understanding of quantized energy levels in atoms.
  • Wave-Particle Duality: Advanced the concept that light exhibits both wave and particle properties.
  • Einstein's A and B Coefficients: Introduced the concepts of spontaneous and stimulated emission, foundational for lasers and masers.
  1. Personal Traits:
  • Known for his wild hair and unconventional approach to problems.
  • Faced challenges as a Jew in the scientific community.
  1. Relationships:
  • Developed a close friendship with Marie Curie.
  • Participated in the Solvay Conferences, contributing to debates on quantum mechanics.

Marie Curie

  1. Experimental Contributions:
  • Discovery of Radioactivity: Identified and isolated radioactive elements like polonium and radium.
  • Radioactive Decay: Demonstrated that atomic nuclei could undergo spontaneous transformations, releasing energy.
  • Experimental Foundation: Provided meticulous experimental evidence that supported the emerging quantum theory.
  1. Personal Traits:
  • Maintained a composed demeanor despite personal scandals.
  • Faced challenges as a woman in the scientific community.
  1. Relationships:
  • Developed a close friendship with Albert Einstein.
  • Participated in the Solvay Conferences, contributing to discussions on quantum physics.

Mutual Influence and Legacy

  • Solvay Conferences: Both scientists were key participants in these pivotal gatherings that advanced quantum physics.
  • Friendship and Correspondence: Their mutual respect and intellectual exchange enriched the scientific community.
  • Enduring Legacy: Both Einstein and Curie are remembered for their groundbreaking contributions to science and their dedication to unraveling the mysteries of the universe.
In summary, Albert Einstein and Marie Curie were both pioneering figures in early 20th-century physics, with Einstein making significant theoretical contributions and Curie providing crucial experimental evidence. Their friendship and mutual respect further enhanced their impact on the scientific world. ----
print("Large Memory Engine (6000 tokens):")

# Have the same conversation with large memory
large_memory_engine.chat("Tell me about Einstein's Nobel Prize")
large_memory_engine.chat("What was Marie Curie's first major discovery?")
large_memory_engine.chat("How did they both contribute to early quantum physics?")

# Test memory retention
large_response = large_memory_engine.chat("Summarize what we've discussed about both scientists")
in_md(large_response.response)
Large Memory Engine (6000 tokens):
--- Response --- Certainly! Here's a summary of the key points discussed about Albert Einstein and Marie Curie:

Albert Einstein

  1. Nobel Prize:
  • Awarded the Nobel Prize in Physics in 1921 for his discovery of the law of the photoelectric effect.
  • The prize recognized his contribution to theoretical physics and the quantum theory.
  1. Photoelectric Effect:
  • Proposed that light consists of discrete packets of energy called quanta (photons).
  • This work provided crucial evidence for quantum theory and had practical applications in technologies like solar cells.
  1. Quantum Theory:
  • Supported and expanded upon Max Planck's quantum theory.
  • Contributed to the understanding of wave-particle duality.
  1. Relativity:
  • Developed the theories of special and general relativity, though these were not the focus of his Nobel Prize.
  1. Legacy:
  • Considered one of the greatest physicists of all time.
  • Inspired future generations of scientists.

Marie Curie

  1. First Major Discovery:
  • Discovered polonium in 1898, named after her native country, Poland.
  • Followed by the discovery of radium in the same year.
  1. Radioactivity:
  • Pioneered the study of radioactivity, providing essential data for the development of quantum mechanics.
  • Her meticulous chemical processes for isolating radioactive elements revealed the complex nature of atomic decay.
  1. Nobel Prizes:
  • Awarded the Nobel Prize in Physics in 1903 (shared with Pierre Curie and Henri Becquerel) for their work on radioactivity.
  • Awarded the Nobel Prize in Chemistry in 1911 for her discovery of polonium and radium.
  1. Impact on Quantum Physics:
  • Provided foundational experimental evidence that supported the emerging quantum theories.
  • Influenced many other scientists in the development of quantum mechanics.
  1. Legacy:
  • Revolutionized the understanding of atomic structure and radioactivity.
  • Inspired future generations of scientists, particularly women in science.

Combined Contributions to Quantum Physics

  • Interdisciplinary Approach: Einstein's theoretical work and Curie's experimental discoveries together helped to shift the scientific community's understanding of the atomic and subatomic world.
  • Foundational Evidence: Both provided crucial evidence that supported the development of quantum physics.
In summary, Albert Einstein and Marie Curie were pivotal figures in the early development of quantum physics. Einstein's theoretical contributions and Curie's experimental discoveries together laid the groundwork for the quantum revolution in physics. ----

Interactive Streamlit Application Features

The  sc_bedrock_app  provides a comprehensive web interface for testing these chat engines. Here's what makes it powerful:

🎯 Key Application Features

1. 📂 Flexible Data Sources
  • Default documents: Pre-loaded science community files
  • Custom directory paths: Point to any local document folder
  • File upload interface: Drag & drop documents directly in browser
  • Format support: .txt, .md, .pdf, .docx files
**2. 🔧 Real-time Configuration
  • Chat Engine Selection: Switch between condense_question, context, and condense_plus_context
  • Temperature Control: Adjust from 0.0 (focused) to 1.0 (creative)
  • Memory Token Limits: Configure from 1000 to 8000 tokens
  • Custom Prompts: Modify system and context prompts on the fly
**3. 📊 Visual Feedback
  • File Statistics: Real-time count and type breakdown of uploaded documents
  • Processing Status: Clear indicators of document loading and indexing
  • Chat History: Persistent conversation with clear message formatting
  • Error Handling: User-friendly error messages and fallback options
**4. 🎨 Enhanced User Experience
  • Column Layout: Clean two-column design for configuration and chat
  • Expandable Sections: Collapsible file lists and help sections
  • Progress Indicators: Loading spinners and status messages
  • Help Documentation: Built-in examples and usage guidance

🚀 Running the Application

# Navigate to the Bedrock app directory
cd sc_bedrock_app

# Configure AWS credentials
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-east-1"

# Launch the application
./run_app.sh
The application will be available at  http://localhost:8501  with full access to all the chat engine configurations demonstrated in this notebook.

LlamaIndex Chat Engines Summary

This Bedrock integration demonstrates the same powerful chat engine capabilities available in LlamaIndex. While this notebook focuses on basic RAG implementation, LlamaIndex supports multiple sophisticated chat engine modes for enhanced conversational AI applications:

🔄 Condense Question Chat Engine

Architecture: Stateless conversational RAG pattern
The Condense Question chat engine transforms multi-turn conversations into standalone queries by condensing the entire chat history and current question into a single, comprehensive query before performing retrieval.
Key Features:
  • Analyzes conversation thread to understand contextual references
  • Reformulates current question to be self-contained
  • Includes all necessary context from previous exchanges
  • Ideal for maintaining conversation context without explicit memory management
Use Case: Best for applications where conversation history needs to be preserved but explicit memory management is not required.



💾 Context Chat Engine

Architecture: Explicit memory management through ChatMemoryBuffer
The Context chat engine leverages explicit memory management to maintain conversational state across multiple interactions, combining retrieved documents with chat memory.
Key Features:
  • Preserves conversation history up to specified token limit (e.g., 3900 tokens)
  • Retrieves relevant context based on current query
  • References previous exchanges while grounding responses in knowledge base
  • Uses system prompts for domain-specific context guidance
Use Case: Particularly effective for specialized applications where conversation continuity and expert knowledge synthesis are essential for coherent multi-turn interactions.



🔀 Condense Plus Context Chat Engine

Architecture: Hybrid approach combining best features of both engines
The Condense Plus Context chat engine represents the most sophisticated approach, implementing a dual-phase process that first condenses conversation history into standalone questions, then retrieves relevant context while maintaining conversation memory.
Key Features:
  • Phase 1: Condenses conversation history (condense question mode)
  • Phase 2: Retrieves relevant context based on reformulated query
  • Maintains conversation memory through ChatMemoryBuffer
  • Provides domain-specific guidance through context prompts
  • Verbose mode reveals the condensation process
Use Case: Ideal for complex conversational RAG applications requiring both high retrieval precision and coherent multi-turn dialogue capabilities.



🎯 Implementation with Bedrock

All these chat engine modes can be implemented using AWS Bedrock models as demonstrated in this notebook:
# Example: Context Chat Engine with Bedrock
from llama_index.core.memory import ChatMemoryBuffer

memory = ChatMemoryBuffer.from_defaults(token_limit=3900)
chat_engine = index.as_chat_engine(
chat_mode="context",
memory=memory,
system_prompt="Your domain-specific instructions here"
)

📊 Choosing the Right Engine

  • Condense Question: Use when you need conversation context without memory overhead
  • Context: Use when explicit memory management and domain expertise are crucial
  • Condense Plus Context: Use for the most sophisticated conversational experiences requiring optimal retrieval and dialogue quality
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article