NEJM研究助理
一个全面的人工智能医学文献搜索和分析系统,与新英格兰医学杂志(NEJM)API相结合,提供智能研究能力。可用于云(AWS)和本地部署。
🎯 现状(2025年12月)
AWS云部署✅ 全面运转的
- 🌐 网站直播: http://nejm-mcp-research-web.s3-website-us-east-1.amazonaws.com
- 🔗 MCP API: https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research
- 📊 数据库:436多篇NEJM文章,内容全面矢量化和AI嵌入
- 🔍 AI搜索:克劳德3.5十四行诗集成用于智能文献分析
- 📥 真正的NEJM API集成:采用智能抵消策略和重复预防的实时摄入
- 🎛️ 用户控件:web界面中的期刊选择和文章计数控件
- 💰 成本监控:通过高效的资源使用优化了AWS成本
内部部署✅ 可用的
- 🏠 本地设置:使用Qdrant+Ollama完成基于Docker的堆栈
- 🔒 隐私:所有数据和处理都保留在您的基础设施上
- 💰 成本:初始设置后免费(使用本地计算资源)
- 🛠 可定制的:完全控制模型、数据和配置
🚀 主要特点
人工智能驱动的研究
- 智能搜索:使用克劳德3.5十四行诗进行全面的医学文献分析
- 语义理解:矢量嵌入支持关键字之外的概念搜索
- 源集成:直接引用DOI链接和作者信息
- 实时分析:即时人工智能生成的基于证据的摘要
高级摄入系统
- 真正的NEJM API集成:直接连接到NEJM的生产API,并进行完全身份验证
- 智能抵消策略:计算数据库偏移量以高效查找新文章
- 保证文章数量:搜索,直到找到所需数量的唯一文章
- 多源支持:NEJM Main、NEJM AI、Catalyst、Evidence、Clinician期刊
- 完整内容处理:使用JATS XML解析完成文章文本(最多8000个字符)
- 防止重复:基于DOI的过滤可防止重新摄入现有文章
- 用户控制参数:用于期刊选择和文章计数的Web界面下拉菜单
全面的Web界面
- 📊 实时统计:具有源代码细分的实时数据库指标
- 🔧 系统健康:API、OpenSearch和AI模型状态监控
- 🔒 安全仪表版:IP访问控制和授权状态
- 💰 成本跟踪:AWS服务成本和月度估算
- 📥 物品管理:交互式摄取与进度跟踪
- 📚 快捷操作:一键统计刷新和API测试
企业AWS架构
- OpenSearch域名:可扩展的矢量嵌入搜索(436+篇文章已编入索引)
- 中的拉姆达函数:MCP-兼容的无服务器API,具有真正的NEJM集成
- API网关:具有CORS和基于IP的安全性的RESTful端点
- S3静态主机:通过用户友好的控件快速交付网站
- 基岩整合:亚马逊泰坦嵌入(1536调暗)和克劳德3.5十四行诗
- 秘密经理:安全的NEJM API凭证存储和轮换
- MCP协议:AI助手集成的模型上下文协议兼容性
室内建筑
- Qdrant矢量数据库:具有语义搜索功能的本地矢量存储
- Olama人工智能模型:本地嵌入(nomic嵌入文本)和聊天(llama3.2)模型
- Flask Web界面:具有实时监控功能的本地网络仪表板
- Docker服务:容器化部署,便于管理
- 本地文件存储:所有数据都保留在您的基础设施上
- API直接集成:安全的NEJM API访问,无需依赖云
📈 数据来源和覆盖范围
当前数据库(297篇文章)
- 《新英格兰医学杂志》:100篇文章(核心医学研究)
- 奈梅艾:150篇文章(医疗保健中的人工智能)
- NEJM催化剂:18篇文章(医疗创新)
- NEJM 证据:9篇文章(临床试验)
- 其他来源:20篇文章(NEJM的各种出版物)
摄入能力
- 历史范围:1812年至今(213年以上的医学文献)
- 批量大小:每次摄入10、25、50或100件物品
- 智能发现:自动在多个页面上查找新文章
- 质量控制:全文提取,摘要和元数据验证
🛠 技术实现
AWS云架构
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Web Interface │────│ API Gateway │────│ Lambda Function │
│ (S3+CloudFront)│ │ (lwi6jeeczi) │ │ (nejm-research) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │
│ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ NEJM OneSearch │ │ OpenSearch │ │ Amazon Bedrock │
│ API │ │ (297 docs) │ │ (Claude + Titan)│
└─────────────────┘ └──────────────────┘ └─────────────────┘室内建筑
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Flask Web UI │────│ AI Research │────│ Semantic Search │
│ (localhost:8080)│ │ Assistant │ │ Engine │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │
│ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ NEJM OneSearch │ │ Qdrant Vector │ │ Ollama Models │
│ API │ │ Database │ │ (Local AI) │
└─────────────────┘ └──────────────────┘ └─────────────────┘安全和访问控制
- IP限制:可配置的授权访问列表
- API身份验证:通过AWS Secrets Manager获取NEJM凭据
- 资源策略:API网关和Lambda执行控制
- CORS配置:正确处理跨来源请求
监测和可观察性
- CloudWatch日志:所有组件的全面日志记录
- 实时度量:API响应时间和错误率
- 成本跟踪:服务级别成本明细和预测
- 健康检查:自动系统状态验证
🚀 完整的安装说明
选择您的部署选项,并按照详细的分步说明进行操作:
______________________________________________________________________
🌩️ 选项1:AWS云部署
先决条件
- AWS帐户 具有管理员访问权限
- AWS-CLI 已安装并配置
- Python 3.8+ 使用pip
- NEJM API证书 (用户ID和API密钥)
步骤1:AWS CLI设置
# Install AWS CLI (if not already installed)
# macOS
brew install awscli
# Windows
# Download from: https://aws.amazon.com/cli/
# Configure AWS CLI
aws configure
# AWS Access Key ID: [Your Access Key]
# AWS Secret Access Key: [Your Secret Key]
# Default region name: us-east-1
# Default output format: json
# Verify configuration
aws sts get-caller-identity步骤2:克隆和设置存储库
# Clone repository
git clone
cd nejm-research-assistant
# Install Python dependencies
pip install -r requirements-aws.txt
# Verify Python version (3.8+ required)
python --version步骤3:配置NEJM API凭据
# Option A: Environment Variable (Recommended)
export NEJM_API_KEY='your-userid|your-api-key'
# Option B: Secure Config File
cd on-prem
python config_manager.py --set-key 'your-userid|your-api-key' --environment qa
# Test credentials
python ../testing/simple_nejm_test.py步骤4:部署AWS基础设施
# Navigate to AWS deployment folder
cd aws-deployment
# Deploy complete infrastructure (takes 10-15 minutes)
python deploy_aws_website.py
# Deploy Lambda dependencies
python deploy_lambda_layer.py
# Update Lambda function with latest code
python fix_lambda_quickly.py步骤5:配置安全性(可选但推荐)
# Set up IP-based access control
python implement_ip_security.py
# Enable CORS for web access
python enable_cors.py
# Test security configuration
python ../testing/test_security_lockdown.py步骤6:迁移初始数据
# Migrate articles from local database (if you have one)
python migrate_all_articles.py
# OR populate with fresh NEJM articles
python populate_aws_test.py --count 50步骤7:测试部署
# Test API functionality
cd ../testing
python test_stats_api.py
# Test ingestion
python test_ingestion_api.py
# Test NEJM API access
python test_nejm_api_access.py步骤8:访问您的部署
- web界面: http://nejm-research-web-interface.s3-website-us-east-1.amazonaws.com
- HTTPS版本: https://d2u3y79uc809ee.cloudfront.net
- API端点: https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research
______________________________________________________________________
🏠 方案2:内部部署
先决条件
- 码头工人 已安装Docker Compose
- Python 3.8+ 使用pip
- 8GB+内存 推荐用于AI模型
- NEJM API证书 (用户ID和API密钥)
第一步:安装Docker
# macOS
brew install docker docker-compose
# Windows
# Download Docker Desktop from: https://www.docker.com/products/docker-desktop
# Linux (Ubuntu/Debian)
sudo apt update
sudo apt install docker.io docker-compose
# Verify installation
docker --version
docker-compose --version步骤2:克隆和设置存储库
# Clone repository
git clone
cd nejm-research-assistant
# Install Python dependencies
pip install -r requirements-web.txt
# Verify Python version
python --version步骤3:启动核心服务
# Start Qdrant vector database
docker run -d --name qdrant -p 6333:6333 qdrant/qdrant
# Start Ollama AI service
docker run -d --name ollama -p 11434:11434 ollama/ollama
# Verify services are running
curl http://127.0.0.1:6333/healthz
curl http://127.0.0.1:11434/api/tags
# Check Docker containers
docker ps步骤4:安装AI模型
# Pull embedding model (required for semantic search)
docker exec ollama ollama pull nomic-embed-text
# Pull chat model (required for AI assistant)
docker exec ollama ollama pull llama3.2
# Verify models are installed
docker exec ollama ollama list步骤5:配置NEJM API访问
# Navigate to on-prem folder
cd on-prem
# Option A: Interactive setup wizard
python setup_wizard.py
# Option B: Manual configuration
python config_manager.py --set-key 'your-userid|your-api-key' --environment qa
# Test NEJM API connection
python nejm_api_client.py --dry-run --limit 3步骤6:初始化数据库并摄取文章
# Create vector database collection
python semantic_search.py --init
# Ingest initial articles from NEJM
python automated_ingestion.py --source nejm-ai --count 25
# Verify articles were ingested
python list_all_articles.py步骤7:启动Web界面
# Start Flask web server
python web_interface.py
# The server will start on http://localhost:8080
# You should see: "Running on http://127.0.0.1:8080"步骤8:测试您的设置
# In a new terminal, test the AI research assistant
cd on-prem
python ai_research_assistant.py "What are the latest AI developments in healthcare?"
# Test semantic search
python semantic_search.py
# Test CLI search
python nejm_search_cli.py --query "machine learning" --limit 5步骤9:访问本地系统
- web界面: http://localhost:8080
- 数据库统计信息:可在web界面中使用
- 直接API:Qdrant athttp://localhost:6333
- AI模型:Ollama在http://localhost:11434
______________________________________________________________________
🔧 高级配置
NEJM API环境
# QA Environment (default, recommended for testing)
python config_manager.py --set-key 'your-key' --environment qa
# Production Environment (requires production API key)
python config_manager.py --set-key 'your-prod-key' --environment production
# List configured environments
python config_manager.py --list数据库管理
# On-Premises: Qdrant Management
cd on-prem
# View all articles
python list_all_articles.py
# Search articles
python semantic_search.py
# Clean article retrieval
python clean_article_retriever.py --doi "10.1056/NEJMoa2345678"
# AWS: OpenSearch Management
cd aws-deployment
# View database statistics
python debug_api_gateway.py
# Direct OpenSearch operations
python direct_opensearch_insert.py --test监控与维护
# On-Premises Monitoring
# Check service health
curl http://127.0.0.1:6333/healthz # Qdrant
curl http://127.0.0.1:11434/api/tags # Ollama
# View Docker logs
docker logs qdrant
docker logs ollama
# AWS Monitoring
# Check Lambda logs
aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/nejm"
# Check API Gateway metrics
cd aws-deployment
python debug_api_gateway.py______________________________________________________________________
🚨 故障排除
常见问题
Docker服务未启动
# Check Docker is running
docker info
# Restart services
docker restart qdrant ollama
# Check port conflicts
lsof -i :6333 # Qdrant port
lsof -i :11434 # Ollama portNEJM API连接问题
# Test credentials manually
curl -H "apiuser: your-userid" -H "apikey: your-key" \
"https://onesearch-api.nejmgroup-qa.org/api/v1/simple?context=nejm&objectType=nejm-article&pageLength=1"
# Check configuration
cd on-prem
python config_manager.py --listAWS部署问题
# Check AWS credentials
aws sts get-caller-identity
# Verify permissions
aws iam get-user
# Check service status
cd aws-deployment
python debug_api_gateway.py模型加载问题
# Re-pull models
docker exec ollama ollama pull nomic-embed-text
docker exec ollama ollama pull llama3.2
# Check available models
docker exec ollama ollama list
# Check Ollama logs
docker logs ollama获取帮助
- 检查
docs/详细文档文件夹 - 审查
testing/诊断脚本文件夹 - 检查Docker容器日志以了解服务问题
- 验证API凭据和网络连接
使用示例
AWS Web界面
- 访问:http://nejm-research-web-interface.s3-website-us-east-1.amazonaws.com
- 输入医学研究问题
- 查看AI分析和源文章
- 使用摄入互动程序添加新文章
- 监控系统运行状况和成本
本地Web界面
- 启动服务:
docker run -d -p 6333:6333 qdrant/qdrant && docker run -d -p 11434:11434 ollama/ollama - 启动web界面:
cd on-prem && python web_interface.py - 访问:http://localhost:8080
- 输入研究问题并查看AI生成的答案
- 监控本地数据库统计信息和运行状况
命令行使用(本地)
# Ask a research question
cd on-prem
python ai_research_assistant.py "What are the latest treatments for diabetes?"
# Search for specific articles
python nejm_search_cli.py --query "machine learning" --limit 5
# List all articles in database
python list_all_articles.py
# Ingest new articles
python automated_ingestion.py --source nejm --count 50AWS API集成
import requests
# Search for articles
response = requests.post(
'https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research',
json={
'query': 'diabetes treatment machine learning',
'max_results': 10
}
)
# Get database statistics
stats = requests.post(
'https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research',
json={'type': 'statistics'}
)
# Ingest new articles
ingestion = requests.post(
'https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research',
json={
'type': 'ingestion',
'source': 'nejm',
'count': 25
}
)📊 性能和成本
当前指标
- 搜索响应时间:约2-5秒用于AI分析
- 摄入速度:每分钟约10-15篇文章
- 数据库大小:297篇文章(约30MB索引内容)
- 每月AWS成本:~52美元(OpenSearch 45美元,Bedrock 3美元,其他4美元)
可扩展性目标
- 目标数据库大小:50000篇文章(NEJM历史档案)
- 预计每月成本:全尺寸约75-100美元
- 搜索性能:保持低于3秒的响应时间
- 并发用户:专为10多名同步研究人员设计
📁 项目结构
nejm-research-assistant/
├── aws-deployment/ # AWS cloud deployment files
│ ├── deploy_aws_website.py
│ ├── fix_lambda_quickly.py
│ ├── aws_web_interface_full.html
│ └── ...
├── on-prem/ # On-premises deployment files
│ ├── ai_research_assistant.py
│ ├── web_interface.py
│ ├── semantic_search.py
│ ├── templates/
│ └── ...
├── testing/ # Test scripts and sample data
│ ├── test_*.py
│ ├── simple_*.py
│ └── ...
├── archived/ # Legacy/unused files
└── docs/ # Documentation files🔧 开发与维护
AWS脚本
aws-deployment/fix_lambda_quickly.py-用最新功能更新Lambda函数aws-deployment/add_missing_tiles.py-部署更新的web界面testing/test_ingestion_api.py-验证摄入功能aws-deployment/debug_api_gateway.py-API连接疑难解答
本地脚本
on-prem/ai_research_assistant.py-指挥线研究助理on-prem/web_interface.py-本地web仪表板on-prem/semantic_search.py-核心搜索功能on-prem/setup_wizard.py-初始设置和配置
监控命令
AWS云监控
# Check system health
cd aws-deployment
python debug_api_gateway.py
# View Lambda logs
aws logs get-log-events --log-group-name "/aws/lambda/nejm-research-assistant"
# Test API endpoints
curl -X POST https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research \
-H "Content-Type: application/json" \
-d '{"type": "statistics"}'
# Check OpenSearch cluster health
aws opensearch describe-domain --domain-name nejm-research
# Monitor costs
aws ce get-cost-and-usage --time-period Start=2025-12-01,End=2025-12-31 \
--granularity MONTHLY --metrics BlendedCost现场监控
# Check service health
curl http://127.0.0.1:6333/healthz # Qdrant
curl http://127.0.0.1:11434/api/tags # Ollama
# View Docker container status
docker ps
docker stats
# Check database statistics
cd on-prem
python list_all_articles.py --stats
# Monitor system resources
htop # or top on systems without htop
df -h # disk usage
free -h # memory usage维护任务
定期维护(每周)
# Update article database
cd on-prem
python automated_ingestion.py --source nejm --count 25
# AWS: Trigger ingestion via web interface or API
curl -X POST https://lwi6jeeczi.execute-api.us-east-1.amazonaws.com/prod/research \
-H "Content-Type: application/json" \
-d '{"type": "ingestion", "source": "nejm", "count": 25}'
# Check for duplicate articles
python list_all_articles.py --duplicates
# Backup configuration (on-premises)
cp ~/.nejm_api/config.json ~/.nejm_api/config.json.backup系统更新
# Update Docker images (on-premises)
docker pull qdrant/qdrant:latest
docker pull ollama/ollama:latest
# Update AI models
docker exec ollama ollama pull nomic-embed-text
docker exec ollama ollama pull llama3.2
# Update Python dependencies
pip install -r requirements-web.txt --upgrade # On-premises
pip install -r requirements-aws.txt --upgrade # AWS
# Update AWS Lambda functions
cd aws-deployment
python fix_lambda_quickly.py🔧 开发与维护
📝 文档
设置指南
docs/AWS_DEPLOYMENT_SUCCESS.md-完整的AWS基础架构设置指南docs/SECURITY_IMPLEMENTATION_SUCCESS.md-安全配置详细信息docs/NEJM_API_ACCESS_SUCCESS.md-API集成文档API_KEY_SETUP.md-NEJM API凭证配置
项目状态
docs/PROJECT_STATUS_COMPREHENSIVE.md-详细的项目状态跟踪docs/SESSION_SUMMARY_DEC15_2024.md-最新开发会议总结docs/FINAL_DEPLOYMENT_SUMMARY.md-完整的部署概述
使用指南
docs/SEARCH_USAGE_GUIDE.md-搜索功能文档docs/NEJM_CONTENT_SOURCES.md-可用内容来源和覆盖范围
🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
______________________________________________________________________
最后更新:2025年12月15日\ 系统状态: ✅ 全面运作\ 数据库计数:297篇文章,并且还在增长
