Amazon Bedrock Samples

repository·main·Indexed 23 days ago

https://github.com/aws-samples/amazon-bedrock-samples

A collection of pre-built examples and blueprints for implementing Generative AI capabilities using Amazon Bedrock. This includes tutorials and notebooks for Advanced Prompt Optimization (APO), Bedrock Agents with Code Interpreter, Agentic Guardrails using frameworks like CrewAI, LangGraph, and Strands Agents, and Agent Blueprint Templates deployed via AWS CDK.

Tokens
243.1K
Snippets
469
Records
871
Agent score
80%

What's inside amazon-bedrock-samples

  1. Overview of Amazon Bedrock Model Distillation

    main

    Amazon Bedrock Model Distillation is a workflow that automates the creation of smaller, faster, and more cost-efficient models. It delivers use-case specific accuracy comparable to larger, more capable 'teacher' models.

    Key Features:

    • Automated Workflow: Automates teacher response generation, data synthesis, and student model fine-tuning with optimized hyperparameter tuning.
    • No Labeling Required: Removes the need to manually create labeled datasets for fine-tuning.
    • Efficiency: Provides high accuracy while maintaining the speed of smaller models.
    • Cost Optimization: Reduces inference costs compared to using larger, advanced models.

    Common Use Cases:

    • Retrieval-Augmented Generation (RAG)
    • Document Summarization
    • Chatbot Deployments
    • Text Classification
  2. Overview of the Citation-Aware Model Distillation Pipeline

    main

    This pipeline implements a four-stage process to distill knowledge from large language models (LLMs) into smaller, specialized models specifically optimized for citation-aware question answering. The goal is to create efficient models that maintain high-quality citation capabilities.

    The pipeline consists of the following stages:

    1. Data Preparation: Uses the SQuAD v2.0 dataset and implements a structured XML output format to handle both answerable and 'impossible' questions.
    2. Model Distillation: Transfers knowledge from a teacher model to a student model.
    3. Batch Inference: Executes large-scale inference using distributed processing and retry mechanisms.
    4. Evaluation: Assesses the distilled model using metrics like Citation Coverage, Correctness, Completeness, Faithfulness, Helpfulness, and Logical Coherence.
  3. Introduction to Prompt Engineering on Amazon Bedrock

    main

    Prompt engineering is the practice of optimizing the quality and performance of a foundation model's response to a request. When working with Amazon Bedrock, effective prompt engineering typically involves the following techniques:

    • Word choice and Phrasing: Selecting specific language to guide the model.
    • Few-shot learning: Providing specific examples within the prompt to demonstrate the desired output.
    • Structure: Using line breaks and content separators to organize information.
    • Format Alignment: Following established formats that align with how the specific model was trained.
    • Stop Sequences: Using stop sequences to instruct the model on when to cease text generation.
  4. Overview of Podcast Analytics with Bedrock Data Automation

    main

    This workshop demonstrates how to build a multimodal data processing pipeline using the Bedrock Data Automation (BDA) service to analyze raw podcast audio files. The goal is to transform unstructured audio into structured, actionable data for downstream analysis.

    Key capabilities explored include:

    • Transcription: Extracting textual transcripts from raw audio.
    • Speaker Identity: Identifying different speakers within the audio.
    • Content Moderation: Analyzing audio for specific content types.
    • Sentiment Analysis: Determining the emotional tone of the discussion.
    • Summarization: Generating quick summaries of podcast content.
    • Metadata Extraction: Incorporating timestamps, speaker information, and chapter segmentation into the pipeline.
  5. Overview of RAG using structured and unstructured data

    main

    This implementation demonstrates a Retrieval Augmented Generation (RAG) approach that leverages multiple data sources to answer queries. It uses a MultiRetrievalQAChain to combine information from:

    1. Unstructured Data: Retrieved from an Amazon Bedrock knowledge base (e.g., PDFs, text files).
    2. Structured Data: Retrieved from a database (e.g., Amazon Athena) using a Text-to-SQL approach.

    The system uses the Claude 3.0 Sonnet language model to generate responses by synthesizing information from these sources while maintaining conversation context via a memory buffer.

  6. Overview of Event-driven Ticket Resolution with Bedrock Agents

    main

    This project demonstrates an automated technical support workflow using an intelligent agentic architecture. Instead of a traditional chatbot, it uses an Amazon Bedrock Agent to interact with live systems, create action plans, and resolve support tickets autonomously.

    Core Workflow

    1. Ticket Submission: An employee submits a ticket, which is written to the TicketDynamoDBTable.
    2. Event Trigger: A DynamoDB Stream captures the change and triggers a Lambda function (ProcessTicketDynamoDBStreamFunction).
    3. Agent Reasoning: The Lambda function invokes the Amazon Bedrock Agent, which uses reasoning to decide how to resolve the ticket.
    4. Action Execution: The agent uses action groups to modify data in various DynamoDB tables (Environment, User Access, User, and Ticket tables).
    5. Context Retrieval: The agent uses an Amazon Bedrock Knowledge Base to retrieve ticket resolution protocols from ingested documents.
    6. Notification: Once processed, the system notifies the user via Amazon SNS.
  7. Overview of Bedrock-ICYM (I See You Monitoring)

    main

    Bedrock-ICYM is a Python-based observability and evaluation solution designed for Amazon Bedrock applications. It provides a way to log and track metrics for Knowledge Bases, Agents, InvokeModel calls, Function Calling, and Guardrails.

    Data is ingested via Amazon Kinesis Data Firehose into an Amazon S3 bucket, which enables downstream analysis using Amazon Athena and visualization via Amazon QuickSight. The solution uses a decorator-based approach to minimize integration effort and supports both production (Firehose) and local (in-memory) logging modes.

  8. Overview of Amazon Bedrock Prompt Flows

    main

    Amazon Bedrock Prompt Flows is a tool for building, testing, and deploying generative AI workflows by linking foundation models (FMs), prompts, and AWS services. It supports both a visual drag-and-drop interface (low-code/no-code) and programmatic control via SDKs.

    Key capabilities include:

    • SDK Integration: Programmatically create, update, and run flows using tools like boto3.
    • Visual Builder: Connect nodes representing prompts, AWS services, and business logic.
    • Testing: Iterative testing directly within the Amazon Bedrock console.
    • Versioning & Deployment: Version flows for easy rollbacks and A/B testing via traffic splitting. Versioned flows are accessible via API.
    • Collaboration: Integration with Amazon Bedrock Studio for SSO-enabled team collaboration.
    • AWS Service Integration: Incorporate services like Amazon Lex as nodes within a flow.
    • Code Hooks: Use AWS Lambda functions to process node outputs within the workflow.
  9. Overview of Function Calling (Tool usage) in Amazon Bedrock

    main

    Function calling allows you to provide Large Language Models (LLMs) with descriptions of tools and functions. The LLM can then intelligently decide when and how to invoke these tools based on a user's query to help answer questions or complete complex tasks.

    This repository provides several implementation patterns for function calling using different Amazon Bedrock interfaces and third-party frameworks.

  10. Overview of Amazon Titan Multimodal Embeddings G1

    main

    The Amazon Titan Multimodal Embeddings G1 model allows you to generate embeddings for both text and image data. These embeddings enable multimodal search and Retrieval Augmented Generation (RAG) workflows, such as:

    • Searching for images using text queries.
    • Searching for images using image queries.
    • Searching using a combination of both text and images.
  11. Overview of the Bedrock-ICYM observability pipeline

    main

    Bedrock-ICYM (I See You Monitoring) is a custom solution designed to collect and analyze observability and metadata for Amazon Bedrock applications (Knowledge Bases, Agents, Invoke Model, Function Calling, and Guardrails).

    Data Flow

    1. Ingestion: JSON data is ingested into Amazon Kinesis Firehose.
    2. Processing: A Lambda function (Python 3.9) intercepts the stream to flatten nested JSON structures.
    3. Storage: Processed data is stored in an Amazon S3 bucket.
    4. Cataloging: An AWS Glue Crawler scans the S3 bucket to create tables in an AWS Glue database.
    5. Analysis: Data is queried via Amazon Athena or visualized using Amazon QuickSight dashboards.

    Tracked Metrics

    The pipeline captures several key data points:

    • User input: The original query.
    • LLM response: The generated output.
    • Response duration: Latency of the LLM generation.
    • Application metadata: Application name, User ID, etc.
    • Evaluation Metrics: Performance and quality insights for Knowledge Bases, Agents, and general response relevance.