Skip to content

Add self-correcting RAG agent notebook with LangGraph#3330

Open
LuciferDono wants to merge 3 commits intoopenvinotoolkit:latestfrom
LuciferDono:llm-agent-langgraph
Open

Add self-correcting RAG agent notebook with LangGraph#3330
LuciferDono wants to merge 3 commits intoopenvinotoolkit:latestfrom
LuciferDono:llm-agent-langgraph

Conversation

@LuciferDono
Copy link
Copy Markdown

Summary

Adds a new notebook notebooks/llm-agent-langgraph/llm-agent-langgraph.ipynb implementing a self-correcting RAG agent using LangGraph and OpenVINO.

The notebook demonstrates a stateful RAG pipeline that goes beyond linear retrieve-then-generate by adding:

  • Document grading — LLM evaluates relevance of each retrieved document
  • Query rewriting — if no relevant documents found, the agent reformulates the query and re-retrieves
  • Conditional routing via LangGraph state machine with a configurable max-rewrite limit

Key features

  • Model selection widget (Phi-3-mini-4k, Llama-3.2-1B, Qwen2.5-1.5B)
  • INT4 weight compression via Optimum CLI
  • ChromaDB vector store with bge-small-en-v1.5 embeddings
  • Interactive Gradio demo showing agent reasoning steps
  • Full table of contents, telemetry, and scarf pixel

Files added

  • notebooks/llm-agent-langgraph/llm-agent-langgraph.ipynb
  • notebooks/llm-agent-langgraph/README.md

Closes #3240

Implements a new notebook demonstrating a self-correcting RAG pipeline
using LangGraph state machine with four nodes: retrieve, grade documents,
generate answer, and rewrite query. Uses Phi-3-mini with INT4 compression
via OpenVINO for efficient inference on Intel hardware.

Closes openvinotoolkit#3240
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@aleksandr-mokrov
Copy link
Copy Markdown
Collaborator

@LuciferDono, thanks for the contribution!

I tried running the notebook locally and hit an error during model conversion with optimum-cli. Could you please share the full conversion log from a successful run on your side? Also, which versions of optimum-intel and openvino did you use?

@LuciferDono
Copy link
Copy Markdown
Author

Hey @aleksandr-mokrov, sorry about the wait. I hit the same conversion error on my end and have been debugging it.

Found a few issues in the notebook. Fixing them up and running a clean test now. Will reply here with the full conversion log and the exact openvino/optimum-intel versions once it goes through.

Switch to cmd_helper.optimum_cli() for conversion, use
HuggingFacePipeline.from_model_id(backend="openvino") for model
loading, pin package versions, add device_widget and telemetry.
@LuciferDono
Copy link
Copy Markdown
Author

LuciferDono commented Mar 18, 2026

Pushed the fix and tested on Colab (Intel Xeon, Python 3.12). Everything runs through now.

Versions: openvino 2026.1.0, optimum-intel from git HEAD, nncf 3.0.0, transformers 4.53.3, torch 2.8.0+cpu

Main things I changed; switched to cmd_helper.optimum_cli() for the conversion, moved model loading to HuggingFacePipeline.from_model_id with the openvino backend, and pinned torch/torchvision to avoid a version conflict that was breaking the export. Phi-3-mini converts and runs fine, the self-correction loop fires correctly on vague queries.

@LuciferDono
Copy link
Copy Markdown
Author

hey @aleksandr-mokrov, just checking in, did the fix work on your end? let me know if you need anything else from me.

Pushed the fix and tested on Colab (Intel Xeon, Python 3.12). Everything runs through now.

Versions: openvino 2026.1.0, optimum-intel from git HEAD, nncf 3.0.0, transformers 4.53.3, torch 2.8.0+cpu

Main things I changed; switched to cmd_helper.optimum_cli() for the conversion, moved model loading to HuggingFacePipeline.from_model_id with the openvino backend, and pinned torch/torchvision to avoid a version conflict that was breaking the export. Phi-3-mini converts and runs fine, the self-correction loop fires correctly on vague queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request : New Notebook for Self-Correcting RAG Agent with LangGraph and OpenVINO

2 participants