Skip to content

Implement Corrective RAG (Web Search Fallback) #46

@joelabreurojas

Description

@joelabreurojas

Goal

To make the ProVAI agent more robust by implementing Corrective-RAG (CRAG). This involves adding a web search tool as a fallback mechanism when the initial document retrieval fails to find relevant information.

To-Do List

  • Pre-requisite: The LangGraph state machine from Issue Plan and Execute DB Migration to PostgreSQL #43 must be complete.
  • Add Dependency: Add tavily-python to pyproject.toml.
  • Create Web Search Tool:
    • Create a WebSearchService that uses the Tavily API to perform a search and return the results as LangChain Document objects.
    • Add a web_search node to your LangGraph (graph_nodes.py).
  • Implement Document Grader Node:
    • Create a grade_documents(state) node that uses an LLM to determine if the retrieved documents are relevant to the user's question. This grader should return a simple "yes" or "no".
  • Update Graph Logic:
    • Add the new grade_documents and web_search nodes to the graph.
    • Modify the conditional edge after the retrieve node. If the grade_documents node returns "no", the edge should route to the web_search node. If "yes", it should route to the generate node.
  • Write tests for cases where web search should be triggered.

Acceptance Criteria

  • When a query is asked for which there is no relevant information in the local documents, the agent correctly identifies this, performs a web search, and uses the web results to generate an answer.
  • The decision-making process is clearly visible in the LangSmith trace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions