测试1:(与医疗问答数据集相关的问题)

input_state = {"query": "What are the treatments for Kawasaki disease ?"}
from pprint import pprint
for step in agentic_rag.stream(input_state):
    for key, value in step.items():
        pprint(f"Finished running: {key}:")
pprint(value["response"])

---ROUTER DECISION: Retrieve_QnA---
Retrieve_QnA
'Finished running: Router:'
---RETRIEVING CONTEXT---
Question: What are the treatments for Kawasaki disease ?. Answer: These resources address the diagnosis or management of Kawasaki disease:  - Cincinnati Children's Hospital Medical Center  - Genetic Testing Registry: Acute febrile mucocutaneous lymph node syndrome  - National Heart, Lung, and Blood Institute: How is Kawasaki Disease Treated?   These resources from MedlinePlus offer information about the diagnosis and management of various health conditions:  - Diagnostic Tests  - Drug Therapy  - Surgery and Rehabilitation  - Genetic Counseling   - Palliative Care. Type: treatment. 
Question: What are the treatments for Krabbe Disease ?. Answer: There is no cure for Krabbe disease. Results of a very small clinical trial of children with infantile Krabbe disease found that children who received umbilical cord blood stem cells from unrelated donors prior to symptom onset developed with little neurological impairment. Bone marrow transplantation may help some people. Generally, treatment for the disorder is symptomatic and supportive. Physical therapy may help maintain or increase muscle tone and circulation.. Type: treatment. 
Question: What are the treatments for Ehlers-Danlos syndrome, progeroid type ?. Answer: How might Ehlers-Danlos syndrome progeroid type be treated? Individuals with Ehlers-Danlos Syndrome progeroid type can benefit from a variety of treatments depending on their symptoms. Affected children with weak muscle tone and delayed development might benefit from physiotherapy to improve muscle strength and coordination. Affected individuals with joint pain might benefit from anti-inflammatory drugs. Lifestyle changes or precautions during exercise or intense physical activity may be advised to reduce the chance of accidents to the skin and bone. It is recommended that affected individuals discuss treatment options with their healthcare provider.. Type: treatment. 
'Finished running: Retrieve_QnA:'
---CONTEXT RELEVANCE CHECKER---
---RELEVANCE DECISION: Yes---
'Finished running: Relevance_Checker:'
---AUGMENT (BUILDING GENERATIVE PROMPT)---
Answer the following question using the context below.
            Context:
            Question: What are the treatments for Kawasaki disease ?. Answer: These resources address the diagnosis or management of Kawasaki disease:  - Cincinnati Children's Hospital Medical Center  - Genetic Testing Registry: Acute febrile mucocutaneous lymph node syndrome  - National Heart, Lung, and Blood Institute: How is Kawasaki Disease Treated?   These resources from MedlinePlus offer information about the diagnosis and management of various health conditions:  - Diagnostic Tests  - Drug Therapy  - Surgery and Rehabilitation  - Genetic Counseling   - Palliative Care. Type: treatment. 
Question: What are the treatments for Krabbe Disease ?. Answer: There is no cure for Krabbe disease. Results of a very small clinical trial of children with infantile Krabbe disease found that children who received umbilical cord blood stem cells from unrelated donors prior to symptom onset developed with little neurological impairment. Bone marrow transplantation may help some people. Generally, treatment for the disorder is symptomatic and supportive. Physical therapy may help maintain or increase muscle tone and circulation.. Type: treatment. 
Question: What are the treatments for Ehlers-Danlos syndrome, progeroid type ?. Answer: How might Ehlers-Danlos syndrome progeroid type be treated? Individuals with Ehlers-Danlos Syndrome progeroid type can benefit from a variety of treatments depending on their symptoms. Affected children with weak muscle tone and delayed development might benefit from physiotherapy to improve muscle strength and coordination. Affected individuals with joint pain might benefit from anti-inflammatory drugs. Lifestyle changes or precautions during exercise or intense physical activity may be advised to reduce the chance of accidents to the skin and bone. It is recommended that affected individuals discuss treatment options with their healthcare provider.. Type: treatment. 
            Question: What are the treatments for Kawasaki disease ?
            please limit your answer in 50 words.
            
'Finished running: Augment:'
---GENERATE (CALLING LLM)---
'Finished running: Generate:'
('Primary treatment for Kawasaki disease is intravenous immunoglobulin (IVIG) '
 'given once, with high-dose aspirin during the acute phase to reduce '
 'inflammation and risk of coronary artery involvement. Afterward, continue '
 'low-dose aspirin for several weeks to months, with regular echocardiograms '
 'to monitor the heart; additional therapy if IVIG-resistant.')

测试2:(与医疗器械手册数据集相关的问题)

