06. Agentic RAG

Agentic RAG

Agent is useful when you need to decide whether to use the search tool. Agent-related content Agent arrow-up-rightSee page.

To implement a search agent LLM Just give the search tool access.

this LangGraph arrow-up-rightCan be integrated into.

Preferences

Basic PDF-based Retrieval Chain creation

Here, we create a Retrieval Chain based on PDF documents. Retrieval Chain with the simplest structure.

However, LangGraph creates Retirever and Chain separately. Only then can you do detailed processing for each node.

Reference

  • As covered in the previous tutorial, we omit the detailed description.

then retriever_tool Generate tools.

Reference

document_prompt is a prompt to express the document retrieved.

Available key

  • page_content

  • metadata Key: (Example) source , page

When using

"<document><context>{page_content}</context><metadata><source>{source}</source><page>{page}</page></metadata></document>"

Agent status

I will define a graph.

To each node state Object.

state messages It consists of a list.

Each node in the graph adds content to this list.

Node and Edge

Agent-based RAG graphs can be configured as follows:

  • state Is a set of messages

  • each node Update (add) status

  • Conditional edge Determine the node to visit next Let's make a simple grader.

graph

  • call_model Start as an agent

  • Determine if the agent calls the function

  • If you decide to call a function, it is time to call the tool (retriever) action Run

  • Message the output value of the tool ( state ) To call the agent

Visualize the graph.

Search for documents below unnecessary An example of a question.

Randomly below Document search impossible Question example.

Therefore, in the process of constantly searching for documents GraphRecursionError Occurred.

Last updated