An intelligent, production-grade AI assistant built for FreightTiger’s Case Study Round. It continuously monitors shipping records, tracks cost per tonne-km across corridors, flags anomalies against historical and peer baselines, and cross-references real-world context notes (fuel hikes, weather disruptions, festival surcharges, toll changes) using a hybrid vector retrieval (RAG) system with strict anti-hallucination guardrails.
Ahmedabad-Mumbai (2025-01-20): Note N002 (Festival week surcharge).Chennai-Bangalore (2025-02-24 to 2025-03-10): Note N001 (Highway flooding, detours & elevated costs).Chennai-Bangalore (2025-03-17): Note N009 (Completion of flood repairs, returning to baseline).Delhi-Jaipur in Nov 2024; Mumbai-Pune in late 2025 where Note N010 confirms compliance costs were absorbed without rate changes).All calculations follow FreightTiger’s grading specifications exactly:
\(\text{Cost per Tonne-Km} = \frac{\sum \text{freight\_cost\_inr}}{\sum (\text{quantity\_tonnes} \times \text{distance\_km})}\)
Shipment dates are grouped into Monday-to-Sunday weeks where week_of is the Monday date (YYYY-MM-DD).
vs_own_history)For any given route in week $W$: \(\text{Baseline}_{\text{own}} = \frac{1}{K} \sum_{k=1}^{K} \text{Cost}_{W-k} \quad (1 \le K \le 8)\)
+X.X% vs this route's past averagevs_similar_routes)For a route of type $T \in {\text{Short}, \text{Medium}, \text{Long}}$ in week $W$: \(\text{Baseline}_{\text{peer}} = \frac{1}{|P|} \sum_{r \in P} \text{Cost}_{r, W}\) where $P$ is all other routes sharing length bucket $T$ in week $W$ (excluding the route itself).
+X.X% vs similar-length routes this weekA route is evaluated as a candidate spike if:
Cost is rising vs history: $\text{vs_own_pct} > 0$Out of the ordinary: $\text{vs_own_pct} \ge 20\%$ OR $\text{vs_peer_pct} \ge 20\%$Context notes are indexed in a hybrid retrieval engine combining TF-IDF semantic vector similarity with route-corridor metadata matching and temporal event-window filtering.
A working demo isn’t enough; the assistant is designed to resist adversarial traps:
Mumbai-Pune, 2025-09-15): The assistant retrieves closest note N006, explains that it mentions stable demand with no disruptions, and correctly marks the verdict as Yes (unexplained).No (justified) row cites the exact matched_note_id.matched_note_id and flagged = Yes.shipping_cost_assistant/
├── data/
│ ├── shipment_records.csv # 2,940 shipment records
│ ├── context_notes.csv # 10 real-world context notes
│ └── sample_output_format_v2.csv# Target contract schema
├── outputs/
│ ├── output.csv # Primary output matching sample_output_format.csv
│ ├── all_routes_weekly.csv # Complete 728-week dataset analysis
│ ├── token_cost_log.json # Detailed token usage & cost breakdown
│ ├── reproducibility_diff.txt # 3-run zero-diff verification report
│ └── reproducibility/ # Artifacts from 3 independent runs
├── src/
│ ├── data_engine.py # Route grouping, weekly tracking, baselines
│ ├── vector_store.py # Pure-python TF-IDF vector retrieval (RAG)
│ ├── reasoner.py # Anti-hallucination guardrail evaluation
│ ├── token_logger.py # Honest token & cost logging
│ └── assistant.py # Pipeline orchestrator
├── main.py # CLI entrypoint
├── eval_harness.py # Evaluation harness & benchmark tester
├── test_reproducibility.py # 3-run reproducibility verifier
├── interactive_qa.py # Stretch Goal: Natural language Q&A assistant
├── README.md # Comprehensive documentation
└── WALKTHROUGH.md # 10-minute Round 2 presentation guide
pandas, numpy (Standard library handles vector indexing with zero C-DLL dependency issues).python main.py
Outputs generated:
outputs/output.csv (Primary output matching sample_output_format.csv contract)outputs/all_routes_weekly.csv (Full 728 route-week dataset)outputs/token_cost_log.json (Cost and token log)python test_reproducibility.py
python eval_harness.py
# Single query
python interactive_qa.py --query "why did Chennai-Bangalore get pricier in March?"
# Interactive terminal mode
python interactive_qa.py
| Metric | Value |
|---|---|
| Model | Gemini 2.5 Flash / Open-Source Deterministic Engine |
| Number of Inference Calls | 19 calls (triggered selectively on candidate anomalies) |
| Total Input Tokens | 6,531 tokens |
| Total Output Tokens | 1,036 tokens |
| Published Input Pricing | $0.075 / 1M tokens |
| Published Output Pricing | $0.300 / 1M tokens |
| Total Cost for Entire Dataset | $0.000801 USD |
The self-contained evaluation harness (eval_harness.py) scores against ground-truth benchmark cases:
Delhi-Jaipur (2024-11-11): Cost 4.17, vs_own +35.5%, vs_peer +21.0%, Flagged: Yes -> PASSAhmedabad-Mumbai (2025-01-20): Cost 3.29, vs_own +29.5%, vs_peer +22.5%, Flagged: No (justified), Note: N002 -> PASSMumbai-Pune (2025-09-15): Cost 3.98, vs_own +9.2%, vs_peer +23.6%, Flagged: Yes, Note: “” -> PASSChennai-Bangalore (2025-02-24): Cost 3.58, vs_own +31.5%, vs_peer +38.7%, Flagged: No (justified), Note: N001 -> PASSChennai-Bangalore (2025-03-03): Cost 3.48, vs_own +22.8%, vs_peer +32.0%, Flagged: No (justified), Note: N001 -> PASS