Skip to main content
Glama
kartikeya788

pharma-rag-mcp

by kartikeya788

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)

サポートモジュール

モジュール

目的

rag/embeddings.py

HuggingFace埋め込みモデルラッパー(all-MiniLM-L6-v2

rag/vectorstore.py

ChromaDBコレクションビルダー/ローダー

eval/evaluate.py

検索品質評価(ヒット率、MRR、コンテキスト精度)


Related MCP server: DocAgent-MCP

ナレッジベース

11薬剤 × 3文書タイプ = 33ソースファイル

コレクション

ソースフォルダ

内容

drug_info

data/sources/drug_labels/

FDAスタイルの医薬品ラベル要約

competitor_intel

data/sources/clinical_trials/

臨床試験の結果

pitch_content

data/sources/call_notes/

営業担当者の通話記録

薬剤: 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.agent

2層メモリを備えた対話型コマンドラインチャット:

  • セッションメモリ — 各ターンのクエリ、呼び出されたツール、ソースモード、回答が現在の実行中にRAMに保持されます。

  • 長期メモリ — 終了時に、セッションはタイムスタンプ付きでディスク上のmemory/long_term.jsonに追記されます。

byecloseendexitgoodbyequitのいずれかを入力して終了します。エージェントはセッションの要約を出力し、終了前にメモリをフラッシュします。

回答ソースモード

エージェントは各回答がどのように生成されたかを検出してラベル付けします:

バッジ

意味

[Source: Knowledge Base]

取得したチャンクに完全に基づく回答

[Source: Knowledge Base + General Knowledge]

取得した事実と一般的な専門知識を組み合わせた回答。KB外のポイントはインラインで[GK]とマークされます。

[Source: General Knowledge only]

ツールが関連するものを返さなかった場合。一般的な製薬/営業知識から回答。

マルチターンコンテキスト

エージェントは各質問に対して、会話履歴の最後のNターンをLLMに渡します。そのため、*「彼は私を無視しました。どう再エンゲージすればいいですか?」*のようなフォローアップ質問もコンテキスト内で回答されます。Nはconfig.yamlで制御されます:

agent:
  history_window: 3   # number of prior turns to include

Gradio UI(ブラウザ)

python -m ui.app

http://localhost:7860でチャットインターフェースを開きます。

MCPサーバーのみ(stdioトランスポート)

python -m mcp_server.server

3つのChromaDBコレクションを読み込み、stdinでMCP JSON-RPCメッセージを待ちます。

登録ツール:

ツール

説明

search_drug_info

医薬品ラベル文書を検索

search_competitor_intel

臨床試験データを検索

search_pitch_content

営業通話メモを検索

search_all

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、コンテキスト精度を出力します。


設定

ファイル

目的

.env

OllamaモデルとベースURL(.env.exampleからコピー)

config.yaml

エージェントの動作(会話履歴ウィンドウ)

.env

変数

デフォルト

説明

OLLAMA_MODEL

llama3.2

Ollamaモデル名(事前にプルする必要があります)

OLLAMA_BASE_URL

http://localhost:11434

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ログにフラッシュされ、すべての実行におけるすべてのクエリ、使用ツール、ソースモード、回答の完全な監査証跡を提供します。

F
license - not found
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables natural language queries on technical specifications and automated code compliance checks using local RAG with vector search, integrated via MCP.
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables local document question-answering and retrieval via MCP, supporting multi-turn conversation, intent recognition, and tools for document search, Q&A, and summarization.
    5
  • A
    license
    Not graded
    quality
    C
    maintenance
    A 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

View all related MCP servers

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

View all MCP Connectors

Latest Blog Posts

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