elasticsearch _knn_search查询多个字段
我正在使用ES 8.2。我想在超过1个向量上使用_knn_search
的近似方法。下面,我已将当前代码搜索附加在单个向量上。就我阅读_knn_search
而不支持嵌套
字段上的搜索。 另外,我可以使用多索引搜索。一个索引,一个向量,一个搜索,将所有结果总结在一起。但是,我需要将所有这些向量存储在一起一个索引,因为我还需要在其他字段上执行过滤,除了向量进行KNN搜索。
因此,问题是,是否有关于如何在1个以上的向量上执行_KNN_Search
的工作?
search_vector = np.zeros(512).tolist()
es_query = {
"knn": {
"field": "feature_vector_1.vector",
"query_vector": search_vector,
"k": 100,
"num_candidates": 1000
},
"filter": [
{
"range": {
"feature_vector_1.match_prc": {
"gt": 10
}
}
}
],
"_source": {
"excludes": ["feature_vector_1.vector", "feature_vector_2.vector"]
}
}
I'm using ES 8.2. I'd like to use approximate method of _knn_search
on more than 1 vector. Below I've attached my current code searching on a single vector. So far as I've read _knn_search
does not support search on nested
fields.
Alternatively, I can use multi index search. One index, one vector, one search, sum up all results together. However, I need to store all these vectors together in one index as I need also to perform filtration on some other fields besides vectors for knn search.
Thus, the question is if there is a work around how I can perform _knn_search
on more than 1 vector?
search_vector = np.zeros(512).tolist()
es_query = {
"knn": {
"field": "feature_vector_1.vector",
"query_vector": search_vector,
"k": 100,
"num_candidates": 1000
},
"filter": [
{
"range": {
"feature_vector_1.match_prc": {
"gt": 10
}
}
}
],
"_source": {
"excludes": ["feature_vector_1.vector", "feature_vector_2.vector"]
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但是,我最终得到的最后一个工作查询是
,这不是2个向量上的AKNN,但如果此类查询的性能满足您的期望,则仍然可以使用。
The last working query that I've end up with is
However, it is not true AKNN on 2 vectors but still working option if performance of such query satisfies your expectations.
以下似乎对我组合KNN搜索的平均分数对我来说似乎很适合我。请注意,这与原始请求有所不同,因为它执行了蛮力搜索,但是您仍然可以通过更换
match_all
lit来预先过滤结果。the below seems to be working for me for combining KNN searches, taking the average of multiple cosine similarity scores. Note that this is a little different than the original request, since it performs a brute force search, but you can still filter the results up front by replacing the
match_all
bit.