Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
374bd2f6
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
374bd2f6
编写于
3月 27, 2019
作者:
X
xiaojun.lin
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'linxj' into 'develop'
Linxj See merge request jinhai/vecwise_engine!12
上级
4542abad
aab9f9f2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
65 addition
and
10 deletion
+65
-10
pyengine/engine/controller/scheduler.py
pyengine/engine/controller/scheduler.py
+1
-1
pyengine/engine/controller/tests/test_scheduler.py
pyengine/engine/controller/tests/test_scheduler.py
+2
-2
pyengine/engine/controller/vector_engine.py
pyengine/engine/controller/vector_engine.py
+8
-7
pyengine/engine/controller/views.py
pyengine/engine/controller/views.py
+1
-0
pyengine/tests/test_function.py
pyengine/tests/test_function.py
+53
-0
未找到文件。
pyengine/engine/controller/scheduler.py
浏览文件 @
374bd2f6
...
@@ -42,7 +42,7 @@ class Scheduler(metaclass=Singleton):
...
@@ -42,7 +42,7 @@ class Scheduler(metaclass=Singleton):
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
if
len
(
result_list
)
==
1
:
if
len
(
result_list
)
==
1
:
return
result_list
[
0
].
vectors
return
result_list
[
0
].
vectors
[
0
].
tolist
()
# TODO(linxj): fix hard code
return
result_list
;
# TODO(linxj): add topk
return
result_list
;
# TODO(linxj): add topk
...
...
pyengine/engine/controller/tests/test_scheduler.py
浏览文件 @
374bd2f6
...
@@ -6,10 +6,10 @@ import numpy as np
...
@@ -6,10 +6,10 @@ import numpy as np
class
TestScheduler
(
unittest
.
TestCase
):
class
TestScheduler
(
unittest
.
TestCase
):
def
test_s
chedule
(
self
):
def
test_s
ingle_query
(
self
):
d
=
64
d
=
64
nb
=
10000
nb
=
10000
nq
=
2
nq
=
1
nt
=
5000
nt
=
5000
xt
,
xb
,
xq
=
get_dataset
(
d
,
nb
,
nt
,
nq
)
xt
,
xb
,
xq
=
get_dataset
(
d
,
nb
,
nt
,
nq
)
ids_xb
=
np
.
arange
(
xb
.
shape
[
0
])
ids_xb
=
np
.
arange
(
xb
.
shape
[
0
])
...
...
pyengine/engine/controller/vector_engine.py
浏览文件 @
374bd2f6
...
@@ -112,8 +112,8 @@ class VectorEngine(object):
...
@@ -112,8 +112,8 @@ class VectorEngine(object):
'type'
:
'index'
,
'type'
:
'index'
,
'filename'
:
index_filename
,
'filename'
:
index_filename
,
'seq_no'
:
file
.
seq_no
+
1
})
'seq_no'
:
file
.
seq_no
+
1
})
pass
db
.
session
.
commit
()
VectorEngine
.
group_dict
=
None
else
:
else
:
# we still can insert into exist raw file, update database
# we still can insert into exist raw file, update database
FileTable
.
query
.
filter
(
FileTable
.
group_name
==
group_id
).
filter
(
FileTable
.
type
==
'raw'
).
update
({
'row_number'
:
file
.
row_number
+
1
,
FileTable
.
query
.
filter
(
FileTable
.
group_name
==
group_id
).
filter
(
FileTable
.
type
==
'raw'
).
update
({
'row_number'
:
file
.
row_number
+
1
,
...
@@ -159,9 +159,8 @@ class VectorEngine(object):
...
@@ -159,9 +159,8 @@ class VectorEngine(object):
vectors
.
append
(
vector
)
vectors
.
append
(
vector
)
result
=
scheduler_instance
.
search
(
index_map
,
vectors
,
limit
)
result
=
scheduler_instance
.
search
(
index_map
,
vectors
,
limit
)
vector_id
=
[
0
]
vector_ids_str
=
[]
vector_ids_str
=
[]
for
int_id
in
vector_id
:
for
int_id
in
result
:
vector_ids_str
.
append
(
group_id
+
'.'
+
str
(
int_id
))
vector_ids_str
.
append
(
group_id
+
'.'
+
str
(
int_id
))
return
VectorEngine
.
SUCCESS_CODE
,
vector_ids_str
return
VectorEngine
.
SUCCESS_CODE
,
vector_ids_str
...
@@ -201,14 +200,16 @@ class VectorEngine(object):
...
@@ -201,14 +200,16 @@ class VectorEngine(object):
VectorEngine
.
group_vector_dict
[
group_id
].
append
(
vector
)
VectorEngine
.
group_vector_dict
[
group_id
].
append
(
vector
)
VectorEngine
.
group_vector_id_dict
[
group_id
].
append
(
vector_id
)
VectorEngine
.
group_vector_id_dict
[
group_id
].
append
(
vector_id
)
print
(
'InsertVectorIntoRawFile: '
,
VectorEngine
.
group_vector_dict
[
group_id
],
VectorEngine
.
group_vector_id_dict
[
group_id
])
# print('InsertVectorIntoRawFile: ', VectorEngine.group_vector_dict[group_id], VectorEngine.group_vector_id_dict[group_id])
print
(
"cache size: "
,
len
(
VectorEngine
.
group_vector_dict
[
group_id
]))
return
filename
return
filename
@
staticmethod
@
staticmethod
def
GetVectorListFromRawFile
(
group_id
,
filename
=
"todo"
):
def
GetVectorListFromRawFile
(
group_id
,
filename
=
"todo"
):
print
(
"GetVectorListFromRawFile, vectors: "
,
serialize
.
to_array
(
VectorEngine
.
group_vector_dict
[
group_id
]))
#
print("GetVectorListFromRawFile, vectors: ", serialize.to_array(VectorEngine.group_vector_dict[group_id]))
print
(
"GetVectorListFromRawFile, vector_ids: "
,
serialize
.
to_int_array
(
VectorEngine
.
group_vector_id_dict
[
group_id
]))
#
print("GetVectorListFromRawFile, vector_ids: ", serialize.to_int_array(VectorEngine.group_vector_id_dict[group_id]))
return
serialize
.
to_array
(
VectorEngine
.
group_vector_dict
[
group_id
]),
serialize
.
to_int_array
(
VectorEngine
.
group_vector_id_dict
[
group_id
])
return
serialize
.
to_array
(
VectorEngine
.
group_vector_dict
[
group_id
]),
serialize
.
to_int_array
(
VectorEngine
.
group_vector_id_dict
[
group_id
])
@
staticmethod
@
staticmethod
...
...
pyengine/engine/controller/views.py
浏览文件 @
374bd2f6
...
@@ -17,6 +17,7 @@ class Vector(Resource):
...
@@ -17,6 +17,7 @@ class Vector(Resource):
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
def
post
(
self
,
group_id
):
def
post
(
self
,
group_id
):
print
(
request
.
json
)
args
=
self
.
__parser
.
parse_args
()
args
=
self
.
__parser
.
parse_args
()
vector
=
args
[
'vector'
]
vector
=
args
[
'vector'
]
code
,
vector_id
=
VectorEngine
.
AddVector
(
group_id
,
vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
group_id
,
vector
)
...
...
pyengine/tests/test_function.py
0 → 100644
浏览文件 @
374bd2f6
import
numpy
as
np
import
requests
import
pytest
import
logging
import
json
url
=
"http://127.0.0.1:5000"
# TODO: LOG and Assert
class
TestEngineFunction
():
def
test_1m_add
(
self
):
d
=
4
nb
=
100
nq
=
1
k
=
10
_
,
xb
,
xq
=
get_dataset
(
d
,
nb
,
1
,
nq
)
groupid
=
"test_search_3"
route_group
=
url
+
"/vector/group/"
+
groupid
r
=
requests
.
post
(
route_group
,
json
=
{
"dimension"
:
d
})
# import dataset
vector_add_route
=
url
+
"/vector/add/"
+
groupid
for
i
in
xb
:
data
=
dict
()
data
[
'vector'
]
=
i
.
tolist
()
# print(data)
r
=
requests
.
post
(
vector_add_route
,
json
=
data
)
print
(
r
.
json
())
# search dataset
vector_search_route
=
url
+
"/vector/search/"
+
groupid
data
=
dict
()
for
i
in
xq
:
data
[
'vector'
]
=
i
.
tolist
()
data
[
'limit'
]
=
k
# print(data)
r
=
requests
.
get
(
vector_search_route
,
json
=
data
)
print
(
r
.
json
())
def
get_dataset
(
d
,
nb
,
nt
,
nq
):
d1
=
10
# intrinsic dimension (more or less)
n
=
nb
+
nt
+
nq
rs
=
np
.
random
.
RandomState
(
1338
)
x
=
rs
.
normal
(
size
=
(
n
,
d1
))
x
=
np
.
dot
(
x
,
rs
.
rand
(
d1
,
d
))
x
=
x
*
(
rs
.
rand
(
d
)
*
4
+
0.1
)
x
=
np
.
sin
(
x
)
x
=
x
.
astype
(
'float32'
)
return
x
[:
nt
],
x
[
nt
:
-
nq
],
x
[
-
nq
:]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录