PROD-01工程级18 min

LLM 选品系统:从关键词到爆款预测

通过 Qwen2.5-3B 轻量模型 + Supabase + PGVector 构建选品推荐系统,自动分析亚马逊搜索词背后的用户意图与市场机会。

Qwen2.5-3BSupabasePGVectorEmbedding选品模型

项目背景

独立站卖家的核心难题是"卖什么"——在亚马逊百万商品中,如何找到竞争度低、需求稳定的细分机会?传统做法靠人工盯关键词榜单,效率低且容易错过窗口期。

本系统用 Qwen2.5-3B 做轻量意图分析,结合 Supabase + PGVector 向量检索,从搜索关键词中自动挖掘高潜力产品类目。整套流程从关键词输入到候选产品列表输出,控制在 3 秒内。

技术架构

整体架构分为三层:采集层负责从亚马逊 API 或第三方数据源(Helium10、JungleScout)拉取关键词月搜索量、竞争度、价格带数据;向量化层用 Qwen2.5-3B 对每条关键词做意图Embedding,存入 PGVector;推理层接收用户输入的种子词,返回相似意图的候选品类并附市场指标。

embed_pipeline.py
from supabase import create_client
from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12')
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)

def embed_keyword(keyword: str) -> list:
    embedding = model.encode(keyword, convert_to_numpy=True)
    return embedding.tolist()

def search_similar(keyword: str, top_k: int = 10):
    query_vec = embed_keyword(keyword)
    result = supabase.rpc(
        'match_keywords',
        {'query_embedding': query_vec, 'match_threshold': 0.75, 'match_count': top_k}
    ).execute()
    return result.data

# 种子词 -> Top-10 相似意图候选
candidates = search_similar('running shoes for men', top_k=10)
for item in candidates:
    print(f"  {item['keyword']} | volume: {item['monthly_vol']} | competition: {item['competition']}")

核心代码

意图 Embedding 的核心在于多语言模型。本系统用 paraphrase-multilingual-MiniLM-L12 兼顾英文效果与中文关键词理解能力(很多长尾词含中文拼音)。PGVector 的 `cosine_distance` 配合 `match_threshold=0.75` 过滤低相关结果。

scoring.py
def score_product(opportunity: dict) -> float:
    volume = opportunity.get('monthly_vol', 0)
    competition = opportunity.get('competition', 10)
    price = opportunity.get('avg_price', 0)
    margin = opportunity.get('estimated_margin', 0)

    demand_score = min(volume / 10000, 1.0) * 0.4
    competition_score = min(competition / 10, 1.0) * 0.3
    margin_score = min(margin / 0.3, 1.0) * 0.3

    return demand_score + (1 - competition_score) + margin_score

opportunities = [
    {'keyword': 'waterproof running socks', 'monthly_vol': 8200, 'competition': 3.2, 'avg_price': 18.5, 'estimated_margin': 0.28},
    {'keyword': 'marathon hydration belt', 'monthly_vol': 3400, 'competition': 1.8, 'avg_price': 24.0, 'estimated_margin': 0.35},
]

ranked = sorted(opportunities, key=score_product, reverse=True)
print("Top pick:", ranked[0]['keyword'], f"score={score_product(ranked[0]):.3f}")

关键指标

· Embedding 延迟:Qwen2.5-3B 单条推理 < 200ms,批量 100 条 < 15s
· 向量检索 QPS:PGVector 单节点 ~500/s,扩展到 3 节点可达 1500/s
· 召回准确率:Top-10 候选与人工标注相比,NDCG@10 > 0.78
· 覆盖语种:支持英语、西班牙语、德语、法语、日语种子词扩展

数据源建议:关键词数据优先用亚马逊 Brand Analytics(需品牌备案),次选 Helium10 或 JS API。数据质量直接影响 Embedding 效果,搜索量 < 100/月的词建议过滤。