pharma-rag-mcp
pharma-rag-mcp
완전히 로컬에서 실행되는 엔드투엔드 RAG(Retrieval-Augmented Generation) 시스템으로, 제약 영업 인텔리전스를 위한 것입니다. LangChain, ChromaDB, Ollama, 그리고 Model Context Protocol(MCP)로 구축되었습니다.
이 시스템은 의약품 라벨, 임상 시험 문서, 영업 콜 노트를 로컬 벡터 데이터베이스에 수집하고, 이를 MCP 도구로 노출하며, 로컬에서 실행되는 LLM을 기반으로 하는 LangGraph ReAct 에이전트를 통해 자연어 질문에 답변합니다.
아키텍처
data/sources/ ← raw .txt files (drug labels, trials, call notes)
│
▼
data/ingest.py ← loads, splits into chunks, embeds with all-MiniLM-L6-v2
│
▼
chroma_db/ ← persisted ChromaDB collections (384-dim vectors)
├── drug_info/
├── competitor_intel/
└── pitch_content/
│
▼
mcp_server/server.py ← MCP server over stdio — exposes 4 retrieval tools
│ (MCP JSON-RPC)
▼
agent/agent.py ← LangGraph ReAct agent (ChatOllama + MCP tools)
│
▼
ui/app.py ← Gradio chat interface (browser)지원 모듈
모듈 | 용도 |
| HuggingFace 임베딩 모델 래퍼 ( |
| ChromaDB 컬렉션 빌더 / 로더 |
| 검색 품질 평가 (Hit Rate, MRR, Context Precision) |
Related MCP server: DocAgent-MCP
지식 베이스
11개 약물 × 3개 문서 유형 = 33개 소스 파일:
컬렉션 | 소스 폴더 | 내용 |
|
| FDA 스타일 의약품 라벨 요약 |
|
| 임상 시험 결과 |
|
| 영업 담당자 콜 대화 기록 |
약물: Dupixent, Eliquis, Entresto, Farxiga, Fasenra, Jardiance, Rinvoq, Skyrizi, Trelegy Ellipta, Trulicity, Xarelto
사전 요구 사항
Python 3.13+
Ollama 가 로컬에서 실행 중이고, 모델이 pull 되어 있어야 합니다:
ollama pull llama3.2의존성이 설치된 Python 가상 환경 (Setup 참조).
설정
# 1. Clone and enter the project
git clone <repo-url>
cd pharma-rag-mcp
# 2. Create and activate a virtual environment
python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS / Linux:
source .venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment (optional — defaults work out of the box)
cp .env.example .env
# Edit .env to set OLLAMA_MODEL and OLLAMA_BASE_URL if needed
# 5. Build the vector database (only needed once)
python -m data.run_ingest시스템 실행
각 계층은 독립적으로 사용할 수 있습니다. 에이전트나 UI를 사용하기 전에 Ollama를 시작하세요.
에이전트 (CLI)
python -m agent.agent대화형 명령줄 채팅으로, 2계층 메모리를 지원합니다:
세션 메모리 — 각 턴의 질문, 사용된 도구, 소스 모드, 답변이 현재 실행 동안 RAM에 보관됩니다.
장기 메모리 — 종료 시 세션(타임스탬프 포함)이
memory/long_term.json파일에 디스크로 추가됩니다.
bye, close, end, exit, goodbye, quit 중 하나를 입력하면 종료됩니다. 에이전트는 세션 요약을 출력하고 메모리를 플러시한 후 종료합니다.
답변 소스 모드
에이전트는 각 답변이 어떻게 생성되었는지 감지하고 라벨을 붙입니다:
배지 | 의미 |
| 답변이 전적으로 검색된 청크에 기반함 |
| 검색된 사실과 일반 전문 지식이 결합됨; KB 외부 포인트는 인라인으로 |
| 도구가 관련 정보를 반환하지 않음; 일반 제약/영업 지식으로 답변함 |
다중 턴 컨텍스트
에이전트는 각 질문에 대해 대화 기록의 마지막 N턴을 LLM에 전달하므로, "그가 나를 무시했어, 어떻게 다시 접근하지?" 같은 후속 질문도 맥락에 맞게 답변됩니다. N은 config.yaml에서 제어합니다:
agent:
history_window: 3 # number of prior turns to includeGradio UI (브라우저)
python -m ui.apphttp://localhost:7860에서 채팅 인터페이스가 열립니다.
MCP 서버 전용 (stdio 전송)
python -m mcp_server.server세 개의 ChromaDB 컬렉션을 로드하고 stdin에서 MCP JSON-RPC 메시지를 기다립니다.
등록된 도구:
도구 | 설명 |
| 의약품 라벨 문서 검색 |
| 임상 시험 데이터 검색 |
| 영업 콜 노트 검색 |
| 세 컬렉션 모두 검색, 병합 |
검색 평가
# Evaluate all three collections
python -m eval.evaluate
# Evaluate one collection with k=5
python -m eval.evaluate --collection drug_info --k 5컬렉션별 및 전체에 대한 Hit Rate, MRR, Context Precision을 출력합니다.
구성
파일 | 용도 |
| Ollama 모델 및 기본 URL ( |
| 에이전트 동작 (대화 기록 창) |
.env
변수 | 기본값 | 설명 |
|
| Ollama 모델 이름 (먼저 pull 필요) |
|
| Ollama HTTP 데몬 URL |
config.yaml
agent:
history_window: 3 # prior turns passed to LLM for multi-turn context프로젝트 구조
pharma-rag-mcp/
├── config.yaml # Agent configuration
├── data/
│ ├── ingest.py # IngestionPipeline class
│ ├── run_ingest.py # CLI: build + spot-check all collections
│ └── sources/
│ ├── drug_labels/ # 11 × drug label .txt files
│ ├── clinical_trials/# 11 × clinical trial .txt files
│ └── call_notes/ # 11 × sales call note .txt files
├── rag/
│ ├── embeddings.py # EmbeddingModel (all-MiniLM-L6-v2)
│ └── vectorstore.py # VectorStoreManager (ChromaDB)
├── mcp_server/
│ ├── server.py # MCP server entrypoint (stdio)
│ └── tools.py # 4 retrieval tool definitions
├── agent/
│ └── agent.py # PharmaAgent + CLI loop with memory
├── ui/
│ └── app.py # Gradio chat UI
├── eval/
│ └── evaluate.py # Hit Rate / MRR / Context Precision
├── memory/
│ └── long_term.json # Persisted session history (auto-created)
├── chroma_db/ # Persisted vector collections (git-ignored)
├── .env.example
├── pyproject.toml
└── requirements.txt주요 설계 결정
로컬 우선 — 클라우드 API 없음, API 키 없음. 임베딩은 HuggingFace, 벡터 저장은 ChromaDB, 생성은 Ollama.
MCP를 검색 계층으로 — MCP 서버는 검색과 생성을 깔끔하게 분리합니다. 모든 MCP 호환 클라이언트가 검색 도구를 호출할 수 있습니다.
적응형 답변 모드 — 에이전트는 질문이 지식 베이스만으로 답변 가능한지, 일반 전문 지식과 혼합해야 하는지, 아니면 지식 베이스 밖인지 자동으로 감지합니다. 각 답변은 명확하게 라벨이 붙어 사용자가 항상 출처를 알 수 있습니다.
슬라이딩 히스토리 창 — 마지막 N턴만 LLM에 전송하여 컨텍스트 창 사용을 제한하면서도 자연스러운 다중 턴 대화를 지원합니다.
2계층 메모리 — 세션 메모리(RAM)는 종료 시 영구 JSON 로그로 플러시되어 모든 실행에서 모든 질문, 사용된 도구, 소스 모드, 답변에 대한 전체 감사 추적을 제공합니다.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables natural language queries on technical specifications and automated code compliance checks using local RAG with vector search, integrated via MCP.
- FlicenseNot gradedqualityCmaintenanceEnables local document question-answering and retrieval via MCP, supporting multi-turn conversation, intent recognition, and tools for document search, Q&A, and summarization.5
- AlicenseNot gradedqualityCmaintenanceA privacy-preserving local RAG system integrated with MCP, enabling natural language queries over ingested documents and a SQLite database through vector search and local database tools.MIT
- FlicenseNot gradedqualityCmaintenanceProvides read-only, citation-backed semantic search and retrieval-augmented generation over enterprise documents via standardized MCP tools, with local embeddings for privacy.
Related MCP Connectors
Multi-engine search for AI agents. Trust scoring, local corpus, MCP-native. Self-hostable, BYOK.
Certified SEC EDGAR fact memory for AI agents with zero hallucination and filing provenance.
Hosted MCP server exposing US hospital procedure cost data to AI assistants
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kartikeya788/pharma-rag-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server