i2i_content_pic_analysis.md
4.68 KB
i2i_content_pic 零产出原因分析
📋 问题描述
output/i2i_content_pic_20251022.txt 文件大小为0字节,没有产生任何图片向量相似度索引数据。
🔍 原因分析
1. ES数据检查结果
检查命令:
curl -u "essa:4hOaLaf41y2VuI8y" "http://localhost:9200/spu/_count" \
-H 'Content-Type: application/json' \
-d '{"query": {"exists": {"field": "embedding_pic_h14"}}}'
结果:
{"count": 0}
2. ES Mapping 检查
字段定义存在:
{
"embedding_pic_h14": {
"type": "nested",
"properties": {
"url": {
"type": "text"
},
"vector": {
"type": "dense_vector",
"dims": 1024,
"index": true,
"similarity": "dot_product"
}
}
}
}
3. 脚本执行情况
从日志 logs/debug/i2i_content_similar_20251022_015349.log 可以看到:
- 活跃商品数: 172,049 个
- 名称向量索引产出: 127,511 个商品
- 图片向量索引产出: 0 个商品
脚本正常运行,但因为ES中没有图片向量数据,所以在代码的以下位置被跳过:
# i2i_content_similar.py 第183-192行
elif vector_field == 'embedding_pic_h14':
pic_data = item_data.get('embedding_pic_h14')
if pic_data and isinstance(pic_data, list) and len(pic_data) > 0:
query_vector = pic_data[0].get('vector') if isinstance(pic_data[0], dict) else None
else:
query_vector = None
if not query_vector:
continue # 跳过没有向量的商品
🎯 结论
核心原因: Elasticsearch索引中没有任何商品的图片向量(embedding_pic_h14)数据。
这不是代码问题,而是数据缺失问题。图片向量数据尚未生成或导入到ES中。
💡 解决方案
方案1:生成图片向量数据(推荐)
需要开发或运行图片向量生成流程:
采集商品图片
- 从商品数据库获取图片URL
- 下载或访问图片资源
生成图片向量
- 使用图像embedding模型(如CLIP H/14)
- 将图片转换为1024维向量
导入ES
- 更新商品文档,添加
embedding_pic_h14字段 - 格式:
[{"url": "图片URL", "vector": [1024维向量]}]
- 更新商品文档,添加
方案2:暂时禁用图片向量索引
如果短期内无法生成图片向量,可以:
修改 i2i_content_similar.py:
# 第280-286行,注释掉图片向量索引生成
# log_processing_step(logger, "生成基于图片向量的相似索引")
# pic_result = generate_similarity_index(
# es, active_items, 'embedding_pic_h14', 'pic', logger
# )
# pic_output = os.path.join(OUTPUT_DIR, f'i2i_content_pic_{date_str}.txt')
# save_index_file(pic_result, es, pic_output, logger)
logger.info("⚠️ 跳过图片向量索引生成(ES中无图片向量数据)")
修改 load_index_to_redis.py:
# 第87行,从加载列表中移除 content_pic
i2i_types = ['swing', 'session_w2v', 'deepwalk', 'content_name'] # 移除 'content_pic'
方案3:检查是否有其他图片向量字段
如果图片向量使用了其他字段名,需要:
- 检查ES mapping中是否有其他图片相关的向量字段
- 更新脚本中的字段名配置
📊 当前数据统计
| 向量类型 | ES中有数据的商品数 | 索引产出数 | 状态 |
|---|---|---|---|
| 名称向量 (embedding_name_zh) | ~172,000 | 127,511 | ✅ 正常 |
| 图片向量 (embedding_pic_h14) | 0 | 0 | ❌ 无数据 |
🔄 后续建议
- 确认业务需求: 是否真的需要基于图片的相似推荐?
- 评估优先级: 图片向量生成的成本和收益
- 制定计划: 如果需要,制定图片向量生成的技术方案和时间表
- 更新文档: 在相关文档中说明
i2i_content_pic的状态
⚙️ 检查脚本
可以使用以下脚本快速检查ES中的向量数据情况:
#!/bin/bash
echo "=== ES向量数据检查 ==="
echo ""
echo "1. 名称向量 (embedding_name_zh):"
curl -s -u "essa:4hOaLaf41y2VuI8y" "http://localhost:9200/spu/_count" \
-H 'Content-Type: application/json' \
-d '{"query": {"exists": {"field": "embedding_name_zh"}}}' | python3 -m json.tool
echo ""
echo "2. 图片向量 (embedding_pic_h14):"
curl -s -u "essa:4hOaLaf41y2VuI8y" "http://localhost:9200/spu/_count" \
-H 'Content-Type: application/json' \
-d '{"query": {"exists": {"field": "embedding_pic_h14"}}}' | python3 -m json.tool
echo ""
echo "3. 总商品数:"
curl -s -u "essa:4hOaLaf41y2VuI8y" "http://localhost:9200/spu/_count" | python3 -m json.tool
保存为 check_es_vectors.sh 并执行:
chmod +x check_es_vectors.sh
./check_es_vectors.sh