用 CocoIndex 把商品目录变成推荐图谱:LLM 分类提取 + Neo4j 增量构建实战
2026/9/15 13:32:40
Lychee-Rerank-MM是基于Qwen2.5-VL的多模态重排序模型,专门用于图文检索场景的精排任务。这个7B参数的模型采用BF16精度推理,由哈工大深圳NLP团队开发,能够处理文本到文本、文本到图像、图像到文本以及图像到图像等多种模态组合的重排序需求。
确保系统中已安装以下基础组件:
# 检查Python版本 python3 --version # 需要3.8+ # 检查PyTorch安装 python3 -c "import torch; print(torch.__version__)" # 需要2.0+模型默认路径为/root/ai-models/vec-ai/lychee-rerank-mm,如果路径不存在,需要先下载模型:
mkdir -p /root/ai-models/vec-ai cd /root/ai-models/vec-ai git clone https://www.modelscope.cn/vec-ai/lychee-rerank-mm.git进入项目目录安装所需依赖:
cd /root/ai-models/vec-ai/lychee-rerank-mm pip install -r requirements.txt推荐使用以下三种方式之一启动服务:
# 方式1:使用启动脚本(推荐) ./start.sh # 方式2:直接运行 python app.py # 方式3:后台运行(生产环境推荐) nohup python app.py > /tmp/lychee_server.log 2>&1 &ps aux | grep "python app.py"输出示例:
user 12345 0.5 2.1 1234567 89012 pts/0 Sl 14:30 0:05 python app.pykill 12345 # 替换为实际的PIDtail -f /tmp/lychee_server.log创建监控脚本monitor.sh确保服务持续运行:
#!/bin/bash while true; do if ! pgrep -f "python app.py" > /dev/null; then echo "$(date): Service not running, restarting..." >> /var/log/lychee_monitor.log nohup python /root/lychee-rerank-mm/app.py > /tmp/lychee_server.log 2>&1 & fi sleep 60 done赋予执行权限并启动监控:
chmod +x monitor.sh nohup ./monitor.sh > /dev/null 2>&1 &curl http://localhost:7860/health预期返回:
{"status":"healthy"}curl -X POST http://localhost:7860/api/v1/rerank \ -H "Content-Type: application/json" \ -d '{ "instruction": "Given a web search query, retrieve relevant passages that answer the query", "query": "What is the capital of China?", "documents": ["The capital of China is Beijing.", "Shanghai is the largest city in China."] }'对于大量文档,使用批量模式可显著提升效率:
# 示例Python代码 import requests url = "http://localhost:7860/api/v1/batch_rerank" data = { "instruction": "Given a product image and description, retrieve similar products", "query": "product_image.jpg", # 或文本查询 "documents": ["doc1.txt", "doc2.jpg", ...] # 支持混合模态 } response = requests.post(url, json=data)根据硬件配置调整以下参数:
max_length:控制处理文本的最大长度(默认3200)batch_size:批量处理时的文档数量flash_attention:确保启用以获得最佳性能检查步骤:
# 确认模型路径 ls /root/ai-models/vec-ai/lychee-rerank-mm # 检查GPU可用性 nvidia-smi # 验证依赖版本 pip list | grep torch解决方案:
batch_size--precision bf16参数排查方法:
# 检查端口占用 netstat -tulnp | grep 7860 # 检查日志错误 grep -i error /tmp/lychee_server.log本教程详细介绍了Lychee-Rerank-MM模型的部署和管理方法,重点包括:
通过本指南,您可以轻松地在生产环境中部署和管理这个强大的多模态重排序模型,为图文检索应用提供精准的排序能力。
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。