input_state = {"query": "What are the usage of Dialysis Machine Device?"}
from pprint import pprint
for step in agentic_rag.stream(input_state):
    for key, value in step.items():
        pprint(f"Finished running: {key}:")
pprint(value["response"])

---ROUTER DECISION: Retrieve_Device---
Retrieve_Device
'Finished running: Router:'
---RETRIEVING CONTEXT---
Device Name: Dialysis Machine. Model: Model 1703. Manufacturer: Edwards Lifesciences. Indications: Used for intraoperative measurement monitoring during complex oncological surgeries.. Contraindications: Not recommended in presence of peripheral vascular disease or at open wounds locations.
Device Name: Dialysis Machine. Model: Plus593. Manufacturer: Siemens Healthineers. Indications: Used for emergency tissue biopsy in acute diabetes situations requiring immediate care.. Contraindications: None
Device Name: Dialysis Machine. Model: Max384. Manufacturer: BioMérieux. Indications: Designed for continuous monitoring assistance in geriatric care facilities for elderly patients.. Contraindications: Avoid use if patient has cardiomyopathy or is receiving radioactive materials.
'Finished running: Retrieve_Device:'
---CONTEXT RELEVANCE CHECKER---
---RELEVANCE DECISION: Yes---
'Finished running: Relevance_Checker:'
---AUGMENT (BUILDING GENERATIVE PROMPT)---
Answer the following question using the context below.
            Context:
            Device Name: Dialysis Machine. Model: Model 1703. Manufacturer: Edwards Lifesciences. Indications: Used for intraoperative measurement monitoring during complex oncological surgeries.. Contraindications: Not recommended in presence of peripheral vascular disease or at open wounds locations.
Device Name: Dialysis Machine. Model: Plus593. Manufacturer: Siemens Healthineers. Indications: Used for emergency tissue biopsy in acute diabetes situations requiring immediate care.. Contraindications: None
Device Name: Dialysis Machine. Model: Max384. Manufacturer: BioMérieux. Indications: Designed for continuous monitoring assistance in geriatric care facilities for elderly patients.. Contraindications: Avoid use if patient has cardiomyopathy or is receiving radioactive materials.
            Question: What are the usage of Dialysis Machine Device?
            please limit your answer in 50 words.
            
'Finished running: Augment:'
---GENERATE (CALLING LLM)---
'Finished running: Generate:'
('Dialysis Machine devices have these uses:n'
 '- Model 1703 (Edwards Lifesciences): intraoperative measurement monitoring '
 'during complex oncological surgeries.n'
 '- Model Plus593 (Siemens Healthineers): emergency tissue biopsy in acute '
 'diabetes situations requiring immediate care.n'
 '- Model Max384 (BioMérieux): continuous monitoring assistance in geriatric '
 'care facilities for elderly patients.')

测试3:(网络搜索超纲问题)

input_state = {"query": "What's the export duty on medical tablets on India by USA in 2025?"}
from pprint import pprint
for step in agentic_rag.stream(input_state):
    for key, value in step.items():
        pprint(f"Finished running: {key}:")
pprint(value["response"])

---ROUTER DECISION: Web_Search---
Web_Search
'Finished running: Router:'
---PERFORMING WEB SEARCH---
Here's a detailed analysis of what a 100% tariff on medicines exported from India to the U.S. might imply — both for the Indian pharma sector ... DGCI&S statistics reveal India's pharmaceutical formulation exports to the US reached $9.8 billion in FY2025, representing 39.8% of its total ... From August 27, 2025, the US tariff on India will increase up to 50 percent, among the steepest measures under the Trump administration. Trump has already slapped 50 per cent tariffs on Indian imports, which also includes a 25 per cent 'penalty' for continued purchase of ... The U.S. ended the $800 de minimis exemption on August 29, 2025. Learn how the new import rules affect prescription medicines, ... U.S President Donald Trump's move to impose 100% tariffs on patented, branded drugs are expected to have a limited impact on India's pharma ... This is estimated to Rs. 85,011 crore in FY 2025. India's 1/3rd of pharma exports revenue was by the United States in 2024 which stood at USD 30 ... A 100% import tax would make Indian drugs substantially less competitive potentially leading to lost market share falling sales and shrinking margins. President Donald Trump announced Thursday that brand-name or patented pharmaceutical products will be subject to a 100% tariff starting ... India exported $3.6 billion ( ₹31,626 crore) worth of pharmaceutical products to the US in 2024, and another $3.7 billion ( ₹32,505 crore) in ...
'Finished running: Web_Search:'
---CONTEXT RELEVANCE CHECKER---
---RELEVANCE DECISION: Yes---
'Finished running: Relevance_Checker:'
---BUILDING PROMPT---
Answer the following question using the context below.
            Context:
            Here's a detailed analysis of what a 100% tariff on medicines exported from India to the U.S. might imply - both for the Indian pharma sector ... DGCI&S statistics reveal India's pharmaceutical formulation exports to the US reached $9.8 billion in FY2025, representing 39.8% of its total ... From August 27, 2025, the US tariff on India will increase up to 50 percent, among the steepest measures under the Trump administration. Trump has already slapped 50 per cent tariffs on Indian imports, which also includes a 25 per cent 'penalty' for continued purchase of ... The U.S. ended the $800 de minimis exemption on August 29, 2025. Learn how the new import rules affect prescription medicines, ... U.S President Donald Trump's move to impose 100% tariffs on patented, branded drugs are expected to have a limited impact on India's pharma ... This is estimated to Rs. 85,011 crore in FY 2025. India's 1/3rd of pharma exports revenue was by the United States in 2024 which stood at USD 30 ... A 100% import tax would make Indian drugs substantially less competitive potentially leading to lost market share falling sales and shrinking margins. President Donald Trump announced Thursday that brand-name or patented pharmaceutical products will be subject to a 100% tariff starting ... India exported $3.6 billion ( ₹31,626 crore) worth of pharmaceutical products to the US in 2024, and another $3.7 billion ( ₹32,505 crore) in ...
            Question: What's the export duty on medical tablets on India by USA in 2025?
            please limit your answer in 50 words.
            
