# Google Cloud OnAIR 研討會 [攜手 Google Gemini 開創 AI 世代新佈局](https://cloudonair.withgoogle.com/events/taiwan-cloud-onair-magic-of-google-gemini-2024?utm_content=feb_newsletter&utm_medium=email&utm_source=cloud_sfdc&utm_campaign=FY23-Q4-apac-ASPA758-onlineevent-er-TWCloudOnAirMagicofGoogleGemini_MC&utm_term=-&mkt_tok=ODA4LUdKVy0zMTQAAAGRh0TOq6mcn8yNUkMQUBxzpHQXKgNW40rSmGhTxZBAGhD26XHLaYdqILx799UwcbzUJu6Ktx3FOCiGKoLiceh1wsbf6om47wimhUQUwnBurFpsWgkr3co) :::info 這是Google 2024/1/31辦的線上中文研討會, 內容主推當然是他們的Gemini相關的應用 不過這場會議並非完全一股腦地介紹他們的產品, 在RAG上面的概念還是蠻值得聽的 ::: ## GenAI技術全面解析 [GOOGLE CLOUD ONAIR 線上研討會系列 | 攜手 Google Gemini 開創 AI 世代新佈局|Gemini 面面觀:多模態 Gemini 及 Gen AI 技術全面解析](https://www.youtube.com/watch?v=lxSLLWhVWv4&t=1s) :::info 下面這張圖, Google解釋了目前的AI的進展, Level5代表AI能力全面屌打人類 分為兩個部分**Narrow AI** and **General AI** **Narrow AI**代表了AI在部分領域上面的能力, 像是車牌辨識, 下棋, 目前Narrow AI大部分可以做到Level2, 少數領域被這些大公司做爛的情況下可以屌打人類(像是AlhpaZero) **General AI**目前還停在Level1, 可以贏過沒有具備專業能力的人類 影片14:50提到, 當通用型model遇到行業專業問題勢必要做修正 ::: ![截圖 2024-02-28 凌晨12.09.07](https://hackmd.io/_uploads/SkEKYYj3T.jpg) **Google Gemini工商時間** - Gemini Ultra : 希望之後能夠推出 - Gemini Pro : Bard - Gemini Nano : 可以運行在Pixel 8上面(雜訊去除, 亮點消除) - Gemini的設計目標 -- Natively Multimodal. -- Sophisticated Resoning. -- Advanced Coding 4x less 輸入成本. 2x less 輸出成本. **Gemini Software Fullstack** ![截圖 2024-02-28 凌晨1.14.21](https://hackmd.io/_uploads/B1w5Oqjn6.jpg) - Duet AI : AI assistant for Developers, 類似Copilot但是是針對Google cloud的, 支援20種code, 支援測試code, 解釋code, 甚至會教學怎麼deploy在Google Cloud - AI Studio/Vertex AI : 希望no code也能幫助企業產生出AI 應用 - Gemini Models : 模型 - AI Optimized Infrastructure. :::info 可以看出, 要有一個AI產品出來, 需要的條件是 1. application (以後傾向都用AI協助產生) 2. models 3. infrastructure ::: **Google model產品**. - Gemini Pro - Gemini Ultra - imgen2 : 文生圖 - MedLM : 醫療的model. - DITO : 影像分割. (Google做的) - Mistral. (Unicorn) - imageBind (Meta的multimodal), 不只文字, 影像, 背景音就可以讓AI對這張圖片做連結 **Google產品finetune** ![截圖 2024-02-28 凌晨1.24.49](https://hackmd.io/_uploads/SJmbj5o3p.jpg) 包含了這幾個features - Discover : 選用哪個model - Tune : 提供了Prompt, Supervised, RLHF, Distillation Step by Step - Augment : RAG - Deploy : 如何驗證 (AutoMetrics, Auto SxS.) **Finetune data quality(是針對不同的finetune情景, 需要的data與model需求)** ![截圖 2024-02-28 凌晨1.28.07](https://hackmd.io/_uploads/r14po9j36.jpg) - Prompt : 1-10 examples - finetune : 100 examples - RLHF : 5K-10K examples - Distilling : 100~1000 unlabled prompts :::info 這樣可以大概知道需要準備多少的data可以finetune模型 ::: **Google 現在有support 130個model** **Automatic Side by Side**. ![截圖 2024-02-28 清晨6.32.40](https://hackmd.io/_uploads/HkiM7133T.jpg) --- **Google工商時間 again** **imagen2**. - 可以產生更高品質的圖片 - 可以指定把字放的圖片中的哪個地方 **SynthID**. 透過GenAI會產生一個浮水印, 也是一個Copyright. **Indemnification** 透過Google產生的東西, Google可以提供一部分的擔保. **NotebookLM(類似Chatpdf)** A platform can search anything, (Only in US now) **Segment Anything Model(SAM)**. Google有TPUv4, TPUv5e TPUv5p有開放架構 **Google GenAI Resources** ![截圖 2024-02-28 清晨6.56.39](https://hackmd.io/_uploads/S1KT_yn3a.jpg) --- ## 打造實體的RAG [當大型語言模型遇上企業資料集:打造你的檢索增強生成式 AI (RAG, Retrieval-Augmented Generation)](https://cloudonair.withgoogle.com/events/taiwan-cloud-onair-magic-of-google-gemini-2024/watch?talk=se2) **多模態應用**. - 直接拍照計算價格. - 拍照後的故障排除. - 影像生成文字描述. **因為語言模型都是網路上拿到的資料,所以不會貼近企業所想要的資料** **缺乏Grounding的問題 (稱為幻覺)** **與資料互動** ![截圖 2024-02-28 清晨7.09.53](https://hackmd.io/_uploads/rk3k3y2hT.jpg) **不同的tuning方法與成本** ![截圖 2024-02-28 清晨7.12.01](https://hackmd.io/_uploads/ryML3kn26.jpg) **Retrieval簡易架構** ![截圖 2024-02-28 清晨7.13.30](https://hackmd.io/_uploads/SkFi3J226.jpg) **何時使用finetune, 何時使用RAG** ![截圖 2024-02-28 清晨7.15.02](https://hackmd.io/_uploads/HkU-Tk326.jpg) :::info **Better retrieval == Better result (所以Retrieval model也是需要訓練的)** ::: ### RAG面臨的挑戰 **與品質相關的挑戰** - 涉及多個步驟導致結果不精確 - 需要品質評估工具 : 衡量各個工作流程跟組件的品質(**Ragas**) - 檢索效果不佳 -- 低精度 : 檢索不到相關的文件 -- 低Recall : 所有相關的文件不一定被找到 - 錯誤的回應生成, 存在幻覺 **與品質無關的挑戰** - 處理不準確性, 定期更新資料 - 治理 : 控制權限 - 額外成本 : 向量儲存, inference. (但還是比LLM訓練便宜) - 延遲增加 : 多種資料處理步驟 - 監控工具需求 : 需要監控各個組件 - 人力需求 : 需要運維整個RAG ### 工程面 ![截圖 2024-02-28 上午9.11.16](https://hackmd.io/_uploads/SyLSOWhhT.jpg) **Chunking & Organizing Data(需要調整的部分)** - 理解文件決定Chunk長度(文章/是否有列表), 這邊要try and error - 使用Embedding model. (適合的chunk長度) - 使用者查詢類型. (使用者想查詢的範圍有多大) ![截圖 2024-02-28 上午9.12.13](https://hackmd.io/_uploads/S10d_-32a.jpg) **固定大小chunking**. (目前langchain已經有support) ![截圖 2024-02-28 上午9.19.26](https://hackmd.io/_uploads/HJJNqZ226.jpg) **根據上下文的chuncking**. ![截圖 2024-02-28 上午9.20.38](https://hackmd.io/_uploads/SkEOcWh2T.jpg) **特殊的格式(table), 理解的方式不同**. **Specialized Chunking**. ![截圖 2024-02-28 上午9.23.47](https://hackmd.io/_uploads/ryEVsW23a.jpg) ### Choosing Embedding Model. ![截圖 2024-02-28 上午9.26.14](https://hackmd.io/_uploads/Hy96o-22a.jpg) ![截圖 2024-02-28 上午9.27.10](https://hackmd.io/_uploads/Hk0lh-nha.jpg) BigQuery現在支援客製化的tensorflow的model ### Vector Store是重要的一環. ![截圖 2024-02-28 上午9.28.35](https://hackmd.io/_uploads/SJo82W336.jpg) **向量相似度**. **使用ANN(Approximate Nearest Neighbor)** 因為如果資料庫有百萬等級, 搜尋會太耗時. ![截圖 2024-02-28 上午9.31.38](https://hackmd.io/_uploads/rJAWaW2na.jpg) 1s or few 100 ms 就要完成搜尋. 階層式搜尋. ### Summary - Embedding : English or non-English - VectorDB : pgvector - LLM for text : model - Prompt = query + relevant documents Vertex AI Search : 不用開發任何東西, Google已經幫忙做好了 ### RAG 建議作法 ![image](https://hackmd.io/_uploads/HJokq233p.png) ## RAG:改變知識搜尋與問答的方式 [RAG:改變知識搜尋與問答的方式](https://cloudonair.withgoogle.com/events/taiwan-cloud-onair-magic-of-google-gemini-2024/watch?talk=se3) Documents -> Embedding -> VectorStore User ask question -> Embedding -> Find adjecent vectors 把question and 找到的content一起送到prompt ![image](https://hackmd.io/_uploads/ByGqih23p.png) ### 新的搜尋方式 希望搜尋以後, 請語言模型讀完以後summary起來回覆我們最後想要的結果 Functional Requirements - Fetch most relevant documents - Answer the question based on retrieved documents - Recommendation based on historical data (根據先前人都點甚麼連結作為推薦的可能性) - Feedback Loop ![image](https://hackmd.io/_uploads/S1Yeyp3hp.png) - 針對不同的部分做轉換(Title, Issue, Comment) - Full content也會做embedding - 然後把full content給LLM model先做一個summary - 最後把上面三樣東西送到PGVector ![image](https://hackmd.io/_uploads/rk1Uyahn6.png) task_type不同, 應該要定義成不同的embedding ![image](https://hackmd.io/_uploads/B1rieahn6.png) Summary希望先做下面的部分 ![image](https://hackmd.io/_uploads/B1nTl632p.png) ![image](https://hackmd.io/_uploads/BJGgZp23T.png) 使用者互動與feedback loop Google是使用Google analytic ![image](https://hackmd.io/_uploads/B1647pnhT.png) ### Design Consideration 一開始儲存dataset的時候就做summary了(針對需要及時拿到結果的) - 比較快 - 但是index time會變長 - summary document但是不會根據問題 另一種方式是爬資料回來的時候不做summary, 只有當被找出來再做summary(針對批次性的) - high query response time - low index time - summarization based on user's query ### Chunked-Summarization vs Full Content Summarization Chunked-Summarization - 可以處理更大的文件 - 可以根據不同的結構(章節)做處理 - 複雜的data processing - may lost context during processing chunks Full Content Summarization - Input tokens limitation - Simple data processing - Always reference to the full content - during data processing ### 值得繼續Study的項目 - MMLU : Massive Multitask Language Understanding** : Multimodal的benchmark - Gemini white paper - Multimodal怎麼訓練 - Google的imgen2 - MedLM - DITO - Mistral - imageBind - 驗證模型的方式 : AutoMetrics, Automatic Side by Side - Ragas(驗證RAG的方式) :::danger ## Summary of this topic ### RAG 實做 1. 針對data的不同部份做轉換 (Title, Issue, Comment, Reference...) -- PDF文件有Camelot(表格提取), Unstructured, PyPDF2, PDFPluimber, LLM Sherpa 3. 會把Full content也做embedding 4. 把full content給LLM model先做一個summary 5. 把上面三樣東西送到PGVector存起來 6. 看完文章以後先生幾個問題問這篇文章 8. 把question跟找到的content一起送到prompt : [{question:""}, {content:""}]然後給LLM去回答 9. 後面的LLM必須針對前面的prompt回答最相關的回答是甚麼 10. metadata可以增加先前的人都停留在哪邊 11. feedback loop持續改進 ### RAG 可以改進的方式 1. Chunk的決定 : 使用者的檔案/文章類型, 使用的embedding model, 使用者欲查詢的答案範圍 2. 混合搜尋 (關鍵字+向量搜尋) 3. 透過Metadata (前人搜尋結果) 4. Query rewriting (有一個model幫忙重新寫query的語句 : Prompt) 5. Reranking : 還沒有很仔細看, 但看起來是使用 6. Recursive : 7. Embedded Tables : 8. Parent Document : 參考其他文件 9. Finetune : Embedding, LLM, Reranking :::