You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GCP Vertex AI Retail Search获取完整商品详情?

解决Vertex AI Retail Search仅返回商品ID和名称的问题

默认情况下,Vertex AI Retail Search的Search API仅返回Product.name字段。要获取标题、描述、价格等额外商品详情,你需要在SearchRequest中显式指定要返回的字段。

修改请求添加返回字段

在你的请求中加入return_fields参数,列出需要获取的字段路径(需匹配Retail Search的Product schema定义):

# Initialize request argument(s)
request = retail_v2alpha.SearchRequest(
    placement="projects/PROJECT_ID/locations/global/catalogs/default_catalog/placements/default_search",
    query="writing lesson",
    visitor_id="test_visitor",
    # 指定需要返回的字段
    return_fields=[
        "title",
        "description",
        "price_info.price",
        "brand",
        "categories"
        # 可根据需求添加其他字段
    ]
)
logging.debug("Request: {}".format(request))
# Make the request
page_result = client.search(request=request)
# Handle the response
for response in page_result:
    print(response)

字段路径规则

  • 顶层字段(如标题、品牌):直接填写字段名,例如"title"、"brand"
  • 嵌套字段(如价格信息):使用点语法访问层级结构,例如价格字段为"price_info.price",原价为"price_info.original_price"
  • 若需返回所有字段,可使用通配符"*",但生产环境不建议这么做——会增加响应体积和延迟

关键注意点

  • 确保你的商品数据中实际包含这些字段,否则返回结果中对应字段会为空值
  • 字段名称必须严格匹配Retail Search的Product schema,不能自定义命名

内容的提问来源于stack exchange,提问作者Ruchit Rami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 15:22:13