`vespa` tutorial : ./src/python/user_search.py U33527 10 KeyError: 'children'

`vespa` tutorial : ./src/python/user_search.py U33527 10 KeyError: 'children'

我正在逐步遵循 Vespa 教程:https://docs.vespa.ai/en/tutorials/news-5-recommendation.html

(vespa) raphy@pc:~/vespa/sample-apps/news$ python3 src/python/train_cold_start.py mind 10
Total loss after epoch 9: 534.6995239257812 (0.4087916910648346 avg)
{'auc': 0.8578, 'mrr': 0.4789, 'ndcg@5': 0.5482, 'ndcg@10': 0.6013}
{'auc': 0.6265, 'mrr': 0.2846, 'ndcg@5': 0.3117, 'ndcg@10': 0.3747}
Total loss after epoch 10: 517.1571044921875 (0.39538004994392395 avg)
{'auc': 0.8758, 'mrr': 0.5073, 'ndcg@5': 0.5817, 'ndcg@10': 0.6315}
{'auc': 0.6246, 'mrr': 0.2843, 'ndcg@5': 0.3113, 'ndcg@10': 0.3732}
(vespa) raphy@pc:~/vespa/sample-apps/news$ 

但是我遇到了这个问题:

(vespa) raphy@pc:~/vespa/sample-apps/news$ ./src/python/user_search.py U33527 10
Traceback (most recent call last):
  File "./src/python/user_search.py", line 58, in <module>
    main()
  File "./src/python/user_search.py", line 51, in main
    user_vector = query_user_embedding(user_id)
  File "./src/python/user_search.py", line 21, in query_user_embedding
    embedding = parse_embedding(result["root"]["children"][0])
KeyError: 'children'
(vespa) raphy@pc:~/vespa/sample-apps/news$ 


(vespa) raphy@pc:~/vespa/sample-apps/news$ grep "U33527" mind/vespa_user_embeddings.json
{"put": "id:user:user::U33527", "fields": {"user_id":"U33527", "embedding": {"values": [0.000000,0.060903,0.158397,0.003585,0.230960,0.005171,-0.300856,-0.295116,-0.042150,-0.416067,-0.173345,-0.241960,-0.140207,-0.000399,0.463869,-0.294422,-0.080257,-0.208765,-0.070218,0.189583,0.031040,-0.073909,-0.147883,-0.164819,-0.229605,-0.248327,0.174647,-0.168265,-0.370106,-0.209611,-0.206252,-0.288447,0.091576,-0.122662,0.000394,0.172982,-0.147844,0.326629,-0.103831,-0.312612,-0.209032,0.190745,-0.335539,0.261593,0.699852,0.041234,0.241921,0.052331,0.103968,-0.216830,-0.279406]} }},

OS: Ubuntu 20.04

如何解决?

Vespa 索引在此处没有 user 文档,因此很可能 usernews 嵌入尚未提供给系统。上一步计算出来后(https://docs.vespa.ai/en/tutorials/news-4-embeddings.html),一定要把它们喂给Vespa:

$ java -jar vespa-http-client-jar-with-dependencies.jar \
       --file mind/vespa_user_embeddings.json \
       --endpoint http://localhost:8080
$ java -jar vespa-http-client-jar-with-dependencies.jar \
       --file mind/vespa_news_embeddings.json \
       --endpoint http://localhost:8080

这将解决问题。