diff --git a/api/models.py b/api/models.py index 2e6a3ca..9998da7 100644 --- a/api/models.py +++ b/api/models.py @@ -198,7 +198,7 @@ class ProductResult(BaseModel): image_url: Optional[str] = Field(None, description="主图URL") in_stock: bool = Field(True, description="是否有库存") variants: List[VariantResult] = Field(default_factory=list, description="变体列表") - relevance_score: float = Field(..., ge=0.0, le=1.0, description="相关性分数(0-1)") + relevance_score: float = Field(..., ge=0.0, description="相关性分数(ES原始分数)") class SearchResponse(BaseModel): diff --git a/api/result_formatter.py b/api/result_formatter.py index b17a6ab..9fcd498 100644 --- a/api/result_formatter.py +++ b/api/result_formatter.py @@ -19,7 +19,7 @@ class ResultFormatter: Args: es_hits: List of ES hit dictionaries (with _id, _score, _source) - max_score: Maximum score for normalization + max_score: Maximum score (unused, kept for compatibility) Returns: List of ProductResult objects @@ -30,11 +30,8 @@ class ResultFormatter: source = hit.get('_source', {}) score = hit.get('_score', 0.0) - # Normalize relevance score to 0-1 - if max_score > 0: - relevance_score = min(score / max_score, 1.0) - else: - relevance_score = 0.0 + # Use original ES score directly (no normalization) + relevance_score = score # Extract variants variants = [] diff --git a/docs/BASE_CONFIG_GUIDE.md b/docs/BASE_CONFIG_GUIDE.md index c30bdf8..013ec98 100644 --- a/docs/BASE_CONFIG_GUIDE.md +++ b/docs/BASE_CONFIG_GUIDE.md @@ -179,7 +179,7 @@ Content-Type: application/json 2. **结构化结果**:每个结果包含`product_id`, `title`, `variants`, `relevance_score`等字段 3. **无ES内部字段**:不包含`_id`, `_score`, `_source`等ES内部字段 4. **嵌套variants**:每个商品包含variants数组,每个variant包含完整的变体信息 -5. **相关性分数**:`relevance_score`是0-1之间的归一化分数 +5. **相关性分数**:`relevance_score`是ES原始分数(不进行归一化) #### ProductResult字段 @@ -196,7 +196,7 @@ Content-Type: application/json - `image_url` - 主图URL - `in_stock` - 是否有库存 - `variants` - 变体列表 -- `relevance_score` - 相关性分数(0-1) +- `relevance_score` - 相关性分数(ES原始分数) #### VariantResult字段 -- libgit2 0.21.2