kotaemon核心GraphRAG、Agent、多模態(tài)代碼解讀!
要說最近RAG方面火熱的項目當(dāng)屬kotaemon,短時間暴漲8k star
??一個開源、清晰、強(qiáng)大且可定制的RAG UI??
kotaemon的亮點是可定制化RAG UI,核心技術(shù)點是混合索引(Vector、Keyword、GraphRAG)、復(fù)雜推理Agent(ReAct、ReWOO、MemoryGIST 和 GraphReader)、多模態(tài)。
混合索引(GraphRAG)
混合索引主要是指:全文和矢量融合,這里還有一個選型就是集成了RAG的新范式:GraphRAG
看代碼直接用的微軟GraphRAG
檢索后重排采用LLMReranker
RERANK_PROMPT_TEMPLATE = """Given the following question and context,
return YES if the context is relevant to the question and NO if it isn't.
> Question: {question}
> Context:
>>>
{context}
>>>
> Relevant (YES / NO):"""
復(fù)雜推理Agent
推理目前主要實現(xiàn)了react與rewoo,tools包括google搜索工具、llm工具、wikipedia工具,可以自定義擴(kuò)展。
react還是經(jīng)典的Thought、Action、Action Input、Observation模式
zero_shot_react_prompt = PromptTemplate(
template="""Answer the following questions as best you can. Give answer in {lang}. You have access to the following tools:
{tool_description}
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action, should be different from the action input of the same action in previous steps.
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
#Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin! After each Action Input.
Question: {instruction}
Thought:{agent_scratchpad}
"""
)
rewoo(Reasoning WithOut Observation),該范式將推理過程與外部觀察分離
planner的prompt模版
from kotaemon.llms import PromptTemplate
zero_shot_planner_prompt = PromptTemplate(
template="""You are an AI agent who makes step-by-step plans to solve a problem under the help of external tools.
For each step, make one plan followed by one tool-call, which will be executed later to retrieve evidence for that step.
You should store each evidence into a distinct variable #E1, #E2, #E3 ... that can be referred to in later tool-call inputs.
##Available Tools##
{tool_description}
##Output Format (Replace '<...>')##
#Plan1: <describe your plan here>
#E1: <toolname>[<input here>] (eg. Search[What is Python])
#Plan2: <describe next plan>
#E2: <toolname>[<input here, you can use #E1 to represent its expected output>]
And so on...
##Your Task##
{task}
##Now Begin##
"""
)
solver的prompt模版
zero_shot_solver_prompt = PromptTemplate(
template="""You are an AI agent who solves a problem with my assistance. I will provide step-by-step plans(#Plan) and evidences(#E) that could be helpful.
Your task is to briefly summarize each step, then make a short final conclusion for your task. Give answer in {lang}.
##My Plans and Evidences##
{plan_evidence}
##Example Output##
First, I <did something> , and I think <...>; Second, I <...>, and I think <...>; ....
So, <your conclusion>.
##Your Task##
{task}
##Now Begin##
"""
)
多模態(tài)
多模態(tài)體現(xiàn)在豐富的loader上面,多達(dá)十幾種比如:html_loader.py、excel_loader.py、unstructured_loader.py等,可以借鑒用于其它場景哦
多模態(tài)測試,AdobeReader
https://github.com/Cinnamon/kotaemon
本文轉(zhuǎn)載自?? PaperAgent??,作者: PaperAgent
