fix(server-release): P1.5 表格图片评分修复 + MAX_IMAGES 动态调整
- 修复 P1.5 使用原始检索分数(0-1)对比 MIN_SCORE(2-5)导致表格图片永远无法返回的 bug - 改为使用 score_image_relevance() 计算表格图片相关性分数 - 添加 s=None 初始化,使 P1.5 可独立计算分数 - 添加 MAX_IMAGES 动态调整,支持表格多图场景(上限15)
This commit is contained in:
@@ -1564,6 +1564,18 @@ def select_images(contexts: List[Dict], query: str) -> List[Dict]:
|
||||
MAX_IMAGES = 2
|
||||
MIN_SCORE = 3.0
|
||||
|
||||
# 动态调整:当表格嵌入大量图片时,提升上限以展示完整内容
|
||||
_table_image_count = 0
|
||||
for _ctx in contexts:
|
||||
_meta = _ctx.get('meta', {})
|
||||
if _meta.get('chunk_type') == 'table' and _meta.get('images_json'):
|
||||
try:
|
||||
_table_image_count += len(json.loads(_meta['images_json']))
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
if _table_image_count > MAX_IMAGES:
|
||||
MAX_IMAGES = min(_table_image_count, 15) # 上限 15
|
||||
|
||||
# 获取检索结果中涉及的主要章节(只看前 3 个最相关的文本块)
|
||||
primary_sections = set()
|
||||
for ctx in contexts[:3]:
|
||||
@@ -1584,6 +1596,8 @@ def select_images(contexts: List[Dict], query: str) -> List[Dict]:
|
||||
for ctx in contexts:
|
||||
meta = ctx.get('meta', {})
|
||||
chunk_type = meta.get('chunk_type', 'text')
|
||||
s = None # P1 评分,用于 P1.5 继承
|
||||
doc = ctx.get('doc', '')
|
||||
|
||||
# 处理图片类型和有关联图片的表格类型
|
||||
if meta.get('image_path') and chunk_type in ('image', 'chart', 'table'):
|
||||
@@ -1696,6 +1710,11 @@ def select_images(contexts: List[Dict], query: str) -> List[Dict]:
|
||||
# ========== P1.5:处理表格切片的 images_json(跨页表格多图)==========
|
||||
# 当表格切片有 images_json 字段时,添加所有关联图片
|
||||
if chunk_type == 'table' and meta.get('images_json'):
|
||||
# 如果 P1 未执行(表格无 image_path),需要独立计算分数
|
||||
if s is None:
|
||||
doc = ctx.get('image_description', '') or meta.get('vlm_desc', '') or ctx.get('doc', '')
|
||||
meta['score'] = ctx.get('score', 0)
|
||||
s = score_image_relevance(query, meta, doc)
|
||||
try:
|
||||
images_list = json.loads(meta['images_json'])
|
||||
for img_info in images_list:
|
||||
@@ -1709,9 +1728,7 @@ def select_images(contexts: List[Dict], query: str) -> List[Dict]:
|
||||
# 跳过已添加的图片(避免重复)
|
||||
existing_ids = {img['id'] for img in scored_images}
|
||||
if img_id and img_id not in existing_ids:
|
||||
# 为关联图片计算分数(继承主表格分数,略低)
|
||||
ctx_score = ctx.get("score", 0)
|
||||
assoc_score = ctx_score - 1.0 if ctx_score >= MIN_SCORE else MIN_SCORE - 1.0
|
||||
assoc_score = s - 1.0 if s >= MIN_SCORE else MIN_SCORE - 1.0
|
||||
if assoc_score >= MIN_SCORE:
|
||||
scored_images.append({
|
||||
'score': assoc_score,
|
||||
|
||||
Reference in New Issue
Block a user