Skip to content

About

It's a basic Multimodal Rag Based Assistant, used fastVLM and LLM to generate response based on the pdf and images you feed to the model.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📍 Multimodal-RagBased-Assistant (https://github.com/latamishra/Multimodal-RagBased-Assistant)


📘 Multimodal RAG-Based Assistant

A multimodal AI assistant that combines Retrieval-Augmented Generation (RAG) with vision understanding, explainability, and evaluation metrics — delivered as a FastAPI service.

The system answers questions grounded in text, interprets images, merges text+image context, and evaluates responses with metrics like grounding score, hallucination risk, and evidence ratios.


🚀 Features

✔️ Text RAG using LangChain and document retrieval ✔️ Vision integration using Apple FastVLM (or replaceable with BLIP/CLIP) ✔️ Multimodal reasoning (combines text + image context) ✔️ Explainability via structured evidence references ✔️ Evaluation metrics including:

  • Grounding score
  • Text & image evidence ratios
  • Hallucination risk
  • Latency ✔️ FastAPI API for question answering ✔️ Modular, extensible, production-ready structure

📁 Repository Structure

Multimodal-RagBased-Assistant/
├── app/
│   ├── main.py                  # FastAPI server
│   ├── reasoning.py             # Combines RAG + vision reasoning
│   ├── vision.py                # Vision model wrapper (FastVLM)
│   ├── evaluator.py             # Metrics evaluation
│   ├── rag.py                   # RAG engine wrapper
│   └── ...                      # Other modules
├── data/                        # Uploaded images & documents
├── requirements.txt             # Python dependencies
├── run.py                       # Entrypoint
├── .env                         # Environment variables
└── README.md

🧠 How It Works (High-Level)

📌 Step 1 — Text Retrieval

The RAG engine retrieves relevant passages from PDFs/text using LangChain.

📌 Step 2 — Vision Perception

VisionEngine generates a perceptual description of an uploaded image — with constraints to avoid identity assumptions or hallucination.

📌 Step 3 — Reasoning

The ReasoningEngine merges:

  • RAG text answer
  • Image description

to produce a multimodal answer.

📌 Step 4 — Evaluation

MetricsEvaluator computes:

  • grounding_score
  • hallucination_risk
  • text_evidence_ratio
  • image_evidence_ratio
  • latency_ms

🧪 Installation & Setup

1. Clone the Repo

git clone https://github.com/latamishra/Multimodal-RagBased-Assistant.git
cd Multimodal-RagBased-Assistant

2. Create & Activate Python 3.12 venv

python3.12 -m venv venv_312
source venv_312/bin/activate

3. Install Dependencies

pip install --upgrade pip
pip install -r requirements.txt

4. Add Environment Variables

Create a .env file with:

GOOGLE_API_KEY=<your_google_api_key>

🏃 Running the API

python3 run.py

FastAPI will start on:

http://127.0.0.1:8000

📡 API Endpoints

POST /ask

Ask a question (optionally with an image):

Parameters (multipart/form-data):

  • question: string
  • image: file (optional)

Response:

{
  "question": "...",
  "answer": "...",
  "image_description": "...",
  "metrics": { ... },
  "evidence": [
    { "id": "...", "source": "...", "page": ..., "content": "..." },
    ...
  ]
}

GET /health

curl http://127.0.0.1:8000/health

Returns:

{"status":"healthy"}

🧪 Sample Use Case

Ask with image:

curl -X POST "http://127.0.1:8000/ask" \
  -F "question=Describe this image and relate to the text." \
  -F "image=@/path/to/image.jpg"

⚙️ Vision Model Notes

Apple FastVLM (default)

  • Loaded via Transformers with trust_remote_code=True
  • Generates perceptual, not identity-specific descriptions

Alternative: You can swap in BLIP2/CLIP models if FastVLM weights are unavailable.


📊 Evaluation Metrics Explained

Metric Meaning
grounding_score How much of the answer overlaps evidence token space
text_evidence_ratio Portion of answer grounded in text evidence
image_evidence_ratio Portion of answer grounded in image
hallucination_risk Likelihood of hallucination (low → safe)
latency_ms End-to-end response time

🧹 Tips for Better Results

✔ Provide clear, unambiguous images ✔ Ensure documents are correctly indexed ✔ Tune text + vision prompt patterns ✔ Avoid overly interpretive language


🧪 Testing

You can write unit tests for:

  • Vision outputs
  • RAG retrieval
  • Evaluator scoring
  • Endpoint functionality

⚠️ Safety & Limitations

  • Vision model may still produce generic religious or cultural context; constrained to “visible elements”.
  • Hallucination scoring is heuristic.
  • Image understanding depends on model quality.

📦 Bonus Extensions (optional)

✔ Add streamlit/gradio UI ✔ Add 2-agent validator workflow ✔ Add Drift detection / monitoring


🧠 Acknowledgements

  • LangChain
  • Hugging Face Transformers
  • Gemini LLM via LangChain Google GenAI

About

It's a basic Multimodal Rag Based Assistant, used fastVLM and LLM to generate response based on the pdf and images you feed to the model.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages