kotaemon核心GraphRAG、Agent、多模态代码解读!

发布于 2024-9-6 15:19
浏览
0收藏

要说最近RAG方面火热的项目当属kotaemon,短时间暴涨8k star

​一个开源、清晰、强大且可定制的RAG UI​

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

kotaemon的亮点是可定制化RAG UI,核心技术点是混合索引(Vector、Keyword、GraphRAG)、复杂推理Agent(ReAct、ReWOO、MemoryGIST 和 GraphReader)、多模态


混合索引(GraphRAG)

混合索引主要是指:全文和矢量融合,这里还有一个选型就是集成了RAG的新范式:GraphRAG

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

看代码直接用的微软GraphRAG

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

检索后重排采用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):"""

复杂推理Agent

推理目前主要实现了reactrewoo,tools包括google搜索工具、llm工具、wikipedia工具,可以自定义扩展。

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

react还是经典的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),该范式将推理过程与外部观察分离

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

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##
"""
)

多模态

多模态体现在丰富的loader上面,多达十几种比如:html_loader.py、excel_loader.py、unstructured_loader.py等,可以借鉴用于其它场景哦


kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

多模态测试,AdobeReader

kotaemon核心GraphRAG、Agent、多模态代码解读!-AI.x社区

https://github.com/Cinnamon/kotaemon

本文转载自​ PaperAgent​,作者: PaperAgent

已于2024-9-6 17:11:13修改
收藏
回复
举报
回复
相关推荐