Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
e3d1624e
M
milvus
项目概览
milvus
/
milvus
接近 1 年 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
e3d1624e
编写于
2月 01, 2023
作者:
C
Cai Yudong
提交者:
GitHub
2月 01, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle distance Inf correctly (#21828)
Signed-off-by:
N
yudong.cai
<
yudong.cai@zilliz.com
>
上级
ec282b19
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
130 addition
and
120 deletion
+130
-120
internal/core/src/query/SubSearchResult.cpp
internal/core/src/query/SubSearchResult.cpp
+16
-4
internal/core/src/query/SubSearchResult.h
internal/core/src/query/SubSearchResult.h
+1
-1
internal/proxy/task_search.go
internal/proxy/task_search.go
+1
-1
internal/proxy/task_search_test.go
internal/proxy/task_search_test.go
+61
-62
internal/querynode/result.go
internal/querynode/result.go
+1
-1
internal/querynode/result_test.go
internal/querynode/result_test.go
+49
-50
tests/python_client/common/common_func.py
tests/python_client/common/common_func.py
+1
-1
未找到文件。
internal/core/src/query/SubSearchResult.cpp
浏览文件 @
e3d1624e
...
...
@@ -40,17 +40,29 @@ SubSearchResult::merge_impl(const SubSearchResult& right) {
auto
rit
=
0
;
// right iter
for
(
auto
buf_iter
=
0
;
buf_iter
<
topk_
;
++
buf_iter
)
{
auto
left_id
=
left_ids
[
lit
];
auto
left_v
=
left_distances
[
lit
];
auto
right_id
=
right_ids
[
rit
];
auto
right_v
=
right_distances
[
rit
];
// optimize out at compiling
if
(
is_desc
?
(
left_v
>=
right_v
)
:
(
left_v
<=
right_v
))
{
if
(
left_id
==
INVALID_SEG_OFFSET
)
{
buf_distances
[
buf_iter
]
=
right_distances
[
rit
];
buf_ids
[
buf_iter
]
=
right_ids
[
rit
];
++
rit
;
}
else
if
(
right_id
==
INVALID_SEG_OFFSET
)
{
buf_distances
[
buf_iter
]
=
left_distances
[
lit
];
buf_ids
[
buf_iter
]
=
left_ids
[
lit
];
++
lit
;
}
else
{
buf_distances
[
buf_iter
]
=
right_distances
[
rit
];
buf_ids
[
buf_iter
]
=
right_ids
[
rit
];
++
rit
;
if
(
is_desc
?
(
left_v
>=
right_v
)
:
(
left_v
<=
right_v
))
{
buf_distances
[
buf_iter
]
=
left_distances
[
lit
];
buf_ids
[
buf_iter
]
=
left_ids
[
lit
];
++
lit
;
}
else
{
buf_distances
[
buf_iter
]
=
right_distances
[
rit
];
buf_ids
[
buf_iter
]
=
right_ids
[
rit
];
++
rit
;
}
}
}
std
::
copy_n
(
buf_distances
.
data
(),
topk_
,
left_distances
);
...
...
internal/core/src/query/SubSearchResult.h
浏览文件 @
e3d1624e
...
...
@@ -27,7 +27,7 @@ class SubSearchResult {
topk_
(
topk
),
round_decimal_
(
round_decimal
),
metric_type_
(
metric_type
),
seg_offsets_
(
num_queries
*
topk
,
-
1
),
seg_offsets_
(
num_queries
*
topk
,
INVALID_SEG_OFFSET
),
distances_
(
num_queries
*
topk
,
init_value
(
metric_type
))
{
}
...
...
internal/proxy/task_search.go
浏览文件 @
e3d1624e
...
...
@@ -655,7 +655,7 @@ func selectHighestScoreIndex(subSearchResultData []*schemapb.SearchResultData, s
sScore
:=
subSearchResultData
[
i
]
.
Scores
[
sIdx
]
// Choose the larger score idx or the smaller pk idx with the same score
if
sScore
>
maxScore
{
if
s
ubSearchIdx
==
-
1
||
s
Score
>
maxScore
{
subSearchIdx
=
i
resultDataIdx
=
sIdx
maxScore
=
sScore
...
...
internal/proxy/task_search_test.go
浏览文件 @
e3d1624e
...
...
@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"strconv"
"strings"
"testing"
...
...
@@ -1271,67 +1270,67 @@ func TestTaskSearch_selectHighestScoreIndex(t *testing.T) {
}
})
t
.
Run
(
"Integer ID with bad score"
,
func
(
t
*
testing
.
T
)
{
type
args
struct
{
subSearchResultData
[]
*
schemapb
.
SearchResultData
subSearchNqOffset
[][]
int64
cursors
[]
int64
topk
int64
nq
int64
}
tests
:=
[]
struct
{
description
string
args
args
expectedIdx
[]
int
expectedDataIdx
[]
int
}{
{
description
:
"reduce 2 subSearchResultData"
,
args
:
args
{
subSearchResultData
:
[]
*
schemapb
.
SearchResultData
{
{
Ids
:
&
schemapb
.
IDs
{
IdField
:
&
schemapb
.
IDs_IntId
{
IntId
:
&
schemapb
.
LongArray
{
Data
:
[]
int64
{
11
,
9
,
8
,
5
,
3
,
1
},
},
},
},
Scores
:
[]
float32
{
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
},
Topks
:
[]
int64
{
2
,
2
,
2
},
},
{
Ids
:
&
schemapb
.
IDs
{
IdField
:
&
schemapb
.
IDs_IntId
{
IntId
:
&
schemapb
.
LongArray
{
Data
:
[]
int64
{
12
,
10
,
7
,
6
,
4
,
2
},
},
},
},
Scores
:
[]
float32
{
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
},
Topks
:
[]
int64
{
2
,
2
,
2
},
},
},
subSearchNqOffset
:
[][]
int64
{{
0
,
2
,
4
},
{
0
,
2
,
4
}},
cursors
:
[]
int64
{
0
,
0
},
topk
:
2
,
nq
:
3
,
},
expectedIdx
:
[]
int
{
-
1
,
-
1
,
-
1
},
expectedDataIdx
:
[]
int
{
-
1
,
-
1
,
-
1
},
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
description
,
func
(
t
*
testing
.
T
)
{
for
nqNum
:=
int64
(
0
);
nqNum
<
test
.
args
.
nq
;
nqNum
++
{
idx
,
dataIdx
:=
selectHighestScoreIndex
(
test
.
args
.
subSearchResultData
,
test
.
args
.
subSearchNqOffset
,
test
.
args
.
cursors
,
nqNum
)
assert
.
Equal
(
t
,
test
.
expectedIdx
[
nqNum
],
idx
)
assert
.
Equal
(
t
,
test
.
expectedDataIdx
[
nqNum
],
int
(
dataIdx
))
}
})
}
})
//
t.Run("Integer ID with bad score", func(t *testing.T) {
//
type args struct {
//
subSearchResultData []*schemapb.SearchResultData
//
subSearchNqOffset [][]int64
//
cursors []int64
//
topk int64
//
nq int64
//
}
//
tests := []struct {
//
description string
//
args args
//
//
expectedIdx []int
//
expectedDataIdx []int
//
}{
//
{
//
description: "reduce 2 subSearchResultData",
//
args: args{
//
subSearchResultData: []*schemapb.SearchResultData{
//
{
//
Ids: &schemapb.IDs{
//
IdField: &schemapb.IDs_IntId{
//
IntId: &schemapb.LongArray{
//
Data: []int64{11, 9, 8, 5, 3, 1},
//
},
//
},
//
},
//
Scores: []float32{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32},
//
Topks: []int64{2, 2, 2},
//
},
//
{
//
Ids: &schemapb.IDs{
//
IdField: &schemapb.IDs_IntId{
//
IntId: &schemapb.LongArray{
//
Data: []int64{12, 10, 7, 6, 4, 2},
//
},
//
},
//
},
//
Scores: []float32{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32},
//
Topks: []int64{2, 2, 2},
//
},
//
},
//
subSearchNqOffset: [][]int64{{0, 2, 4}, {0, 2, 4}},
//
cursors: []int64{0, 0},
//
topk: 2,
//
nq: 3,
//
},
//
expectedIdx: []int{-1, -1, -1},
//
expectedDataIdx: []int{-1, -1, -1},
//
},
//
}
//
for _, test := range tests {
//
t.Run(test.description, func(t *testing.T) {
//
for nqNum := int64(0); nqNum < test.args.nq; nqNum++ {
//
idx, dataIdx := selectHighestScoreIndex(test.args.subSearchResultData, test.args.subSearchNqOffset, test.args.cursors, nqNum)
// assert.Not
Equal(t, test.expectedIdx[nqNum], idx)
// assert.Not
Equal(t, test.expectedDataIdx[nqNum], int(dataIdx))
//
}
//
})
//
}
//
})
t
.
Run
(
"String ID"
,
func
(
t
*
testing
.
T
)
{
type
args
struct
{
...
...
internal/querynode/result.go
浏览文件 @
e3d1624e
...
...
@@ -193,7 +193,7 @@ func selectSearchResultData(dataArray []*schemapb.SearchResultData, resultOffset
idx
:=
resultOffsets
[
i
][
qi
]
+
offset
distance
:=
dataArray
[
i
]
.
Scores
[
idx
]
if
distance
>
maxDistance
{
if
sel
==
-
1
||
distance
>
maxDistance
{
sel
=
i
maxDistance
=
distance
resultDataIdx
=
idx
...
...
internal/querynode/result_test.go
浏览文件 @
e3d1624e
...
...
@@ -18,7 +18,6 @@ package querynode
import
(
"context"
"math"
"testing"
"github.com/stretchr/testify/assert"
...
...
@@ -475,54 +474,54 @@ func TestResult_selectSearchResultData_int(t *testing.T) {
}
})
t
.
Run
(
"Integer ID with bad score"
,
func
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
args
args
want
int
}{
{
args
:
args
{
dataArray
:
[]
*
schemapb
.
SearchResultData
{
{
Ids
:
&
schemapb
.
IDs
{
IdField
:
&
schemapb
.
IDs_IntId
{
IntId
:
&
schemapb
.
LongArray
{
Data
:
[]
int64
{
11
,
9
,
7
,
5
,
3
,
1
},
},
},
},
Scores
:
[]
float32
{
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
},
Topks
:
[]
int64
{
2
,
2
,
2
},
},
{
Ids
:
&
schemapb
.
IDs
{
IdField
:
&
schemapb
.
IDs_IntId
{
IntId
:
&
schemapb
.
LongArray
{
Data
:
[]
int64
{
12
,
10
,
8
,
6
,
4
,
2
},
},
},
},
Scores
:
[]
float32
{
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
,
-
math
.
MaxFloat32
},
Topks
:
[]
int64
{
2
,
2
,
2
},
},
},
resultOffsets
:
[][]
int64
{{
0
,
2
,
4
},
{
0
,
2
,
4
}},
offsets
:
[]
int64
{
0
,
1
},
topk
:
2
,
nq
:
3
,
qi
:
0
,
},
want
:
-
1
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
selectSearchResultData
(
tt
.
args
.
dataArray
,
tt
.
args
.
resultOffsets
,
tt
.
args
.
offsets
,
tt
.
args
.
qi
);
got
!=
tt
.
want
{
t
.
Errorf
(
"selectSearchResultData() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
})
//
t.Run("Integer ID with bad score", func(t *testing.T) {
//
tests := []struct {
//
name string
//
args args
//
want int
//
}{
//
{
//
args: args{
//
dataArray: []*schemapb.SearchResultData{
//
{
//
Ids: &schemapb.IDs{
//
IdField: &schemapb.IDs_IntId{
//
IntId: &schemapb.LongArray{
//
Data: []int64{11, 9, 7, 5, 3, 1},
//
},
//
},
//
},
//
Scores: []float32{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32},
//
Topks: []int64{2, 2, 2},
//
},
//
{
//
Ids: &schemapb.IDs{
//
IdField: &schemapb.IDs_IntId{
//
IntId: &schemapb.LongArray{
//
Data: []int64{12, 10, 8, 6, 4, 2},
//
},
//
},
//
},
//
Scores: []float32{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32},
//
Topks: []int64{2, 2, 2},
//
},
//
},
//
resultOffsets: [][]int64{{0, 2, 4}, {0, 2, 4}},
//
offsets: []int64{0, 1},
//
topk: 2,
//
nq: 3,
//
qi: 0,
//
},
//
want: -1,
//
},
//
}
//
for _, tt := range tests {
//
t.Run(tt.name, func(t *testing.T) {
//
if got := selectSearchResultData(tt.args.dataArray, tt.args.resultOffsets, tt.args.offsets, tt.args.qi); got != tt.want {
//
t.Errorf("selectSearchResultData() = %v, want %v", got, tt.want)
//
}
//
})
//
}
//
})
}
tests/python_client/common/common_func.py
浏览文件 @
e3d1624e
...
...
@@ -621,7 +621,7 @@ def tanimoto(x, y):
y
=
np
.
asarray
(
y
,
np
.
bool_
)
res
=
np
.
double
(
np
.
bitwise_and
(
x
,
y
).
sum
())
/
np
.
double
(
np
.
bitwise_or
(
x
,
y
).
sum
())
if
res
==
0
:
value
=
0
value
=
float
(
"inf"
)
else
:
value
=
-
np
.
log2
(
res
)
return
value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录