Blame view

offline_tasks/i2i_content_pic_analysis.md 4.68 KB
c59dd0b0   tangwang   补充部分任务明文版本输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  # i2i_content_pic 零产出原因分析
  
  ## 📋 问题描述
  
  `output/i2i_content_pic_20251022.txt` 文件大小为0字节,没有产生任何图片向量相似度索引数据。
  
  ## 🔍 原因分析
  
  ### 1. ES数据检查结果
  
  **检查命令:**
  ```bash
  curl -u "essa:4hOaLaf41y2VuI8y" "http://localhost:9200/spu/_count" \
    -H 'Content-Type: application/json' \
    -d '{"query": {"exists": {"field": "embedding_pic_h14"}}}'
  ```
  
  **结果:**
  ```json
  {"count": 0}
  ```
  
  ### 2. ES Mapping 检查
  
  **字段定义存在:**
  ```json
  {
    "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中没有图片向量数据,所以在代码的以下位置被跳过:
  
  ```python
  # 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:生成图片向量数据(推荐)
  
  需要开发或运行图片向量生成流程:
  
  1. **采集商品图片**
     - 从商品数据库获取图片URL
     - 下载或访问图片资源
  
  2. **生成图片向量**
     - 使用图像embedding模型(如CLIP H/14)
     - 将图片转换为1024维向量
  
  3. **导入ES**
     - 更新商品文档,添加 `embedding_pic_h14` 字段
     - 格式:`[{"url": "图片URL", "vector": [1024维向量]}]`
  
  ### 方案2:暂时禁用图片向量索引
  
  如果短期内无法生成图片向量,可以:
  
  **修改 `i2i_content_similar.py`:**
  
  ```python
  # 第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`:**
  
  ```python
  # 第87行,从加载列表中移除 content_pic
  i2i_types = ['swing', 'session_w2v', 'deepwalk', 'content_name']  # 移除 'content_pic'
  ```
  
  ### 方案3:检查是否有其他图片向量字段
  
  如果图片向量使用了其他字段名,需要:
  
  1. 检查ES mapping中是否有其他图片相关的向量字段
  2. 更新脚本中的字段名配置
  
  ## 📊 当前数据统计
  
  | 向量类型 | ES中有数据的商品数 | 索引产出数 | 状态 |
  |---------|------------------|-----------|------|
  | 名称向量 (embedding_name_zh) | ~172,000 | 127,511 | ✅ 正常 |
  | 图片向量 (embedding_pic_h14) | 0 | 0 | ❌ 无数据 |
  
  ## 🔄 后续建议
  
  1. **确认业务需求:** 是否真的需要基于图片的相似推荐?
  2. **评估优先级:** 图片向量生成的成本和收益
  3. **制定计划:** 如果需要,制定图片向量生成的技术方案和时间表
  4. **更新文档:** 在相关文档中说明 `i2i_content_pic` 的状态
  
  ## ⚙️ 检查脚本
  
  可以使用以下脚本快速检查ES中的向量数据情况:
  
  ```bash
  #!/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` 并执行:
  ```bash
  chmod +x check_es_vectors.sh
  ./check_es_vectors.sh
  ```