{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import path_setup  # noqa: F401 — adds project root to sys.path\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8e9f5186",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "de5897b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     name           start_time             end_time  input_tokens  \\\n",
      "0     rag  1785328999065523818  1785328999066923856           NaN   \n",
      "1  search  1785345600408090860  1785345600472549871           NaN   \n",
      "2     llm  1785345600498654399  1785345601417900402           NaN   \n",
      "3     rag  1785345600407981419  1785345601428992749           NaN   \n",
      "4  search  1785346051721740855  1785346051760978276           NaN   \n",
      "5     llm  1785346051779277751  1785346052971642439         825.0   \n",
      "6     rag  1785346051721612708  1785346052994837542           NaN   \n",
      "7  search  1785347479872550768  1785347480613928970           NaN   \n",
      "8     llm  1785347480633554893  1785347482081077094         795.0   \n",
      "9     rag  1785347479872352090  1785347482094178201           NaN   \n",
      "\n",
      "   output_tokens  cost  \n",
      "0            NaN  None  \n",
      "1            NaN  None  \n",
      "2            NaN  None  \n",
      "3            NaN  None  \n",
      "4            NaN  None  \n",
      "5          240.0  None  \n",
      "6            NaN  None  \n",
      "7            NaN  None  \n",
      "8           86.0  None  \n",
      "9            NaN  None  \n"
     ]
    }
   ],
   "source": [
    "import sqlite3\n",
    "import pandas as pd\n",
    "\n",
    "conn = sqlite3.connect(\"sqlite/otel/traces.db\")\n",
    "\n",
    "df = pd.read_sql(\n",
    "    \"SELECT * FROM spans\",\n",
    "    conn\n",
    ")\n",
    "\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "80e30590",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[92m23:21:17 - LiteLLM:WARNING\u001b[0m: utils.py:2730 - register_model: model=5fde7336d29cebcd30558ae0085b7916413c5817d51a8443bbd6001c998e0990 not in built-in cost map and no prefix/region variant matched; cache cost fields will default to 0. To track cache cost, add cache_creation_input_token_cost and cache_read_input_token_cost to model_info\n",
      "\u001b[92m23:21:17 - LiteLLM:WARNING\u001b[0m: utils.py:2730 - register_model: model=mistral/ministral-3b-2512 not in built-in cost map and no prefix/region variant matched; cache cost fields will default to 0. To track cache cost, add cache_creation_input_token_cost and cache_read_input_token_cost to model_info\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You should **not** move an injured person at an accident site **unless there is an immediate danger** (e.g., fire, oncoming traffic, toxic fumes, or another vehicle threatening their safety).\n",
      "\n",
      "If the casualty is conscious but shows signs of spinal injury, severe fractures, difficulty breathing, or extreme pain, **do not move them** unless absolutely necessary. Instead, stabilize them and wait for professional help.\n"
     ]
    }
   ],
   "source": [
    "from rag.starter import RAGProduction\nfrom config import make_llm_client\nfrom embedder import Embedder\nfrom ingest import load_faq_data, build_index, build_vector_index\nllm_client = make_llm_client()\ndocuments = load_faq_data()\ntext_index = build_index(documents)\nembedder = Embedder()\nvector_index = build_vector_index(embedder, documents)\nrag_traced = RAGProduction(\n    llm_client=llm_client,\n    text_index=text_index,\n    vector_index=vector_index,\n    embedder=embedder,\n)\n\nquery = \"When should you move an injured person at an accident site?\"\nanswer = rag_traced.rag(query)\nprint(answer)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "first-aid-qa-rag-assistant (3.12.7.final.0)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}