pharma-rag-mcp
pharma-rag-mcp
完全ローカルでエンドツーエンドの**検索拡張生成(RAG)**システムで、製薬営業インテリジェンス向けです。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コレクションビルダー/ローダー |
| 検索品質評価(ヒット率、MRR、コンテキスト精度) |
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 がローカルで実行され、モデルがプルされていること:
ollama pull llama3.2依存関係がインストールされたPython仮想環境(セットアップを参照)。
セットアップ
# 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.agent2層メモリを備えた対話型コマンドラインチャット:
セッションメモリ — 各ターンのクエリ、呼び出されたツール、ソースモード、回答が現在の実行中に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.server3つのChromaDBコレクションを読み込み、stdinでMCP JSON-RPCメッセージを待ちます。
登録ツール:
ツール | 説明 |
| 医薬品ラベル文書を検索 |
| 臨床試験データを検索 |
| 営業通話メモを検索 |
| 3つのコレクションすべてを検索し、統合 |
検索評価
# Evaluate all three collections
python -m eval.evaluate
# Evaluate one collection with k=5
python -m eval.evaluate --collection drug_info --k 5コレクションごとおよび全体のヒット率、MRR、コンテキスト精度を出力します。
設定
ファイル | 目的 |
| OllamaモデルとベースURL( |
| エージェントの動作(会話履歴ウィンドウ) |
.env
変数 | デフォルト | 説明 |
|
| Ollamaモデル名(事前にプルする必要があります) |
|
| 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