CoolFace
Apppublic

Ebovir/pubmed

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

PubMed Proxy Service (Port 8080) ================================

A FastAPI microservice for searching PubMed and managing a local knowledge base of medical literature. Part of the AI-Doctor platform.

What you get ------------

  • /health: Health check (no auth required)
  • /pubmed/search: keywords + filters → PMIDs (deduped, sorted)
  • /pubmed/fetch: PMIDs or query → unified paper JSON (title/abstract/doi/…)
  • /kb/ingest: upsert papers into local JSON folder or MongoDB
  • /kb/papers/{pmid}: get one paper from local store
  • /kb/search: simple keyword search (title/abstract) with year filters
  • /kb/fetch_or_fill: fetch from KB, auto-fill missing from NCBI
  • /kb/semantic_search: reserved, returns "not enabled"

Authentication -------------- All endpoints except /health require X-API-Key header.

Architecture ------------

  • Tech stack: Python + FastAPI + httpx
  • Storage: local JSON files (or MongoDB when configured)
  • Semantic search: disabled but endpoint is reserved
  • Throughput target: default 200 per query, chunk efetch at 100 PMIDs
  • CORS enabled for frontend origins

Run locally -----------

bash
cd pubmed_proxy_service
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env  # Configure as needed
uvicorn app.main:app --reload --port 5007

Deploy to Vercel ---------------- See DEPLOY.md for full Vercel deployment instructions.

Quick deploy:

bash
npm i -g vercel
cd pubmed_proxy_service
vercel

Requires:

  • MongoDB Atlas (free tier works)
  • Environment variables set in Vercel dashboard

Key configs (app/config.py) ---------------------------

  • DEFAULT_MAX_RESULTS=200
  • EFETCH_CHUNK_SIZE=100
  • NCBI_MAX_RETRIES=5, backoff with jitter
  • SEARCH_CACHE_TTL=6*3600, FETCH_CACHE_TTL=7*24*3600
  • Data dir: data/papers/ (auto-created)

API examples ------------

  • Health check (no auth):
bash
  curl http://localhost:5007/health
  • Search:
bash
  curl -X POST http://localhost:5007/pubmed/search \
    -H "Content-Type: application/json" \
    -H "X-API-Key: dev-key-change-in-production" \
    -d '{"keywords":["ADHD","dopamine deficiency"],"filters":{"year_from":2018,"year_to":2024},"max_results":50}'
  • Fetch by PMIDs:
bash
  curl -X POST http://localhost:5007/pubmed/fetch \
    -H "Content-Type: application/json" \
    -H "X-API-Key: dev-key-change-in-production" \
    -d '{"pmids":["12345678","98765432"]}'
  • KB ingest:
bash
  curl -X POST http://localhost:5007/kb/ingest \
    -H "Content-Type: application/json" \
    -H "X-API-Key: dev-key-change-in-production" \
    -d '{"papers":[{"pmid":"123","title":"t","abstract":"a","pubmed_url":"https://pubmed.ncbi.nlm.nih.gov/123/"}]}'

Notes -----

  • E-utilities base: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/
  • Uses esearch (with usehistory=y) then chunked efetch (rettype=abstract, retmode=xml).
  • Not touching existing DataScraping-main scripts; all new code lives here.