Giter VIP home page Giter VIP logo

aws-ai-rag's Introduction

AWS AI RAG

tests coverage flake8 mypy pycodestyle pydocstyle pylint pyright bandit

Using RAG (Retrieval-augmented generation) to provide an LLM with up-to-date news.

Try the working demonstration.

Architecture summary

Main technologies/products used:

  • Amazon OpenSearch Service (free tier on t2.small.search with 10GB EBS storage)
  • AWS Bedrock generative AI (Anthropic Claude 3 Sonnet) and vector embedding (Titan)
  • AWS Lambda, SQS, API Gateway, S3, EventBridge, CloudFormation, DynamoDB
  • FastAPI, Mangum

Data ingestion pipeline

  1. A periodically triggered lambda function obtains the URLs of the ten "most read" news articles from the main BBC news website https://www.bbc.co.uk/news and places each URL as a message in a SQS queue.
  2. A second lambda removes URLs from the queue and does the following steps:
    • Check the OpenSearch vector database and discard the URL if it has already been processed
    • Extract the news article's full text and other information such as publication date, keywords, etc.
    • Form a short text chunk comprising the article title and first 3 paragraphs
    • Produce a vector embedding of the text chunk using the AWS Bedrock Titan model
    • Store the article data as a document in the OpenSearch database, indexed by the embedding vector
  3. A third lambda periodically deletes old documents from the OpenSearch database.

Query process with RAG

  1. Serve a simple static website to the user from S3
  2. The user sends a question in a REST POST request to the API Gateway, which is routed to a lambda
  3. Produce a vector embedding of the question using AWS Bedrock
  4. Do a semantic similarity search on the OpenSearch vector database using the vector embedding
  5. Combine the full text of the most relevant search results with the question to produce a RAG query
  6. Pass the RAG query to the AWS Bedrock Titan LLM and obtain a response
  7. Present the response to the user, together with the URLs of the source news articles selected in step 4 as citations/further reading.

Front end

github.com/e-mit/aws-api-website is used to create an API Gateway which serves the files in /static/ and proxies the API.

This also configures a custom domain name for the gateway URL and provides CAPTCHA support.

Setup notes

  • AWS Bedrock is available in only a subset of AWS regions (e.g. Paris, not London)
  • Must enable account access to the LLMs ("Foundation Models") with Bedrock before use

aws-ai-rag's People

Contributors

e-mit avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.