new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain · LangGraph · all subjects

agentic-rag

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Agentic RAG decision point

An agentic RAG system differs from a fixed retrieve-then-generate pipeline by having the model decide whether to retrieve or answer directly. The agent makes this choice at the generate_query_or_respond node, which calls the model on current messages with the retriever tool bound, allowing retrieval to run only when the model requests it.

Document grading with structured output

Document grading uses a model with a structured output schema to evaluate whether retrieved documents are relevant to the user's question. The grading function returns the name of the next node: generate_answer if documents are relevant, or rewrite_question if they are not.

Retry loop for weak retrieval

When the grader marks documents as irrelevant, the graph rewrites the original question into a clearer search query and routes back to generate_query_or_respond so the agent can retrieve again. This retry mechanism allows the agent to recover from weak initial retrieval instead of hallucinating answers.

RAG answer generation keeps prompt tight

The generate_answer node combines the original user question with retrieved context in a tight prompt to ensure the model answers from provided context instead of inventing details.

Agentic RAG graph flow

The complete agentic RAG graph flows as follows: (1) Start at generate_query_or_respond to determine whether to call retriever_tool; (2) If tool_calls are returned, call retriever_tool for context, otherwise respond directly; (3) Grade retrieved documents with grade_documents; (4) If not relevant, rewrite_question and loop back to generate_query_or_respond; (5) If relevant, proceed to generate_answer with the ToolMessage containing retrieved context for final response generation.

Give your agent this brain