我如何使用 Marqo 进行推荐? [已关闭]

问题描述 投票:0回答:1

我想使用 marqo.ai 从数据库中获取与查询类似性质的建议。

我已经在 python 中下载了 marqo 包并按照文档进行操作,但我没有从 mq.index("").search(q="") 获得最佳结果。

recommendation-engine semantic-search marqo
1个回答
0
投票

您可以通过搜索索引中已有内容的向量来在 Marqo 中实现推荐系统。这将返回邻近的产品,您还可以将其与搜索词结合起来,将搜索和推荐效果结合到一个操作中。在代码中,这个模式看起来像:

# get the document with the embedding for the item you want to recommend based off
item_with_facets = mq.index("my-index").get_document(
    document_id=item_id, expose_facets=True
)
# get the vector for the item
vec = item_with_facets["_tensor_facets"][0]["_embedding"]
# search with the vector
result = mq.index("my-index").search(
    q=None,
    context={"tensor": [{"vector": vec, "weight": 1}]},
    filter_string=f"NOT _id:{item_id}", # filter out the item so it doesn't recommend itself
    limit=num_results,
)

您还可以包含搜索词,如下所示:

result = mq.index("my-index").search(
    q={"shirt": 1.0},
    context={"tensor": [{"vector": vec, "weight": 0.2}]},
    filter_string=f"NOT _id:{item_id}",
    limit=num_results,
)

此搜索“衬衫”和 item_id 向量,其加权平均值使用 1 和 0.2 的权重。

© www.soinside.com 2019 - 2024. All rights reserved.