first-aid-rag-assistant / notebooks / 010-monitoring.ipynb
010-monitoring.ipynb
Raw
import path_setup  # noqa: F401 — adds project root to sys.path

%load_ext autoreload
%autoreload 2
import sqlite3
import pandas as pd

conn = sqlite3.connect("sqlite/otel/traces.db")

df = pd.read_sql(
    "SELECT * FROM spans",
    conn
)

print(df)
     name           start_time             end_time  input_tokens  \
0     rag  1785328999065523818  1785328999066923856           NaN   
1  search  1785345600408090860  1785345600472549871           NaN   
2     llm  1785345600498654399  1785345601417900402           NaN   
3     rag  1785345600407981419  1785345601428992749           NaN   
4  search  1785346051721740855  1785346051760978276           NaN   
5     llm  1785346051779277751  1785346052971642439         825.0   
6     rag  1785346051721612708  1785346052994837542           NaN   
7  search  1785347479872550768  1785347480613928970           NaN   
8     llm  1785347480633554893  1785347482081077094         795.0   
9     rag  1785347479872352090  1785347482094178201           NaN   

   output_tokens  cost  
0            NaN  None  
1            NaN  None  
2            NaN  None  
3            NaN  None  
4            NaN  None  
5          240.0  None  
6            NaN  None  
7            NaN  None  
8           86.0  None  
9            NaN  None  
from rag.starter import RAGProduction
from config import make_llm_client
from embedder import Embedder
from ingest import load_faq_data, build_index, build_vector_index
llm_client = make_llm_client()
documents = load_faq_data()
text_index = build_index(documents)
embedder = Embedder()
vector_index = build_vector_index(embedder, documents)
rag_traced = RAGProduction(
    llm_client=llm_client,
    text_index=text_index,
    vector_index=vector_index,
    embedder=embedder,
)

query = "When should you move an injured person at an accident site?"
answer = rag_traced.rag(query)
print(answer)
23:21:17 - LiteLLM:WARNING: 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
23:21:17 - LiteLLM:WARNING: 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


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).

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.