Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
a7636a26
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
a7636a26
编写于
4月 02, 2019
作者:
J
jinhai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add batch import
上级
bd10891c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
66 addition
and
63 deletion
+66
-63
pyengine/engine/controller/tests/test_vector_engine.py
pyengine/engine/controller/tests/test_vector_engine.py
+10
-9
pyengine/engine/controller/tests/test_views.py
pyengine/engine/controller/tests/test_views.py
+3
-3
pyengine/engine/controller/vector_engine.py
pyengine/engine/controller/vector_engine.py
+51
-48
pyengine/engine/controller/views.py
pyengine/engine/controller/views.py
+1
-2
pyengine/engine/run_test.sh
pyengine/engine/run_test.sh
+1
-1
未找到文件。
pyengine/engine/controller/tests/test_vector_engine.py
浏览文件 @
a7636a26
...
@@ -11,6 +11,7 @@ logger = logging.getLogger(__name__)
...
@@ -11,6 +11,7 @@ logger = logging.getLogger(__name__)
class
TestVectorEngine
:
class
TestVectorEngine
:
def
setup_class
(
self
):
def
setup_class
(
self
):
self
.
__vectors
=
[[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]]
self
.
__vector
=
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
self
.
__vector
=
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
self
.
__limit
=
1
self
.
__limit
=
1
...
@@ -44,29 +45,29 @@ class TestVectorEngine:
...
@@ -44,29 +45,29 @@ class TestVectorEngine:
assert
group_list
==
[{
'group_name'
:
'test_group'
,
'file_number'
:
0
}]
assert
group_list
==
[{
'group_name'
:
'test_group'
,
'file_number'
:
0
}]
# Add Vector for not exist group
# Add Vector for not exist group
code
,
vector_id
=
VectorEngine
.
AddVector
(
'not_exist_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'not_exist_group'
,
self
.
__vector
s
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
vector_id
==
'invalid'
assert
vector_id
==
'invalid'
# Add vector for exist group
# Add vector for exist group
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
s
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.0'
assert
vector_id
==
[
'test_group.0'
]
# Add vector for exist group
# Add vector for exist group
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
s
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.1'
assert
vector_id
==
[
'test_group.1'
]
# Add vector for exist group
# Add vector for exist group
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
s
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.2'
assert
vector_id
==
[
'test_group.2'
]
# Add vector for exist group
# Add vector for exist group
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
s
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.3'
assert
vector_id
==
[
'test_group.3'
]
# Check search vector interface
# Check search vector interface
code
,
vector_id
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
code
,
vector_id
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
...
...
pyengine/engine/controller/tests/test_views.py
浏览文件 @
a7636a26
...
@@ -48,17 +48,17 @@ class TestViews:
...
@@ -48,17 +48,17 @@ class TestViews:
assert
resp
.
status_code
==
200
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'code'
]
==
0
vector
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]}
vector
=
{
"vector"
:
[
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
]}
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
assert
resp
.
status_code
==
200
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'code'
]
==
0
vector
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]}
vector
=
{
"vector"
:
[
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
]}
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
assert
resp
.
status_code
==
200
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'code'
]
==
0
vector
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]}
vector
=
{
"vector"
:
[
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
]}
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
resp
=
test_client
.
post
(
'/vector/add/6'
,
data
=
json
.
dumps
(
vector
),
headers
=
TestViews
.
HEADERS
)
assert
resp
.
status_code
==
200
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'code'
]
==
0
...
...
pyengine/engine/controller/vector_engine.py
浏览文件 @
a7636a26
...
@@ -80,14 +80,17 @@ class VectorEngine(object):
...
@@ -80,14 +80,17 @@ class VectorEngine(object):
@
staticmethod
@
staticmethod
def
AddVector
(
group_id
,
vector
):
def
AddVector
(
group_id
,
vector
s
):
print
(
group_id
,
vector
)
print
(
group_id
,
vector
s
)
code
,
_
,
_
=
VectorEngine
.
GetGroup
(
group_id
)
code
,
_
,
_
=
VectorEngine
.
GetGroup
(
group_id
)
if
code
==
VectorEngine
.
FAULT_CODE
:
if
code
==
VectorEngine
.
FAULT_CODE
:
return
VectorEngine
.
GROUP_NOT_EXIST
,
'invalid'
return
VectorEngine
.
GROUP_NOT_EXIST
,
'invalid'
vector_str_list
=
[]
for
vector
in
vectors
:
file
=
FileTable
.
query
.
filter
(
FileTable
.
group_name
==
group_id
).
filter
(
FileTable
.
type
==
'raw'
).
first
()
file
=
FileTable
.
query
.
filter
(
FileTable
.
group_name
==
group_id
).
filter
(
FileTable
.
type
==
'raw'
).
first
()
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
if
file
:
if
file
:
print
(
'insert into exist file'
)
print
(
'insert into exist file'
)
# create vector id
# create vector id
...
@@ -120,7 +123,6 @@ class VectorEngine(object):
...
@@ -120,7 +123,6 @@ class VectorEngine(object):
'seq_no'
:
file
.
seq_no
+
1
})
'seq_no'
:
file
.
seq_no
+
1
})
db
.
session
.
commit
()
db
.
session
.
commit
()
print
(
'Update db for raw file insertion'
)
print
(
'Update db for raw file insertion'
)
pass
else
:
else
:
print
(
'add a new raw file'
)
print
(
'add a new raw file'
)
...
@@ -134,8 +136,9 @@ class VectorEngine(object):
...
@@ -134,8 +136,9 @@ class VectorEngine(object):
db
.
session
.
add
(
FileTable
(
group_id
,
raw_filename
,
'raw'
,
1
))
db
.
session
.
add
(
FileTable
(
group_id
,
raw_filename
,
'raw'
,
1
))
db
.
session
.
commit
()
db
.
session
.
commit
()
vector_id_str
=
group_id
+
'.'
+
str
(
vector_id
)
vector_str_list
.
append
(
group_id
+
'.'
+
str
(
vector_id
))
return
VectorEngine
.
SUCCESS_CODE
,
vector_id_str
return
VectorEngine
.
SUCCESS_CODE
,
vector_str_list
@
staticmethod
@
staticmethod
...
...
pyengine/engine/controller/views.py
浏览文件 @
a7636a26
...
@@ -14,10 +14,9 @@ from flask_restful import request
...
@@ -14,10 +14,9 @@ from flask_restful import request
class
Vector
(
Resource
):
class
Vector
(
Resource
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'vector'
,
type
=
floa
t
,
action
=
'append'
,
location
=
[
'json'
])
self
.
__parser
.
add_argument
(
'vector'
,
type
=
lis
t
,
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/engine/run_test.sh
浏览文件 @
a7636a26
pytest
-v
--disable-warnings
pytest
-v
v
--disable-warnings
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录