使用Marqo添加文档触发MarqoWebError问题求助
解决Marqo add_documents触发MarqoWebError的问题
错误原因
你直接传入单个字符串给add_documents()不符合方法要求。Marqo的add_documents()方法必须接收包含文档字典的列表,每个文档需以键值对形式的字典存在,至少要包含一个用于嵌入和检索的内容字段(比如content)。
修正后的代码
import marqo # 改为文档字典组成的列表 DOCUMENTS = [{"content": "the document"}] mq = marqo.Client(url='http://localhost:8882') # 传入文档列表执行添加 mq.index("my-first-index").add_documents(DOCUMENTS)
额外说明
- 如果需要给文档指定自定义ID,可以在字典中添加
_id字段,示例:DOCUMENTS = [{"_id": "doc_001", "content": "the document"}] - 同时要确认Marqo服务确实在
http://localhost:8882正常运行,服务未启动或端口错误也会触发MarqoWebError。
内容的提问来源于stack exchange,提问作者Ndaman
相关产品推荐
相关产品推荐

