Objective

To build an AI system that intelligently routes user questions to the appropriate information source:

  • For AI-related topics (agents, prompt engineering, adversarial attacks), it uses a private knowledge base (via RAG and vector database).
  • For general topics, it uses Wikipedia to fetch the answer.

Tools and Technologies

ComponentTechnology
LLM for RoutingGroq (Gemma2-9b-It) via LangChain
Knowledge BaseAstra DB (Cassandra) with HuggingFace embeddings
Web SearchWikipedia API (via LangChain tools)
Document LoaderWebBaseLoader
Vector IndexingLangChain VectorStoreIndexWrapper
Workflow EngineLangGraph
Frontend (optional)Gradio
Development EnvGoogle Colab

Architecture Flow

Workflow Description

  • The user’s question enters the LangGraph app.
  • A routing LLM decides whether the question should go to:
    • The vector database (for technical questions), or
    • Wikipedia (for general knowledge).
  • Based on this decision, LangGraph routes the input to the appropriate node.
  • The result is returned with the source (vectorstore or wiki_search) specified.

Setup Instructions (in Google Colab)

Step 1: Install Required Libraries

Run this in the first Colab cell:

!pip install langchain langgraph cassio langchain_community

!pip install -U tiktoken langchain-groq langchainhub langchain_huggingface

!pip install arxiv wikipedia gradio

Step 2: Connect to Astra DB

Update the following credentials in the script with your Astra DB token and database ID:

ASTRA_DB_APPLICATION_TOKEN = “your_token_here”

ASTRA_DB_ID = “your_db_id_here”

Step 3: Load and Embed Documents

The script will:

  • Load 3 AI-related blog posts using WebBaseLoader.
  • Split them into chunks.
  • Embed them using HuggingFace.
  • Store them into Astra DB for vector retrieval.

Step 4: Define LangGraph Workflow

The LangGraph is built with:

  • A router node using Groq LLM.
  • Two branches: wiki_search and retrieve.
  • Conditional edges based on question type.

Step 5: Run Inference

You can test the system by changing the question like this:

inputs = {“question”: “What is agent?”}

The response will either come from the vectorstore (RAG) or Wikipedia based on the router’s decision.

How to Use

In Colab

  1. Open the notebook and run all cells.
  2. Ask a question using the defined inputs.
  3. The system will display:
    • The retrieved answer.
    • The node (either vectorstore or wiki_search) that handled it.

Locally with Gradio (optional)

  1. Just run the collab file it will directly start