---
# System prepended metadata

title: RAG - Retrieval-Augmented Generation
tags: [log]

---

# RAG - Retrieval-Augmented Generation

## 架構
### 檢索器
從外部知識庫檢索訊息
Embedding Vector Database

RAG + Sentence Transformer

[Sentence Transformer](https://axk51013.medium.com/%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8%E8%B6%85%E5%BC%B7nlp-model-bert-db9c2a331b0f)

### 生成器
生成回應

## 運作
### Create External Data
* API, Databases, document repositories
* Embedding language models: creates a knowledge library that the generative AI models can understand

### Retrieve Relevant Information
* Convert query to vector and match with vector databases

### Augment the LLM Prompt
* Augments the user input (prompts) by adding the relevant retrived data in context
* Allows the LLM to generate an accurate answer to user queries

[Setting up a Private Retrieval Augmented Generation (RAG) System with Local Llama 2 model and Vector Database
](https://medium.com/unstructured-io/setting-up-a-private-retrieval-augmented-generation-rag-system-with-local-vector-database-d42f34692ca7)

![image](https://hackmd.io/_uploads/rJP-T97JC.png)

![image](https://hackmd.io/_uploads/SJenn5Q1R.png)


![image](https://hackmd.io/_uploads/Bk0bkqXeR.png)


https://learnbybuilding.ai/tutorials/rag-from-scratch