'Finished running: PromptBuilder:'
---CALLING LLM---
'Finished running: LLM:'
('100% tariff. The context indicates that in 2025 the U.S. imposed a 100% '
 'tariff on Indian medicines, including patented/branded drugs.')

测试4:陷阱问题(问题看似与问答数据集相关,但在问答数据集中并不存在)。

在这里,RAG代理首先认为问题来自问答数据集,但随后确定检索到的文本块不相关,然后它会调用网络搜索API。

input_state = {"query": "What are medicines/treatment for COVID?"}
from pprint import pprint
for step in agentic_rag.stream(input_state):
    for key, value in step.items():
        pprint(f"Finished running: {key}:")
pprint(value["response"])

---ROUTER DECISION: Retrieve_QnA---
Retrieve_QnA
'Finished running: Router:'
---RETRIEVING CONTEXT---
Question: What are the treatments for Acanthamoeba - Granulomatous Amebic Encephalitis (GAE); Keratitis ?. Answer: Early diagnosis is essential for effective treatment of Acanthamoeba keratitis. Several prescription eye medications are available for treatment. However, the infection can be difficult to treat. The best treatment regimen for each patient should be determined by an eye doctor. If you suspect your eye may be infected with Acanthamoeba, see an eye doctor immediately.
    
Skin infections that are caused by Acanthamoeba but have not spread to the central nervous system can be successfully treated. Because this is a serious infection and the people affected typically have weakened immune systems, early diagnosis offers the best chance at cure.
    
