📍 Multimodal-RagBased-Assistant (https://github.com/latamishra/Multimodal-RagBased-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.
✔️ 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
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
The RAG engine retrieves relevant passages from PDFs/text using LangChain.
VisionEngine generates a perceptual description of an uploaded image — with constraints to avoid identity assumptions or hallucination.
The ReasoningEngine merges:
- RAG text answer
- Image description
to produce a multimodal answer.
MetricsEvaluator computes:
- grounding_score
- hallucination_risk
- text_evidence_ratio
- image_evidence_ratio
- latency_ms
git clone https://github.com/latamishra/Multimodal-RagBased-Assistant.git
cd Multimodal-RagBased-Assistantpython3.12 -m venv venv_312
source venv_312/bin/activatepip install --upgrade pip
pip install -r requirements.txtCreate a .env file with:
GOOGLE_API_KEY=<your_google_api_key>
python3 run.pyFastAPI will start on:
http://127.0.0.1:8000
Ask a question (optionally with an image):
Parameters (multipart/form-data):
question: stringimage: file (optional)
Response:
{
"question": "...",
"answer": "...",
"image_description": "...",
"metrics": { ... },
"evidence": [
{ "id": "...", "source": "...", "page": ..., "content": "..." },
...
]
}curl http://127.0.0.1:8000/healthReturns:
{"status":"healthy"}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"
- 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.
| 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 |
✔ Provide clear, unambiguous images ✔ Ensure documents are correctly indexed ✔ Tune text + vision prompt patterns ✔ Avoid overly interpretive language
You can write unit tests for:
- Vision outputs
- RAG retrieval
- Evaluator scoring
- Endpoint functionality
- Vision model may still produce generic religious or cultural context; constrained to “visible elements”.
- Hallucination scoring is heuristic.
- Image understanding depends on model quality.
✔ Add streamlit/gradio UI ✔ Add 2-agent validator workflow ✔ Add Drift detection / monitoring
- LangChain
- Hugging Face Transformers
- Gemini LLM via LangChain Google GenAI