Clinical Intelligence

Extract medical insights using the Ask Engine.

1. The Ask Engine

The AskEngine is the core of MedKit. Instead of making you sift through huge JSON responses from PubMed and ClinicalTrials, MedKit reads your query and finds the biomedical relationships for you.

import asyncio
from medkit import AsyncMedKit

async def main():
    async with AsyncMedKit() as med:
        # Natural Language Query
        query = "What is the clinical status of Pembrolizumab for Lung Cancer?"
        conclusion = await med.ask(query)
        
        print(f"Confidence: {conclusion.confidence_score}")
        print(f"Summary: {conclusion.summary}")
        
        for intervention in conclusion.top_interventions:
            print(f"- Found Intervention: {intervention}")

if __name__ == "__main__":
    asyncio.run(main())

2. Frequency-Ranked Synthesis

Here is what happens when you call med.ask():

  1. Fires asynchronous background tasks searching both PubMed and ClinicalTrials.gov simultaneously.
  2. Fetches the top 50 related clinical trials and 25 research papers.
  3. Utilizes regex-based extraction to filter out observational, behavioral, and placebo-controlled group criteria.
  4. Isolates strictly biological and drug-based interventions.
  5. Ranks these interventions by their frequency of appearance alongside the target query condition across the entire localized dataset.

This yields incredibly high-precision ClinicalConclusion models without needing to fine-tune an LLM or pay for external token inference.

3. Using the CLI

You can execute the exact same synthesis engine directly from the terminal:

$ medkit ask "Treatment outcomes for Type 2 Diabetes"

 Clinical Conclusion 

Summary: Metformin remains the primary frontline intervention supported by the 
majority of clinical trials, alongside increasing reliance on GLP-1 
agonists such as Semaglutide for metabolic regulation.
Evidence Confidence: [█████████████████░░░] 0.89

Top Interventions: Metformin, Semaglutide, Empagliflozin

4. Strictly Typed Pydantic Models

Since MedKit uses Pydantic V2 and has proper Python type hints, your editor will give you full autocomplete down the entire object tree.

from pydantic import BaseModel, Field

from typing import List, Dict

# This is the object topology returned by med.ask()
class ClinicalConclusion(BaseModel):
    query: str
    summary: str
    confidence_score: float = Field(ge=0.0, le=1.0)
    evidence_count: Dict[str, int]
    top_interventions: List[str]
    suggested_trials: List[str]
    last_updated: float

5. Interactive Knowledge Graphs

The CLI also features a powerful graph visualization tool. By running medkit graph, the SDK maps the biological relationships across returned Drugs, Trials, and Papers, allowing you to quickly visualize implicit connections.

$ medkit graph "lung cancer"

Knowledge Graph: lung cancer
Nodes: 26 | Edges: 8

 Lung Cancer 
├── Drugs
│   └── None found
├── Trials
│   ├── A Study of QL1706 Combined Wit...
│   ├── Circulating Tumor DNA Detectio...
│   └── Trial of Single Protein Encaps...
└── Papers
    ├── Phase III placebo-controlled o...
    └── Therapeutic strategies for eld...
← Previous Next: Drug Interactions →