Skip to content

Latest commit

 

History

History
52 lines (41 loc) · 1.95 KB

File metadata and controls

52 lines (41 loc) · 1.95 KB

Retrieval Augmented Generation

In the context of large language models, "RAG" stands for Retrieval-Augmented Generation. It refers to a technique that combines the power of a language model (for generation) with external retrieval of information (for augmentation). In a RAG framework, the model retrieves relevant documents or information from an external knowledge base or corpus and uses that data to improve or inform its text generation process.

This allows the model to answer questions or generate text that is more accurate and up-to-date, even if that information wasn't part of the model's original training data. It's commonly used in scenarios where up-to-date or specific factual information is important, such as question answering, summarization, or providing contextually rich responses.

This script asks an OpenAI LLM for the list of winners of the Nobel Prize in physics from 2020 to 2024. Since the LLM was trained before the announcement in 2024 it can only tell the winners from 2020 to 2023. However, with RAG we can extend the training of the LLM seamlessly.

flowchart TD
    A[Client] --Makes request for the information\nwhich the LLM wasn't trained with.--> B[3rd party source... DB, Web, Etc.]
    B --Adds the retrieved information.--> A[Client]
    A[Client] --Makes requests with query.--> C["Large Language Model"]
    C --LLM augments its training\nwith the extra information,\ngenerates content and responds.--> A
Loading

Python Version

>=3.12

You can use pyenv to set up the right version. Example pyenv local v3.12.7

Setup Local Env

python -m venv .venv

Change directory

cd rag

Install

pip install -r requirements.txt

Setup OpenAI API Key

The script talks to the OpenAI API. A project and API key are needed.

export OPENAI_API_KEY=<your-api-key>

Run Script without RAG

python main.py

Run Script with RAG

python main.py --rag true