[線上課程筆記]DeepLearningAI - Advanced Retrieval for AI with Chroma
課程簡介 Deep Learning AI 新的課程,如何優化 IR/RAG on Chroma 。 講師是 Chroma co-founder 有以下三個技術: Query Expansion: 透過相關概念來擴展查詢。 Cross-encoder reranking: 透過不同檢索編碼來排序查詢結果。 Training and utilizing Embedding Adapters: 透過加入 adapter 來優化檢索結果。 課程資訊: https://learn.deeplearning.ai/advanced-retrieval-for-ai/ RAG Pitfall 經常查詢 RAG 結果回來會是不相關的,怎麼看出來? 透過一個 umap 套件 import umap import numpy as np from tqdm import tqdm embeddings = chroma_collection.get(include=['embeddings'])['embeddings'] umap_transform = umap.UMAP(random_state=0, transform_seed=0).fit(embeddings) # 畫點出來 import matplotlib.pyplot as plt plt.figure() plt.scatter(projected_dataset_embeddings[:, 0], projected_dataset_embeddings[:, 1], s=10) plt.gca().set_aspect('equal', 'datalim') plt.title('Projected Embeddings') plt.axis('off') 比較相近的問題(單一問題,比較容易) 這樣看起來查詢的資訊跟我們問得蠻相近的,紅色是回答的。綠色是前面幾個相關的。 如果問句有兩個以上,或是問句本身就不太相關。 這樣就會出現差相當多的結果,造成查詢的資料相關度過少。出來的結果當然也就很差。 解決方式就要靠接下來的三個方法。 Query Expansion 透過延伸的假設答案,加上原來的問題。一起下去詢問: def augment_query_generated(query, model="gpt-3.5-turbo"): messages = [ { "role": "system", "content": "You are a helpful expert financial research assistant. Provide an example answer to the given question, that might be found in a document like an annual report. " }, {"role": "user", "content": query} ] response = openai_client.chat.completions.create( model=model, messages=messages, ) content = response.choices[0].message.content return content e.g. Q: Was there significant turnover in the executive team? 先用這個 Q 直接問 OpenAI 得到可能的解答 hypothetical_answer,但是因為沒有查詢特有...
繼續閱讀