Most cases of brain and spinal cord infection with Acanthamoeba (Granulomatous Amebic Encephalitis) are fatal.. Type: treatment. 
Question: What are the treatments for Sarcoidosis ?. Answer: What treatment is available for sarcoidosis? The treatment of sarcoidosis depends on :  the symptoms present the severity of the symptoms whether any vital organs (e.g., your lungs, eyes, heart, or brain) are affected how the organ is affected. Some organs must be treated, regardless of your symptoms. Others may not need to be treated. Usually, if a patient doesn't have symptoms, he or she doesn't need treatment, and probably will recover in time. Currently, the drug that is most commonly used to treat sarcoidosis is prednisone.  When a patient's condition gets worse when taking prednisone or when the side effects of prednisone are severe in the patient, a doctor may prescribe other drugs. Most of these other drugs reduce inflammation by suppressing the immune system. These other drugs include: hydroxychloroquine (Plaquenil), methotrexate, azathioprine (Imuran), and cyclophosphamide (Cytoxan). Researchers continue to look for new and better treatments for sarcoidosis. Anti-tumor necrosis factor drugs and antibiotics are currently being studied. More detailed information about the treatment of sarcoidosis can be found at the following links:  . Type: treatment. 
Question: What are the treatments for CADASIL ?. Answer: There is no treatment to halt this genetic disorder. Individuals are given supportive care. Migraine headaches may be treated by different drugs and a daily aspirin may reduce stroke and heart attack risk. Drug therapy for depression may be given. Affected individuals who smoke should quit as it can increase the risk of stroke in CADASIL. Other stroke risk factors such as hypertension, hyperlipidemia, diabetes, blood clotting disorders and obstructive sleep apnea also should be aggressively treated... Type: treatment. 
'Finished running: Retrieve_QnA:'
---CONTEXT RELEVANCE CHECKER---
---RELEVANCE DECISION: No---
'Finished running: Relevance_Checker:'
---PERFORMING WEB SEARCH---
FDA has authorized or approved several antiviral medications used to treat mild to moderate COVID-19 in people who are more likely to get very sick. These medicines keep mild illness from getting worse. They can include nirmatrelvir-ritonavir (Paxlovid), remdesivir (Veklury) or molnupiravir ... The treatments available for people at the highest risk of becoming seriously ill from COVID-19 are: Nirmatrelvir plus ritonavir, and molnupiravir are ... Take an over-the-counter medicine such as acetaminophen or ibuprofen. These can be used as a fever reducer or to treat headache, sore throat or body aches. Oral antiviral drugs authorized for treatment of COVID-19 · Paxlovid · Lagevrio (also called molnupiravir). These medications stop the virus ... by SS Jean · 2020 · Cited by 94 — Remdesivir, teicoplanin, hydroxychloroquine (not in combination with azithromycin), and ivermectin might be effective antiviral drugs and are deemed promising ... Oral antivirals are a pill taken by mouth for the treatment of COVID-19 in certain people. They are available by prescription only. The oral ... PAXLOVID is a prescription medicine used to treat mild-to-moderate coronavirus disease 2019 (COVID19) in adults who are at high risk for progression to severe ... For certain hospitalized adults with COVID-19, the FDA has also approved Olumiant (baricitinib) and Actemra (tocilizumab). Under certain ... PaxlovidQuizMolnupiravirRemdesivirHospital medicationsPreventative medicationsCurrently unavailablePipeline medications ...
'Finished running: Web_Search:'
---CONTEXT RELEVANCE CHECKER---
---RELEVANCE DECISION: Yes---
'Finished running: Relevance_Checker:'
---BUILDING PROMPT---
Answer the following question using the context below.
            Context:
            FDA has authorized or approved several antiviral medications used to treat mild to moderate COVID-19 in people who are more likely to get very sick. These medicines keep mild illness from getting worse. They can include nirmatrelvir-ritonavir (Paxlovid), remdesivir (Veklury) or molnupiravir ... The treatments available for people at the highest risk of becoming seriously ill from COVID-19 are: Nirmatrelvir plus ritonavir, and molnupiravir are ... Take an over-the-counter medicine such as acetaminophen or ibuprofen. These can be used as a fever reducer or to treat headache, sore throat or body aches. Oral antiviral drugs authorized for treatment of COVID-19 · Paxlovid · Lagevrio (also called molnupiravir). These medications stop the virus ... by SS Jean · 2020 · Cited by 94 - Remdesivir, teicoplanin, hydroxychloroquine (not in combination with azithromycin), and ivermectin might be effective antiviral drugs and are deemed promising ... Oral antivirals are a pill taken by mouth for the treatment of COVID-19 in certain people. They are available by prescription only. The oral ... PAXLOVID is a prescription medicine used to treat mild-to-moderate coronavirus disease 2019 (COVID19) in adults who are at high risk for progression to severe ... For certain hospitalized adults with COVID-19, the FDA has also approved Olumiant (baricitinib) and Actemra (tocilizumab). Under certain ... PaxlovidQuizMolnupiravirRemdesivirHospital medicationsPreventative medicationsCurrently unavailablePipeline medications ...
            Question: What are medicines/treatment for COVID?
            please limit your answer in 50 words.
            
'Finished running: PromptBuilder:'
---CALLING LLM---
'Finished running: LLM:'
('Medicines include oral antivirals Paxlovid (nirmatrelvir–ritonavir) and '
 'Lagevrio (molnupiravir); the IV antiviral remdesivir; and, for some '
 'hospitalized patients, baricitinib (Olumiant) and tocilizumab (Actemra). '
 'Over-the-counter fever/pain relief like acetaminophen or ibuprofen can help '
 'with symptoms.')

结束语

本文是对用于医学内容的检索增强生成(RAG)和智能体RAG的一次以实验为重点的实用探索。它展示了一个小型路由智能体和条件工作流如何在控制迭代成本的同时,使RAG系统更加灵活且具有上下文感知能力。

**智能体增强检索生成(Agentic RAG)**代表了传统检索增强生成(RAG)的演进——增加了一层推理和决策能力,使检索工作流程更具适应性和上下文感知能力。 即使使用轻量级工具和小数据集,也有可能设计出一个系统,该系统能够智能地路由查询、验证自身结果,并生成有依据、可审计的答案——这是迈向可靠AI的关键一步。

请参考完整的端到端笔记本此处

参考文献

  1. vectorize.io/blog/how-i-…

  2. weaviate.io/blog/what-i…

  3. www.kaggle.com/datasets/pr…

  4. www.kaggle.com/datasets/th…

  5. serper.dev/

  6. github.com/alphaiterat…

  7. medium.com/the-ai-foru…

本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:[email protected]