据我所知,您可以使用documents
参数或file
参数来告诉openai您想要搜索的标签。我使用documents
参数时得到了预期的结果,而使用file
参数时结果不尽如人意。我原本期望它们的结果是一样的。
当使用documents
参数进行搜索时..
response = dict(openai.Engine('davinci').search( query='sitcom', #file=file_id, max_rerank=5, documents=["white house", "school", "seinfeld"], return_metadata=False))
..我得到了预期的结果..”sitcom”在搜索中得分771,胜出。
{'object': 'list', 'data': [<OpenAIObject search_result at 0xb5e8ef48> JSON: { "document": 0, "object": "search_result", "score": 147.98}, <OpenAIObject search_result at 0xb5ebd148> JSON: { "document": 1, "object": "search_result", "score": 211.021}, <OpenAIObject search_result at 0xb5ebd030> JSON: { "document": 2, "object": "search_result", "score": 771.348}], 'model': 'davinci:2020-05-03'}
现在尝试使用file
参数,我创建了一个temp.jsonl
文件,内容如下..
{"text": "white house", "metadata": "metadata here"}{"text": "school", "metadata": "metadata here"}{"text": "seinfeld", "metadata": "metadata here"}
然后我将文件上传到openai服务器..
res = openai.File.create(file=open('temp.jsonl'), purpose="search")
其中..
file_id = res['id']
我等待服务器处理完文件后..
response = dict(openai.Engine('davinci').search( query='sitcom', file=file_id, max_rerank=5, #documents=["white house", "school", "seinfeld"], return_metadata=False))
但当我执行搜索时,我得到了以下消息..
No similar documents were found in file with ID 'file-LzHkASUxbDjTAWBhHxHpIOf4'.Please upload more documents or adjust your query.
只有当我的查询完全匹配标签时,我才能得到结果..
response = dict(openai.Engine('davinci').search( query='seinfeld', file=file_id, max_rerank=5, #documents=["white house", "school", "seinfeld"], return_metadata=False)){'object': 'list', 'data': [<OpenAIObject search_result at 0xb5e74f48> JSON: { "document": 0, "object": "search_result", "score": 668.846, "text": "seinfeld"}], 'model': 'davinci:2020-05-03'}
我做错了什么?使用documents
参数或file
参数的结果不应该是一样的吗?
回答:
重新阅读文档后,我发现,当使用file
参数而不是documents
参数时,服务器首先使用提供的query
执行基本的“关键词”搜索以缩小结果范围,然后再使用相同的query
对这些结果进行语义搜索重新排序。
这令人失望。
为了提供一个工作示例..
{"text": "stairway to the basement", "metadata": "metadata here"}{"text": "school", "metadata": "metadata here"}{"text": "stairway to heaven", "metadata": "metadata here"}
现在使用查询“led zeppelin’s most famous song stairway”,服务器会将结果缩小到文档0和文档2,找到“stairway”这个词的匹配项。然后它会执行语义搜索并对这两者进行评分。文档2(“stairway to heaven”)将获得最高的相关性得分。
使用查询“stairway to the underground floor”将使文档0(“stairway to the basement”)获得最高的相关性得分。
这令人失望,因为查询必须对关键词搜索和语义搜索都有效。
在我的原始帖子中,关键词搜索没有提供任何结果,因为查询仅设计用于语义搜索。当使用documents
参数时,只执行语义搜索,这就是为什么在那种情况下它能工作的原因。