Skip to content
Charan Kumar Reddy
AI & AgentsCompleteSynthetic data

DriveDocs AI

Multimodal RAG with verified citations and prompt-injection guardrails

Multimodal RAG assistant over a fictional car manual: MiniLM and CLIP embeddings in FAISS, a LangChain tool-calling agent, verified citations, and prompt-injection and PII guardrails.

Uses an offline planner, so the public demo does not call an LLM.

Recall@5 on the 39-question set (written with the corpus)
1.0
reports/evaluation_report.json
citation precision (file + page)
0.924
reports/evaluation_report.json
DriveDocs AI workspace with example questions and system status for the text and image indexes

The problem

Answering questions over a vehicle manual needs text and diagrams, citations to real pages, and protection against personal data and injected instructions in the documents.

The approach

MiniLM text and CLIP image embeddings in FAISS feed a LangChain tool-calling agent; answers carry verified file and page citations, behind prompt-injection and PII guardrails.

Architecture

  1. 01

    Ingestion and redaction

    pypdf parses PDFs page by page and extracts embedded figures, alongside Markdown, text and image files; text is chunked, PII is redacted and instruction-like sentences are flagged before anything is embedded.

  2. 02

    Embeddings and indexes

    MiniLM (384-d, int8 ONNX) embeds text and CLIP ViT-B/32 (512-d, 4-bit ONNX) embeds images on ONNX Runtime, stored in two separate FAISS IndexFlatIP indexes.

  3. 03

    Input guardrails

    Each question is screened for prompt-injection patterns and requests for personal data; injected clauses are removed and PII requests are refused before retrieval.

  4. 04

    LangChain agent

    A tool-calling loop over search_manual_text and search_manual_diagrams; the default planner is a deterministic offline LangChain chat model, with OpenAI or Gemini planners as optional extras.

  5. 05

    Evidence and answer

    Per-modality relevance thresholds and rank fusion select evidence, and the default generator writes extractive answers with [Source: file, Page N] tags.

  6. 06

    Verification and output

    A citation verifier checks each tag against the document registry, page and retrieved passage, output guardrails mask PII and injected text, and FastAPI returns the answer with the agent trace and a security report.

Key decisions

  • Keeps text and image vectors in separate FAISS indexes with their own relevance thresholds and merges them by rank fusion, because CLIP and MiniLM similarity scales differ; on the bundled set rank fusion showed no gain over raw-score mixing and is kept because it does not compare incompatible scores.
  • Defaults to a deterministic offline planner and extractive answers, so the demo needs no API key and answers are quotations; the README notes an LLM planner generalises better to unusual phrasings.
  • Redacts PII at ingestion, before embedding, so it cannot be retrieved or sent to an LLM, and scrubs every response again; detection is pattern-based and misses names in free prose.
  • Removes any citation tag that does not match a registered document, an existing page and a retrieved passage; verification checks provenance and word overlap, not semantic entailment.
  • Runs quantized models on ONNX Runtime instead of PyTorch, builds the demo index at deploy time and unloads the CLIP vision tower when idle, to fit a 512 MB instance.
  • Searches anyway if an LLM planner answers without calling tools, so the returned answer is never the planner's own unverified prose.

Results

  • All QA and security cases pass in the committed evaluation report, after fixes made in response to an earlier run that failed several cases.
  • Location questions with no textual answer are answered by retrieving the engine-bay diagram through CLIP.
  • The public demo uses the offline planner and extractive answers and does not call an LLM.
Measured results and the files they come from
MetricValueSource
Recall@5 (39-question set)1.0reports/evaluation_report.json
Citation precision (file + page)0.924reports/evaluation_report.json
Groundedness (39-question set)1.0reports/evaluation_report.json
Attack success (23 cases)0.0reports/evaluation_report.json

How it is tested

  • 155 pytest test functions (the README reports 207 tests) using mock embeddings and scripted LangChain chat models: agent planning and fallback, guardrail patterns and false positives, citation verification, ingestion hardening (malformed files, encodings, decompression bombs), FAISS persistence, and API errors, size limits and path traversal.
  • CI runs the unit and API suite, then downloads the real ONNX models, builds the demo index, runs the real-model tests and run_eval.py --strict, which fails on any QA or security regression.
  • The evaluation uses a 39-question QA set and a 23-case security suite (direct injection, indirect injection through a poisoned document, PII extraction and benign controls), both written by the author alongside the synthetic corpus.

Limits, stated plainly

  • The evaluation sets are small and were written with the synthetic corpus; the first full run passed 33 of 39 QA and 13 of 23 security cases, so the scores are indicative only and say nothing about adaptive attackers.
  • Guardrails are pattern-based and do not catch every paraphrase.
  • No OCR: text inside scanned pages is not extracted, and CLIP reads only large labels.
  • Relevance thresholds were calibrated on the bundled corpus and need recalibration for other manuals.
  • Single process, no authentication, local filesystem storage and exact flat FAISS search; demo uploads are visible to everyone and lost on restart.

Stack

PythonLangChainFAISSONNX RuntimeCLIPMiniLMFastAPIpypdf