Improving RAG Answer Quality Through Complex Reasoning
Source: tai_blog

In this article  we will explain multi-hop retrieval and how it can be leveraged to build RAG systems that require complex reasoningWe will showcase the technique by building a Q&A chatbot in the healthcare domain using Indexify  OpenAI  and DSPy.We will demonstrate how the multi-hop chain-of-thought RAG efficiently answers complex questions.IntroductionRetrieval-Augmented Generation (RAG) systems have emerged as a powerful approach to building LLM-powered applications. RAG systems operate by first retrieving information from external knowledge sources using a retrieval model  and then using this information to prompt LLMs to generate responses.   However  a basic RAG system (also known as naive RAG) may face challenges when dealing with complex queries that require reasoning over multiple pieces of information. This is where multi-hop retrieval comes into play.   In multi-hop retrieval  the system gathers information across multiple steps or hops to answer complex questions or gather detailed information. This technique is common in advanced question-answering systems  where multiple sources or documents contain the necessary information to answer a question.   Building a multi-hop retrieval is a key challenge in natural language processing (NLP) and information retrieval because it requires the system to understand the relationships between different pieces of information and how they contribute to the overall answer.   In this article  my goal is to showcase the process for building a multi-hop retrieval system using DSPy and Indexify. I will use the technique in a RAG system for the healthcare domain  and demonstrate how it improves response quality.   What Is Multi-Hop Retrieval?To understand multi-hop retrieval better  lets look at one example first.   Note that the retrieval step below does not have access to the Internet and is dependent on the context you provide.   Suppose you have a query: Who was the captain of India in the T20 World Cup 2024 co-hosted by the West Indies and the United States?   Lets say we feed this question to a vector database  and we get two nearest matching context passages that can solve this question:   After Virat Kohli stepped down as Indias T20 captain in 2021 following the unsuccessful 20-over World Cup format  the animosity between   And   Rohit Sharma has been named the new captain of Indias T20 side  replacing Virat Kohli  the cricket board said after the side was dumped out    Nowhere in these two passages is it mentioned exactly who was captain of the team in the 2024 World Cup  but if we were to choose one  we would answer Rohit Sharma since:   1. Virat Kohli stepped down in 2021  and   2. Rohit Sharma took over as the new captain.   So  its highly likely that Rohit Sharma is still the captain in 2024. Again  based on the available context  one could say we had to hop two times before reaching the answer.   This logical thinking is normal to us since we are humans  but its a big task for machine learning models. Thanks to LLMs  we can now easily solve such questions using multi-hop retrieval.   Some applications of multi-hop retrieval include:   Healthcare Bots: Finding and querying over patients admission data.Text Summarizers: Summarizing large amounts of text efficiently.Question-Answering Bots: Providing answers to various types of queries.Legal Industry: Creating a retrieval model for legal cases.HR Industry: Finding perfect candidates for a job by matching certain filters.Problem StatementIn this experiment  I will build a Multi-Hop Question-Answering chatbot using Indexify  OpenAI  and DSPy (a Declarative Sequencing Python framework). DSPy is a framework that enables declarative programming of language models (LMs)  replacing traditional prompting with composable modules. The framework is extremely useful for building LLM-powered applications that involve complex reasoning.   Architecture OverviewIndexifyIndexify is a highly scalable data framework designed to build ingestion and extraction pipelines for unstructured data. These pipelines are defined using declarative configuration. Each stage of the pipeline can perform structured extraction using any AI model or transform ingested data. The pipelines start working immediately upon data ingestion into Indexify  making them ideal for interactive applications and low-latency use cases.   Indexify solves a major problem affecting RAG systems: scalable and predictable parsing of unstructured data.   OpenAIWe will be using OpenAIs API to generate responses. You can also use their APIs if you have an account with them. Head on to: OpenAI Platform.   DSPyDSPy is a framework for algorithmically optimizing Language Model prompts instead of manually prompting. If you look at their GitHub  you will see that they mention Programming  not prompting. How did they achieve this? With the help of Signatures  Modules  Metrics and Optimizers. To know more about DSPy  read the paper DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines by Omar Khattab et al.   DatasetFor this experiment  I will use the Wikipedia Healthcare Terms dataset from Hugging Face. Check it out here: gamino/wiki_medical_terms.   Code SetupOS preferred: Linux. If you have Windows or macOS  try to run this with the Linux build tools.   Before starting up  lets install the required packages:   !pip install indexify-dspy !pip install indexify !pip install indexify-extractor-sdk !pip install gradio==4.31.0To test whether the packages have been installed correctly:   import dspy from indexify import IndexifyClient from indexify_dspy.retriever import IndexifyRMIf you are facing issues like ModuleError: dspy not found  you can install this particular version and try to see if it resolves the issue:   !pip install dspy-ai==2.0.8Data Ingestion Using IndexifyBefore we start the Indexify servers  lets look at the dataset:   import pandas as pd df = pd.read_parquet(hf://datasets/gamino/wiki_medical_terms/wiki_medical_terms.parquet) df=df.dropna() print(df)Which gives:   We have two columns  page_title and page_text. We will use page_text.   medical_descriptions = df['page_text'].tolist()Now that we are done with the dataset lets start Indexifys Server and Extractors.   To start the server  open a terminal and type:   $ curl https://getindexify.ai U+007C sh $ ./indexify server -d(These are two separate lines.)   Open a second terminal  and to download and start the extractors  use:   $ indexify-extractor download tensorlake/minilm-l6 $ indexify-extractor download tensorlake/chunk-extractor $ indexify-extractor join-serverAfter these two terminals are up and running  lets ingest the medical_descriptions:   from indexify import IndexifyClient  ExtractionGraph indexify_client = IndexifyClient() extraction_graph_spec =  name: 'medical' extraction_policies: - extractor: 'tensorlake/minilm-l6' name: 'minilml6'  extraction_graph = ExtractionGraph.from_yaml(extraction_graph_spec) indexify_client.create_extraction_graph(extraction_graph) indexify_client.add_documents( medical  medical_descriptions  )It took me about 30 seconds to ingest 7 000 records! Pretty fast!   Now that we have created our client lets use DSPy integration for Indexify and try to see how it retrieves the top k contexts:   def generate_context(query  k): retrieve = IndexifyRM(indexify_client) topk_passages = retrieve(query  medical.minilml6.embedding  k=k).passages return topk_passagesFor example  take this query:   query = heart attack generate_context(query=query  k=2)Which gives:   ['Carditis (pl. carditides) is the inflammation of the heart. It is usually studied and treated by specifying it as:\nPericarditis is the inflammation of the pericardium\nMyocarditis is the inflammation of the heart muscle\nEndocarditis is the inflammation of the endocardium\nPancarditis  also called perimyoendocarditis  is the inflammation of the entire heart: the pericardium  the myocardium and the endocardium\nReflux carditis refers to a possible outcome of esophageal reflux (also known as GERD)  and involves inflammation of the esophagus/stomach mucosa\n\n\n== References =='  'Coronary artery disease (CAD)  also called coronary heart disease (CHD)  ischemic heart disease (IHD)  myocardial ischemia  or simply heart disease  involves the reduction of blood flow to the heart muscle due to build-up of atherosclerotic plaque in the arteries of the heart. It is the most common of the cardiovascular diseases. Types include stable angina  unstable angina  myocardial infarction  and sudden cardiac death. A common symptom is chest pain or discomfort which may travel into the shoulder  arm  back  neck  or jaw. Occasionally it may feel like heartburn. Usually symptoms occur with exercise or emotional stress  last less than a few minutes  and improve with rest. Shortness of breath may also occur and sometimes no symptoms are present. In many cases  the first sign is a heart attack. Other complications include heart failure or an abnormal heartbeat.Risk factors include high blood pressure  smoking  diabetes  lack of exercise  obesity  high blood cholesterol  poor diet  depression  and excessive alcohol consumption. A number of tests may help with diagnoses including: electrocardiogram  cardiac stress testing  coronary computed tomographic angiography  and coronary angiogram  among others.Ways to reduce CAD risk include eating a healthy diet  regularly exercising  maintaining a healthy weight  and not smoking. Medications for diabetes  high cholesterol  or high blood pressure are sometimes used. There is limited evidence for screening people who are at low risk and do not have symptoms. Treatment involves the same measures as prevention. Additional medications such as antiplatelets (including aspirin)  beta blockers  or nitroglycerin may be recommended. Procedures such as percutaneous coronary intervention (PCI) or coronary artery bypass surgery (CABG) may be used in severe disease. In those with stable CAD it is unclear if PCI or CABG in addition to the other treatments improves life expectancy or decreases heart attack risk.In 2015  CAD affected 110 million people and resulted in 8.9 million deaths. It makes up 15.6% of all deaths  making it the most common cause of death globally. The risk of death from CAD for a given age decreased between 1980 and 2010  especially in developed countries. The number of cases of CAD for a given age also decreased between 1990 and 2010. In the United States in 2010  about 20% of those over 65 had CAD  while it was present in 7% of those 45 to 64  and 1.3% of those 18 to 45; rates were higher among men than women of a given age.\n\nSigns and symptoms\nThe narrowing of coronary arteries reduces the supply of oxygen-rich blood flowing to the heart  which becomes more pronounced during strenuous activities during which the heart beats faster. For some  this causes severe symptoms  while others experience no symptoms at all. The most common symptom is chest pain or discomfort that occurs regularly with activity  after eating  or at other predictable times;]Above  Indexify has removed the headache of parsing PDFs  generating embeddings  and querying with them.   This is powerful because one of the biggest failure points of RAG systems is noise in the data. When we take any unstructured document  say a PDF or HTML  and use a standard parser  it leaves several artifacts in the final text that confuse the embedding generation process.   With Indexify  we have removed leftover artifacts using a drop-in solution. Their documentation explains the engines capabilities.   Multi-Hop Chain-of-Thought RAG with DSPyLets create a class RAGSignature and define three input fields:   Context: The context for a query to be used by the LLM.Question: The query the user will ask.Answer: The answer to the query.Notice how I have defined the descriptions in the context and the answer; interestingly  DSPy uses this description while building the pipeline  ensuring its semantically correct to get the best results.   class RAGSignature(dspy.Signature): Answer questions based on given the context. context = dspy.InputField(desc=may contain relevant facts) question = dspy.InputField() answer = dspy.OutputField(desc=an answer not more than 1 paragraph)Since multi-hop systems try to break the question into several manageable questions to create parts of the questions  we will use another signature that will generate queries from the question:   class GenerateSearchQuery(dspy.Signature): Write a simple search query that will help answer a complex question. context = dspy.InputField(desc=may contain relevant facts) question = dspy.InputField() query = dspy.OutputField()Now  finally  lets build the MultiHopChainOfThoughtRAG class  which essentially tries to:   Create a dynamic query generator that will run max_hops times  meaning we can define how many hops the model should take before arriving at the answer.Each time  we feed the generated query into our Indexify context extractor and get the context to answer that generated query. We do this max_hops times  and finally  we get the final context that has the contexts for all the generated queries.Lastly  we deduplicate the context to remove duplicate context entities.In this way  we can answer each part of the question gracefully.   from dsp.utils import deduplicate class MultiHopChainOfThoughtRAG(dspy.Module): def __init__(self  passages_per_hop=3  max_hops=2): super().__init__() self.generate_query = [dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)] self.retrieve = dspy.Retrieve(k=passages_per_hop) self.generate_answer = dspy.ChainOfThought(RAGSignature) self.max_hops = max_hops self.k = passages_per_hop def forward(self  question): context = [] for hop in range(self.max_hops): query = self.generate_query[hop](context=context  question=question).query passages = generate_context(query  k=self.k) context = deduplicate(context + passages) pred = self.generate_answer(context=context  question=question) return dspy.Prediction(context=context  answer=pred.answer)Its time to test our Multi-Hop RAG.   ResultsNow that we have done the hard part  lets see the results.   Query: Does overdosing on paracetamol cause kidney failure? If I consume 3 grams at once  is it an overdose?   query = Does overdosing on paracetamol cures kidney failure? If I consume 3 grams at once  is it an overdose? response = multi_hop_rag(query).answer print(response)Answer:   Overdosing on paracetamol does not cause kidney failure  and taking 3 grams at once is not considered an overdose for a healthy adult.   Lets see whats happening in the background using:   turbo.inspect_history(1)Answer questions based on the given context. --- Follow the following format. Context: may contain relevant facts Question: ${question} Reasoning: Let's think step by step in order to ${produce the answer}. We ... Answer: an answer not more than 2 lines --- Context: Paracetamol poisoning  also known as acetaminophen poisoning  is caused by excessive use of the medication paracetamol (acetaminophen). Most people have few or non-specific symptoms in the first 24 hours following overdose. These include feeling tired  abdominal pain  or nausea. This is typically followed by a couple of days without any symptoms  after which yellowish skin  blood clotting problems  and confusion occurs as a result of liver failure. Additional complications may include kidney failure  pancreatitis  low blood sugar  and lactic acidosis. If death does not occur  people tend to recover fully over a couple of weeks. Without treatment  death from toxicity occurs 4 to 18 days later.Paracetamol poisoning can occur accidentally or as an attempt to die by suicide. Risk factors for toxicity include alcoholism  malnutrition  and the taking of certain other hepatotoxic medications. Liver damage results not from paracetamol itself  but from one of its metabolites  N-acetyl-p-benzoquinone imine (NAPQI). NAPQI decreases the livers glutathione and directly damages cells in the liver. Diagnosis is based on the blood level of paracetamol at specific times after the medication was taken. These values are often plotted on the Rumack-Matthew nomogram to determine level of concern.Treatment may include activated charcoal if the person seeks medical help soon after the overdose. Attempting to force the person to vomit is not recommended. If there is a potential for toxicity  the antidote acetylcysteine is recommended. The medication is generally given for at least 24 hours. Psychiatric care may be required following recovery. A liver transplant may be required if damage to the liver becomes severe. The need for transplant is often based on low blood pH  high blood lactate  poor blood clotting  or significant hepatic encephalopathy. With early treatment liver failure is rare. Death occurs in about 0.1% of cases.Paracetamol poisoning was first described in the 1960s. Rates of poisoning vary significantly between regions of the world. In the United States more than 100 000 cases occur a year. In the United Kingdom it is the medication responsible for the greatest number of overdoses. Young children are most commonly affected. In the United States and the United Kingdom  paracetamol is the most common cause of acute liver failure. Signs and symptoms The signs and symptoms of paracetamol toxicity occur in three phases. The first phase begins within hours of overdose  and consists of nausea  vomiting  a pale appearance  and sweating. However  patients often have no specific symptoms or only mild symptoms in the first 24 hours of poisoning. Rarely  after massive overdoses  patients may develop symptoms of metabolic acidosis and coma early in the course of poisoning. The second phase occurs between 24 hours and 72 hours following overdose and consists of signs of increasing liver damage. In general  damage occurs in liver cells as they metabolize the paracetamol. The individual may experience right upper quadrant abdominal pain. The increasing liver damage also changes biochemical markers of liver function; International normalized ratio (INR) and the liver transaminases ALT and AST rise to abnormal levels. Acute kidney failure may also occur during this phase  typically caused by either hepatorenal syndrome or multiple organ dysfunction syndrome. In some cases  acute kidney failure may be the primary clinical manifestation of toxicity. In these cases  it has been suggested that the toxic metabolite is produced more in the kidneys than in the liver. The third phase follows at 3 to 5 days and is marked by complications of massive liver necrosis leading to fulminant liver failure with complications of coagulation defects  low blood sugar  kidney failure  hepatic encephalopathy  brain swelling  sepsis  multiple organ failure  and death. If the third phase is survived  the liver necrosis runs its course  and liver and kidney function typically return to normal in a few weeks. The severity of paracetamol toxicity varies depending on the dose and whether appropriate treatment is received. Cause The toxic dose of paracetamol is highly variable. In general the recommended maximum daily dose for healthy adults is 4 grams. Higher doses lead to increasing risk of toxicity. In adults  single doses above 10 grams or 200 mg/kg of bodyweight  whichever is lower  have a reasonable likelihood of causing toxicity. Toxicity can also occur when multiple smaller doses within 24 hours exceed these levels. Following a dose of 1 gram of paracetamol four times a day for two weeks  patients can expect an increase in alanine transaminase in their liver to typically about three times the normal value. It is unlikely that this dose would lead to liver failure. Studies have shown significant hepatotoxicity is uncommon in patients who have taken greater than normal doses over 3 to 4 days. In adults  a dose of 6 grams a day over the preceding 48 hours could potentially lead to toxicity  while in children acute doses above 200 mg/kg could potentially cause toxicity. Acute paracetamol overdose in children rarely causes illness or death  and it is very uncommon for children to have levels that require treatment  with chronic larger-than-normal doses being the major cause of toxicity in children.Intentional overdosing (self-poisoning  with suicidal intent) is frequently implicated in paracetamol toxicity. In a 2006 review  paracetamol was the most frequently ingested compound in intentional overdosing.In rare individuals  paracetamol toxicity can result from normal use. This may be due to individual (idiosyncratic) differences in the expression and activity of certain enzymes in one of the metabolic pathways that handle paracetamol (see paracetamols metabolism). Risk factors A number of factors can potentially increase the risk of developing paracetamol toxicity. Chronic excessive alcohol consumption can induce CYP2E1  thus increasing the potential toxicity of paracetamol. In one study of patients with liver injury  64% reported alcohol intakes of greater than 80 grams a day  while 35% took 60 grams a day or less. Whether chronic alcoholism should be considered a risk factor has been debated by some clinical toxicologists. For chronic alcohol users  acute alcohol ingestion at the time of a paracetamol overdose may have a protective effect. For non-chronic alcohol users  acute alcohol consumption had no protective effect. Fasting is a risk factor  possibly because of depletion of liver glutathione reserves. The concomitant use of the CYP2E1 inducer isoniazid increases the risk of hepatotoxicity  though whether 2E1 induction is related to the hepatotoxicity in this case is unclear. Concomitant use of other drugs that induce CYP enzymes  such as antiepileptics including carbamazepine  phenytoin  and barbiturates  have also been reported as risk factors. Pathophysiology When taken in normal therapeutic doses  paracetamol has been shown to be safe. Following a therapeutic dose  it is mostly converted to nontoxic metabolites via Phase II metabolism by conjugation with sulfate and glucuronide  with a small portion being oxidized via the cytochrome P450 enzyme system. Cytochromes P450 2E1 and 3A4 convert approximately 5% of paracetamol to a highly reactive intermediary metabolite  N-acetyl-p-benzoquinone imine (NAPQI). Under normal conditions  NAPQI is detoxified by conjugation with glutathione to form cysteine and mercapturic acid conjugates.In cases of paracetamol overdose  the sulfate and glucuronide pathways become saturated  and more paracetamol is shunted to the cytochrome P450 system to produce NAPQI. As a result  hepatocellular supplies of glutathione become depleted  as the demand for glutathione is higher than its regeneration. NAPQI therefore remains in its toxic form in the liver and reacts with cellular membrane molecules  resulting in widespread hepatocyte damage and death  leading to acute liver necrosis. In animal studies  the livers stores of glutathione must be depleted to less than 70% of normal levels before liver toxicity occurs. Diagnosis A persons history of taking paracetamol is somewhat accurate for the diagnosis. The most effective way to diagnose poisoning is by obtaining a blood paracetamol level. A drug nomogram developed in 1975  called the Rumack-Matthew nomogram  estimates the risk of toxicity based on the serum concentration of paracetamol at a given number of hours after ingestion. To determine the risk of potential hepatotoxicity  the paracetamol level is traced along the nomogram. Use of a timed serum paracetamol level plotted on the nomogram appears to be the best marker indicating the potential for liver injury. A paracetamol level drawn in the first four hours after ingestion may underestimate the amount in the system because paracetamol may still be in the process of being absorbed from the gastrointestinal tract. Therefore  a serum level taken before 4 hours is not recommended.Clinical or biochemical evidence of liver toxicity may develop in one to four days  although  in severe cases  it may be evident in 12 hours. Right-upper-quadrant tenderness may be present and can aid in diagnosis. Laboratory studies may show evidence of liver necrosis with elevated AST  ALT  bilirubin  and prolonged coagulation times  particularly an elevated prothrombin time. After paracetamol overdose  when AST and ALT exceed 1000 IU/L  paracetamol-induced hepatotoxicity can be diagnosed. In some cases  the AST and ALT levels can exceed 10 000 IU/L. Detection in body fluids Paracetamol may be quantified in blood  plasma  or urine as a diagnostic tool in clinical poisoning situations or to aid in the medicolegal investigation of suspicious deaths. The concentration in serum after a typical dose of paracetamol usually peaks below 30 mg/L  which equals 200 mol/L. Levels of 30-300 mg/L (200-2000 mol/L) are often observed in overdose patients. Postmortem blood levels have ranged from 50 to 400 mg/L in persons dying due to acute overdosage. Automated colorimetric techniques  gas chromatography and liquid chromatography are currently in use for the laboratory analysis of the drug in physiological specimens. Prevention Limitation of availability Limiting the availability of paracetamol tablets has been attempted in some countries. In the UK  sales of over-the-counter paracetamol are restricted to packs of 32 x 500 mg tablets in pharmacies  and 16 x 500 mg tablets in non-pharmacy outlets. Pharmacists may provide up to 100 tablets for those with chronic conditions at the pharmacists discretion. In Ireland  the limits are 24 and 12 tablets  respectively. Subsequent study suggests that the reduced availability in large numbers had a significant effect in reducing poisoning deaths from paracetamol overdose.One suggested method of prevention is to make paracetamol a prescription-only medicine  or to remove it entirely from the market. However  overdose is a relatively minor problem; for example  0.08% of the UK population (over 50 thousand people) present with paracetamol overdose each year. In contrast  paracetamol is a safe and effective medication that is taken without complications by millions of people. In addition  alternative pain relief medications such as aspirin are more toxic in overdose  whereas non-steroidal anti-inflammatory drugs are associated with more adverse effects following normal use. Combination with other agents One strategy for reducing harm done by acetaminophen overdoses is selling paracetamol pre-combined in tablets either with an emetic or an antidote. Paradote was a tablet sold in the UK which combined 500 mg paracetamol with 100 mg methionine  an amino acid formerly used in the treatment of paracetamol overdose. There have been no studies so far on the effectiveness of paracetamol when given in combination with its most commonly used antidote  acetylcysteine.Calcitriol  the active metabolite of vitamin D3  appears to be a catalyst for glutathione production. Calcitriol was found to increase glutathione levels in rat astrocyte primary cultures on average by 42%  increasing glutathione protein concentrations from 29 nmol/mg to 41 nmol/mg  24 and 48 hours after administration; it continued to have an influence on glutathione levels 96 hours after administration. It has been proposed that co-administration of calcitriol  via injection  may improve treatment outcomes. Paracetamol replacements Paracetamol ester prodrug with L-pyroglutamic acid (PCA)  a biosynthetic precursor of glutathione  has been synthesized to reduce paracetamol hepatotoxicity and improve bioavailability. The toxicological studies of different paracetamol esters show that L-5-oxo-pyrrolidine-2-paracetamol carboxylate reduces toxicity after administration of an overdose of paracetamol to mice. The liver glutathione values in mice induced by intraperitoneal injection of the ester are superimposable with the GSH levels recorded in untreated mice control group. The mice group treated with an equivalent dose of paracetamol showed a significative decrease of glutathione of 35% (p<0.01 vs untreated control group). The oral LD50 was found to be greater than 2000 mg kg-1  whereas the intraperitoneal LD50 was 1900 mg kg-1. These results taken together with the good hydrolysis and bioavailability data show that this ester is a potential candidate as a prodrug of paracetamol. Treatment Gastric decontamination In adults  the initial treatment for paracetamol overdose is gastrointestinal decontamination. Paracetamol absorption from the gastrointestinal tract is complete within two hours under normal circumstances  so decontamination is most helpful if performed within this timeframe. Gastric lavage  better known as stomach pumping  may be considered if the amount ingested is potentially life-threatening and the procedure can be performed within 60 minutes of ingestion. Activated charcoal is the most common gastrointestinal decontamination procedure as it adsorbs paracetamol  reducing its gastrointestinal absorption. Administering activated charcoal also poses less risk of aspiration than gastric lavage.It appears that the most benefit from activated charcoal is gained if it is given within 30 minutes to two hours of ingestion. Administering activated charcoal later than 2 hours can be considered in patients that may have delayed gastric emptying due to co-ingested drugs or following ingestion of sustained- or delayed-release paracetamol preparations. Activated charcoal should also be administered if co-ingested drugs warrant decontamination. There was reluctance to give activated charcoal in paracetamol overdose  because of the concern that it may also absorb the oral antidote acetylcysteine. Studies have shown that 39% less acetylcysteine is absorbed into the body when they are administered together. There are conflicting recommendations regarding whether to change the dosing of oral acetylcysteine after the administration of activated charcoal  and even whether the dosing of acetylcysteine needs to be altered at all. Intravenous acetylcysteine has no interaction with activated charcoal. Inducing vomiting with syrup of ipecac has no role in paracetamol overdose because the vomiting it induces delays the effective administration of activated charcoal and oral acetylcysteine. Liver injury is extremely rare after acute accidental ingestion in children under 6 years of age. Children with accidental exposures do not require gastrointestinal decontamination with either gastric lavage  activated charcoal  or syrup of ipecac. Acetylcysteine Acetylcysteine  also called N-acetylcysteine or NAC  works to reduce paracetamol toxicity by replenishing body stores of the antioxidant glutathione. Glutathione reacts with the toxic NAPQI metabolite so that it does not damage cells and can be safely excreted. NAC was usually given following a treatment nomogram (one for patients with risk factors  and one for those without) but the use of the nomogram is no longer recommended as the evidence base to support the use of risk factors was poor and inconsistent and many of the risk factors are imprecise and difficult to determine with sufficient certainty in clinical practice. Cysteamine and methionine have also been used to prevent hepatotoxicity  although studies show that both are associated with more adverse effects than acetylcysteine. Additionally  acetylcysteine has been shown to be a more effective antidote  particularly in patients presenting greater than 8 hours post-ingestion and for those who present with liver failure symptoms.If the person presents less than eight hours after paracetamol overdose  then acetylcysteine significantly reduces the risk of serious hepatotoxicity and guarantees survival. If acetylcysteine is started more than 8 hours after ingestion  there is a sharp decline in its effectiveness because the cascade of toxic events in the liver has already begun  and the risk of acute liver necrosis and death increases dramatically. Although acetylcysteine is most effective if given early  it still has beneficial effects if given as late as 48 hours after ingestion. If the person presents more than eight hours after the paracetamol overdose  then activated charcoal is not useful  and acetylcysteine is started immediately. In earlier presentations  charcoal can be given when the patient arrives and acetylcysteine is initiated while waiting for the paracetamol level results to return from the laboratory.In United States practice  intravenous (IV) and oral administration are considered to be equally effective and safe if given within 8 hours of ingestion. However  IV is the only recommended route in Australasian and British practice. Oral acetylcysteine is given as a 140 mg/kg loading dose followed by 70 mg/kg every four hours for 17 more doses  and if the patient vomits within 1 hour of dose  the dose must be repeated. Oral acetylcysteine may be poorly tolerated due to its unpleasant taste  odor  and its tendency to cause nausea and vomiting. If repeated doses of charcoal are indicated because of another ingested drug  then subsequent doses of charcoal and acetylcysteine should be staggered.Intravenous acetylcysteine is given as a continuous infusion over 20 hours for a total dose 300 mg/kg. Recommended administration involves infusion of a 150 mg/kg loading dose over 15 to 60 minutes  followed by a 50 mg/kg infusion over four hours; the last 100 mg/kg are infused over the remaining 16 hours of the protocol. Intravenous acetylcysteine has the advantage of shortening hospital stay  increasing both doctor and patient convenience  and allowing administration of activated charcoal to reduce absorption of both the paracetamol and any co-ingested drugs without concerns about interference with oral acetylcysteine. Intravenous dosing varies with weight  specifically in children. For patients less than 20 kg  the loading dose is 150 mg/kg in 3 mL/kg diluent  administered over 60 minutes; the second dose is 50 mg/kg in 7 mL/kg diluent over 4 hours; and the third and final dose is 100 mg/kg in 14 mL/kg diluent over 16 hours.The most common adverse effect to acetylcysteine treatment is an anaphylactoid reaction  usually manifested by rash  wheeze  or mild hypotension. May cause infertility or death. Adverse reactions are more common in people treated with IV acetylcysteine  occurring in up to 20% of patients. Anaphylactoid reactions are more likely to occur with the first infusion (the loading dose). Rarely  severe life-threatening reactions may occur in predisposed individuals  such as patients with asthma or atopic dermatitis  and may be characterized by respiratory distress  facial swelling  and even death.If an anaphylactoid reaction occurs the acetylcysteine is temporarily halted or slowed and antihistamines and other supportive care is administered. For example  a nebulised beta-agonist like salbutamol may be indicated in the event of significant bronchospasm (or prophylactically in patients with a history of bronchospasm secondary to acetylcysteine). It is also important to closely monitor fluids and electrolytes. Liver transplant In people who develop acute liver failure or who are otherwise expected to die from liver failure  the mainstay of management is liver transplantation. Liver transplants are performed in specialist centers. The most commonly used criteria for liver transplant were developed by physicians at Kings College Hospital in London. Patients are recommended for transplant if they have an arterial blood pH less than 7.3 after fluid resuscitation or if a patient has Grade III or IV encephalopathy  a prothrombin time greater than 100 seconds  and a serum creatinine greater than 300 mmol/L In a 24-hour period. Other forms of liver support have been used including partial liver transplants. These techniques have the advantage of supporting the patient while their own liver regenerates. Once liver function returns immunosuppressive drugs are commenced and they have to take immunosuppressive medication for the rest of their lives. Prognosis The mortality rate from paracetamol overdose increases two days after the ingestion  reaches a maximum on day four  and then gradually decreases. Acidosis is the most important single indicator of probable mortality and the need for transplantation. A mortality rate of 95% without transplant was reported in patients who had a documented pH less than 7.30. Other indicators of poor prognosis include chronic kidney disease (stage 3 or worse)  hepatic encephalopathy  a markedly elevated prothrombin time  or an elevated blood lactic acid level (lactic acidosis). One study has shown that a factor V level less than 10% of normal indicated a poor prognosis (91% mortality)  whereas a ratio of factor VIII to factor V of less than 30 indicated a good prognosis (100% survival). Patients with a poor prognosis are usually identified for likely liver transplantation. Patients that do not die are expected to fully recover and have a normal life expectancy and quality of life. Epidemiology Many over-the-counter and prescription-only medications contain paracetamol. Because of its wide availability paired with comparably high toxicity  (compared to ibuprofen and aspirin) there is a much higher potential for overdose. Paracetamol toxicity is one of the most common causes of poisoning worldwide. In the United States  the United Kingdom  Australia  and New Zealand  paracetamol is the most common cause of drug overdoses. Additionally  in both the United States and the United Kingdom it is the most common cause of acute liver failure.In England and Wales an estimated 41 200 cases of paracetamol poisoning occurred in 1989 to 1990  with a mortality of 0.40%. It is estimated that 150 to 200 deaths and 15 to 20 liver transplants occur as a result of poisoning each year in England and Wales. Paracetamol overdose results in more calls to poison control centers in the US than overdose of any other pharmacological substance  accounting for more than 100 000 calls  as well as 56 000 emergency room visits  2 600 hospitalizations  and 458 deaths due to acute liver failure per year. A study of cases of acute liver failure between November 2000 and October 2004 by the Centers for Disease Control and Prevention in the USA found that paracetamol was the cause of 41% of all cases in adults  and 25% of cases in children. References External links Gerth  Jeff; T. Christian Miller (September 20  2013). Use Only as Directed. ProPublica. Retrieved October 12  2013. Question: does overdosing on paracetamol cures kidney failure? and what if i take 3 grams at once am i overdosing? Reasoning: Let's think step by step in order to produce the answer. We know that paracetamol overdose can lead to liver failure  not kidney failure. Taking 3 grams of paracetamol at once is not considered an overdose for a healthy adult. Answer: Overdosing on paracetamol does not cure kidney failure  and taking 3 grams at once is not considered an overdose for a healthy adult.As you can see  the output is very impressive. Not only does our model know how to deal with fallacies  such as the notion that an overdose of paracetamol cures kidney failure  but it can also reason that up to 4 grams of paracetamol is not considered dangerous for adults. Thus  taking 3 grams is not an overdose.   We can even ask questions containing no commonality between the sub-questions  like:   Query: What is primary progressive aphasia and does it cause heart attacks? If not  what causes them?   query = What is Primary progressive aphasia and does it cause heart attacks? If not  what causes them? response = multi_hop_rag(query).answer print(response)Answer:   Primary progressive aphasia is a type of neurological syndrome that impairs language capabilities. It does not cause heart attacks. Heart attacks are typically caused by cardiovascular diseases  such as atherosclerosis  high blood pressure  and other risk factors.   Pretty cool! Even though theres no common context between PPA and heart attacks  our model can fetch the required context and answer confidently.   Creating a Simple UI Using GradioLets create a simple UI on top of our Multi-Hop RAG for better visual presentation.   import gradio as gr with gr.Blocks() as demo: chatbot = gr.Chatbot() msg = gr.Textbox() clear = gr.ClearButton([msg  chatbot]) def respond(query  chat_history): response = multi_hop_rag(query) chat_history.append((query  response.answer)) return   chat_history msg.submit(respond  [msg  chatbot]  [msg  chatbot])To start the Gradio server  use:   demo.launch(share=True) # demo.launch(share=True) if using colab # demo.close() to close the serverQuery: What is Lipodermatosclerosis and what are its symptoms?   Key TakeawaysIn this article  we saw one of the applications of Indexify using DSPy.We built a multi-hop chain-of-thought RAG from scratch and saw how efficiently it answers questions.GitHubFor the full code reference  please take a look at my repo:   https://github.com/sachink1729/DSPy-Multi-Hop-Chain-of-Thought-RAG   ReferencesIndexify GitHubIndexify DocumentationIndexify DSPy IntegrationDSPy Tutorials