app
~
~RESPONSE~
CompiledGraph(nodes={'agent': ChannelInvoke(bound=RunnableLambda(call_model)
| ChannelWrite(channels=[ChannelWriteEntry(channel='agent', value=None, skip_none=False), ChannelWriteEntry(channel='messages', value=RunnableLambda(...), skip_none=False)]), config={'tags': []}, channels={'messages': 'messages'}, triggers=['agent:inbox'], mapper=functools.partial(<function _coerce_state at 0x7de64d4c9ab0>, <class '__main__.AgentState'>)), 'action': ChannelInvoke(bound=RunnableLambda(call_tool)
| ChannelWrite(channels=[ChannelWriteEntry(channel='action', value=None, skip_none=False), ChannelWriteEntry(channel='messages', value=RunnableLambda(...), skip_none=False)]), config={'tags': []}, channels={'messages': 'messages'}, triggers=['action:inbox'], mapper=functools.partial(<function _coerce_state at 0x7de64d4c9ab0>, <class '__main__.AgentState'>)), 'agent:edges': ChannelInvoke(bound=RunnableLambda(runnable), config={'tags': ['langsmith:hidden']}, channels={'messages': 'messages'}, triggers=['agent']), 'action:edges': ChannelInvoke(bound=ChannelWrite(channels=[ChannelWriteEntry(channel='agent:inbox', value='action', skip_none=True)]), config={'tags': ['langsmith:hidden']}, channels={'messages': 'messages'}, triggers=['action']), '__start__': ChannelInvoke(bound=ChannelWrite(channels=[ChannelWriteEntry(channel='__start__', value=None, skip_none=False), ChannelWriteEntry(channel='messages', value=RunnableLambda(...), skip_none=False)]), config={'tags': ['langsmith:hidden']}, channels={None: '__start__:inbox'}, triggers=['__start__:inbox']), '__start__:edges': ChannelInvoke(bound=ChannelWrite(channels=[ChannelWriteEntry(channel='agent:inbox', value=None, skip_none=False)]), config={'tags': ['langsmith:hidden']}, channels={'messages': 'messages'}, triggers=['__start__'])}, channels={'messages': <langgraph.channels.binop.BinaryOperatorAggregate object at 0x7de64de19e70>, 'agent:inbox': <langgraph.channels.any_value.AnyValue object at 0x7de64de19fc0>, 'action:inbox': <langgraph.channels.any_value.AnyValue object at 0x7de64de1a080>, '__start__:inbox': <langgraph.channels.any_value.AnyValue object at 0x7de64de1ad10>, 'agent': <langgraph.channels.ephemeral_value.EphemeralValue object at 0x7de64de1b2b0>, 'action': <langgraph.channels.ephemeral_value.EphemeralValue object at 0x7de64de1b880>, '__start__': <langgraph.channels.ephemeral_value.EphemeralValue object at 0x7de64de18340>, '__end__': <langgraph.channels.last_value.LastValue object at 0x7de64de18490>, <ReservedChannels.is_last_step: 'is_last_step'>: <langgraph.channels.last_value.LastValue object at 0x7de64de1b670>}, output='__end__', hidden=['agent:inbox', 'action:inbox', '__start__', 'messages'], snapshot_channels=['messages'], input='__start__:inbox', graph=<langgraph.graph.state.StateGraph object at 0x7de64de18880>)
运行测试1:"什么是大型语言模型中的 RAG?它是何时出现的?"
from langchain_core.messages import HumanMessage
inputs = {"messages" : [HumanMessage(content="What is RAG in the context of Large Language Models? When did it break onto the scene?")]}
response = app.invoke(inputs)print(response)
~RESPOSNE~
{'messages': [HumanMessage(content='What is RAG in the context of Large Language Models? When did it break onto the scene?'),
AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{"query":"RAG in the context of Large Language Models"}', 'name': 'duckduckgo_search'}}, response_metadata={'token_usage': {'completion_tokens': 25, 'prompt_tokens': 171, 'total_tokens': 196}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_b28b39ffa8', 'finish_reason': 'function_call', 'logprobs': None}),
FunctionMessage(content="Large language models (LLMs) are incredibly powerful tools for processing and generating text. However, they inherently struggle to understand the broader context of information, especially when dealing with lengthy conversations or complex tasks. This is where large context windows and Retrieval-Augmented Generation (RAG) come into play. These advanced, generalized language models are trained on vast datasets, enabling them to understand and generate human-like text. In the context of RAG, LLMs are used to generate fully formed responses based on the user query and contextual information retrieved from the vector DBs during user queries. Querying In the rapidly evolving landscape of language models, the debate between Retrieval-Augmented Generation (RAG) and Long Context Large Language Models (LLMs) has garnered significant attention. Retrieval-augmented generation (RAG) is an AI framework for improving the quality of LLM-generated responses by grounding the model on external sources of knowledge to supplement the LLM's internal representation of information. Implementing RAG in an LLM-based question answering system has two main benefits: It ensures that the model has ... RAG stands for R etrieval- A ugmented G eneration. RAG enables large language models (LLM) to access and utilize up-to-date information. Hence, it improves the quality of relevance of the response from LLM. Below is a simple diagram of how RAG is implemented.", name='duckduckgo_search'),
AIMessage(content="RAG stands for Retrieval-Augmented Generation in the context of Large Language Models (LLMs). It is an AI framework that improves the quality of LLM-generated responses by grounding the model on external sources of knowledge to supplement the LLM's internal representation of information. RAG enables LLMs to access and utilize up-to-date information, thereby improving the relevance and quality of the responses generated by the model. RAG broke onto the scene in the rapidly evolving landscape of language models as a way to enhance the capabilities of LLMs in understanding and generating human-like text.", response_metadata={'token_usage': {'completion_tokens': 117, 'prompt_tokens': 491, 'total_tokens': 608}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None})]}
response['messages'][-1].content
~RESPONSE~
RAG stands for Retrieval-Augmented Generation in the context of Large Language Models (LLMs). It is an AI framework that improves the quality of LLM-generated responses by grounding the model on external sources of knowledge to supplement the LLM's internal representation of information. RAG enables LLMs to access and utilize up-to-date information, thereby improving the relevance and quality of the responses generated by the model. RAG broke onto the scene in the rapidly evolving landscape of language models as a way to enhance the capabilities of LLMs in understanding and generating human-like text.
运行测试2:"谁是检索增强生成论文的主要作者,他们在哪所大学就读?"
question = "Who is the main author on the Retrieval Augmented Generation paper - and what University did they attend?"
inputs = {"messages" : [HumanMessage(content=question)]}
#
response = app.invoke(inputs)print(response['messages'][-1].content)
~RESPONSE~
The main author on the "Retrieval Augmented Generation" paper is Huayang Li. Unfortunately, the University they attended is not mentioned in the summary provided.
运行测试3:"谁是检索增强一代论文的主要作者?"
question = "Who is the main author on the Retrieval Augmented Generation paper?"
inputs = {"messages" : [HumanMessage(content=question)]}
response = app.invoke(inputs)print(response['messages'][-1].content)
~RESPONSE~
The main authors on the paper "A Survey on Retrieval-Augmented Text Generation" are Huayang Li, Yixuan Su, Deng Cai, Yan Wang, and Lemao Liu.
4 - RAG智能体应用前景
既然我们已经了解了基础知识,让我们谈谈RAG智能体如何在各个领域和组织中扩展和发展。因为坦率地说,对智能语言生成和信息检索能力的需求只会不断增长。
企业知识管理:想象一下有一支RAG智能体团队专门致力于帮助你的组织管理其庞大的知识资源。这些智能体可以专门用于处理不同领域或部门,实现对多个数据源的信息高效访问和综合。谈论打破壁垒,促进跨职能协作!
客户服务与支持:老实说,处理客户查询和支持请求可能是一个真正头痛的问题,特别是当它们涉及跨多个知识库或文档来源的复杂问题时。但是通过RAG智能体,你可以拥有真正理解这些复杂查询的智能体,从各种来源检索相关信息,并提供准确和个性化的回应,实现差异化的客户体验!
智能助理与对话人工智能:你是否曾希望你的虚拟助手能够真正理解并回应你复杂的查询,而不会丢失上下文?好吧,这正是RAG智能体要做的。通过将这种方法整合到智能助手和对话人工智能系统中,你可以让它们进行更自然、更引人入胜的对话体验。就像有一个真实的伴侣,但没有尴尬的沉默。
研究与科学探索:想象一下有一个智能体,可以筛选大量的科学文献、实验数据和研究发现,从这些多样化的来源中综合知识,发现新的见解并生成突破性的假设。RAG智能体可能是推动科学发现达到新高度的秘密武器。
内容生成和创意写作:RAG智能体可能成为你在生成高质量、连贯和符合上下文的内容方面的新伙伴。这些智能体可以在各种文本来源上接受训练,使它们能够在创作过程中为你提供帮助,同时培养原创性和创造力。
教育与电子学习:在教育和电子学习领域,RAG智能体可以彻底改变我们对个性化学习经验的看法。这些智能体可以适应个人学习者的需求,检索相关的教育资源,并生成定制的解释和学习材料,将学习过程推向新高度。
医疗保健与医学信息学:想象一下有一个RAG智能体,可以从多个来源,如研究论文、临床指南和患者数据中获取和综合医学知识。这些智能体可以帮助医疗保健专业人员做出明智的决策,提供准确和最新的信息,同时确保患者隐私和数据安全。
法律和法规合规:在法律和法规领域,理解和解释复杂的法律文件和判例非常重要,而RAG智能体可能会改变游戏规则。这些智能体可以检索和分析相关的法律信息,促进研究、案件准备和合规监督。
5 - RAG智能体挑战机遇
尽管RAG智能体方法具有巨大的潜力,但要确保其成功采用和持续发展,必须解决一些很重要的挑战。让我们更仔细地看看其中一些障碍。
数据质量和管理:RAG智能体的性能严重依赖于基础数据源的质量和管理。如果数据不完整、不准确或不相关,那么这些智能体生成的输出也会反映这一点。确保数据的完整性、准确性和相关性对于生成可靠和可信任的输出至关重要。必须实施有效的数据管理策略和质量保证机制,以确保一切顺利运行。
可扩展性和效率:随着智能体、工具和数据源的数量不断增加,可扩展性和效率变得至关重要。我们谈论的是管理系统资源、优化检索过程,并确保智能体之间的无缝通信。如果这些方面处理不当,即使是最先进的RAG智能体系统也可能变得迟缓和低效。没有人想要一个缓慢而不响应的人工智能助手。
可解释性和可说明性: 虽然RAG智能体可提供智能响应,但确保其决策过程的透明度和可解释性至关重要。开发可解释的模型和技术,解释代理的推理过程和所使用的信息来源,可以增强信任感和责任感。毕竟,你不会希望在不了解人工智能如何得出结论的情况下盲目听从它的建议。
隐私和安全:RAG智能体系统可能处理敏感或机密数据,引发隐私和安全方面的担忧。必须实施强大的数据保护措施、访问控制和安全通信协议,以保护敏感信息并维护用户隐私。你最不想看到的就是你的机密数据泄露。
道德考量:RAG智能体的开发和部署引发了有关偏见、公平性和潜在滥用的道德问题。制定道德准则、进行彻底测试和实施防止意外后果的保障措施对于负责任的采用至关重要。我们不希望我们的人工智能助手发展出任何歧视性或有害的倾向。
尽管存在这些挑战,RAG智能体的未来为创新和增长提供了令人兴奋的机遇。在多智能体协调、强化学习和自然语言理解等领域的持续研究和开发可以进一步提升RAG智能体的能力和适应性。
此外,将RAG智能体与其他新兴技术(如知识图谱、本体论和语义网技术)结合起来,可以开辟知识表达和推理的新途径,实现更复杂和上下文感知的语言生成。
想象一下拥有RAG智能体,它可以无缝地导航和利用庞大的知识图谱,建立联系和推断,这对人类而言几乎是不可能实现的。就像有一个超级助手,不仅可以检索信息,还可以理解信息中的错综复杂的关系。
随着组织和行业拥抱RAG智能体技术,共同努力和知识分享对于推动其广泛采用和解决共同挑战至关重要。通过培育研究人员、开发人员和从业者的社区,RAG智能体生态系统可以茁壮成长,从而产生开创性的应用程序和解决方案,彻底改变我们与和利用信息的方式。
6 - 拥抱RAG智能体范式
RAG智能体方法不仅仅是另一个时髦词汇或短暂的趋势——它代表着语言生成和信息检索领域的一种范式转变。通过弥合传统RAG实现与自主智能体的智能之间的差距,RAG智能体解决了过去的局限,并为信息真正触手可及的未来铺平了道路。
具有上下文感知、智能检索、多智能体协作和推理能力等功能,RAG智能体提供了一种曾经被认为是科幻小说的复杂性和适应性水平。从企业知识管理和客户服务到科学研究和内容生成,RAG智能体的应用是广泛而深远的。想象一下拥有一支智能体团队,致力于帮助你驾驭庞大的信息海洋,当你需要时检索到你需要的信息,并以一种有意义的方式呈现出来。
当然,伴随着巨大的力量而来的是巨大的责任,我们不能忽视这项技术所面临的挑战。数据质量、可扩展性、可解释性、隐私和道德考量都是必须克服的障碍,以确保RAG智能体系统的负责任开发和部署。拥抱RAG智能体范式不仅仅是采用一种新技术;它是在人类与机器之间寻求理解和发现的过程中培育一种共生关系。它是利用智能体的力量来增强我们自身能力的过程,使我们能够解决复杂的问题并发现几年前还无法想象的见解。
所以,让我们毫不犹豫地投入到RAG智能体的世界中,拥抱智能信息检索和生成技术的下一代。