Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
28aed840
M
milvus
项目概览
milvus
/
milvus
11 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
28aed840
编写于
9月 26, 2021
作者:
D
dragondriver
提交者:
GitHub
9月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[skip ci] Add a document to explain how proxy reduce the search results (#8589)
Signed-off-by:
N
dragondriver
<
jiquan.long@zilliz.com
>
上级
019f18dd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
0 deletion
+56
-0
docs/developer_guides/figs/nq_topk_search_results.png
docs/developer_guides/figs/nq_topk_search_results.png
+0
-0
docs/developer_guides/figs/reduce_results.png
docs/developer_guides/figs/reduce_results.png
+0
-0
docs/developer_guides/proxy-reduce-cn.md
docs/developer_guides/proxy-reduce-cn.md
+56
-0
未找到文件。
docs/developer_guides/figs/nq_topk_search_results.png
0 → 100644
浏览文件 @
28aed840
10.4 KB
docs/developer_guides/figs/reduce_results.png
0 → 100644
浏览文件 @
28aed840
23.2 KB
docs/developer_guides/proxy-reduce-cn.md
0 → 100644
浏览文件 @
28aed840
# How Proxy Reduce the Multiple Search Results?
## Search Results 的组织形式
假设对于某个特定的 Search 请求,该 Search 请求 nq = 2,topk = 10,Proxy 收到来自 Query Nodes 的 4 份 Search Result。
每一份 Search Result 都是 nq
*
topk 的二维结构,如下图所示,该结果表示用户输入了 nq 个向量,希望分别获取和这 nq 个向量最相似的 topk 个向量。
![
search_result_format
](
./figs/nq_topk_search_results.png
)
对于同一个 query,topk 个命中结果按照 score 降序,score 越大,表示命中结果与待查向量越相似。不同 query 之间命中结果互相独立。
因此我们下面讨论 Proxy 如何对结果进行归并也只关注一个 query 结果如何归并即可,对 nq 个 query 结果,循环遍历 nq 或者并行处理即可。
于是问题退化为,4 个长度为 topk(10) 的数组,每个数组降序排列,如何从这 4 个数组中得到其中最大的 10(topk) 个数。如下图所示:
![
final_result
](
./figs/reduce_results.png
)
## 多路归并算法
该算法的伪代码如下:
```
golang
n
=
4
multiple_results
=
[[
topk
results
1
],
[
topk
results
2
],
[
topk
results
3
],
[
topk
results
4
]]
locs
=
[
0
,
0
,
0
,
0
]
topk_results
=
[]
for
i
->
topk
:
score
=
min_score
choice
=
-
1
for
j
->
n
:
choiceOffset
=
locs
[
j
]
if
choiceOffset
>
topk
:
// all result from this way has been got, got from other way
continue
score_this_way
=
multiple_results
[
j
][
choiceOffset
]
if
score_this_way
>
score
:
choice
=
j
score
=
score_this_way
if
choice
!=
-
1
:
// update location
locs
[
choice
]
++
topk_results
=
append
(
topk_results
,
choice
)
```
该算法脱胎于归并排序算法的归并阶段,两者共同点是归并时结果已经排序,不同点是归并排序是归并两路结果,reduce 这里归并多路结果。
对比归并排序时使用两个指针记录两路结果的偏移量,proxy reduce 使用多个指针 locs 记录多路结果的偏移量。
具体到该例子,n 表示有 4 份结果需要归并,multiple_results 是四份 topk 的数组,locs 里面每一个 choiceOffset 记录了每一路的偏移量。
该偏移量对应的 score_this_way 记录了当前这一路的最大值,因此取下一个较大的 score 时只需要从这四个最大值里面挑一个即可。
这样子保证了我们每次取的结果都是剩余结果中最大的。
该算法最多只会线性扫描所有的 Search Results,因此该算法的时间复杂度为 n
*
topk。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录