Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
5616ec74
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,发现更多精彩内容 >>
提交
5616ec74
编写于
3月 25, 2019
作者:
X
xj.lin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix much bug
上级
925af7e1
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
53 addition
and
15 deletion
+53
-15
pyengine/engine/controller/scheduler.py
pyengine/engine/controller/scheduler.py
+11
-2
pyengine/engine/controller/tests/test_vector_engine.py
pyengine/engine/controller/tests/test_vector_engine.py
+18
-3
pyengine/engine/controller/tests/test_views.py
pyengine/engine/controller/tests/test_views.py
+12
-2
pyengine/engine/controller/vector_engine.py
pyengine/engine/controller/vector_engine.py
+3
-2
pyengine/engine/controller/views.py
pyengine/engine/controller/views.py
+2
-2
pyengine/engine/ingestion/build_index.py
pyengine/engine/ingestion/build_index.py
+1
-1
pyengine/engine/ingestion/serialize.py
pyengine/engine/ingestion/serialize.py
+5
-1
pyengine/engine/model/group_table.py
pyengine/engine/model/group_table.py
+0
-1
pyengine/engine/settings.py
pyengine/engine/settings.py
+1
-1
未找到文件。
pyengine/engine/controller/scheduler.py
浏览文件 @
5616ec74
from
engine.retrieval
import
search_index
from
engine.ingestion
import
build_index
from
engine.ingestion
import
serialize
import
numpy
as
np
class
Singleton
(
type
):
_instances
=
{}
...
...
@@ -22,25 +23,33 @@ class Scheduler(metaclass=Singleton):
def
__scheduler
(
self
,
index_data_key
,
vectors
,
k
):
result_list
=
[]
d
=
None
raw_vectors
=
None
print
(
"__scheduler: vectors: "
,
vectors
)
query_vectors
=
np
.
asarray
(
vectors
).
astype
(
'float32'
)
if
'raw'
in
index_data_key
:
raw_vectors
=
index_data_key
[
'raw'
]
raw_vectors
=
np
.
asarray
(
raw_vectors
).
astype
(
'float32'
)
d
=
index_data_key
[
'dimension'
]
if
'raw'
in
index_data_key
:
index_builder
=
build_index
.
FactoryIndex
()
print
(
"d: "
,
d
,
" raw_vectors: "
,
raw_vectors
)
index
=
index_builder
().
build
(
d
,
raw_vectors
)
searcher
=
search_index
.
FaissSearch
(
index
)
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
result_list
.
append
(
searcher
.
search_by_vectors
(
query_
vectors
,
k
))
index_data_list
=
index_data_key
[
'index'
]
for
key
in
index_data_list
:
index
=
GetIndexData
(
key
)
searcher
=
search_index
.
FaissSearch
(
index
)
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
result_list
.
append
(
searcher
.
search_by_vectors
(
query_
vectors
,
k
))
if
len
(
result_list
)
==
1
:
return
result_list
[
0
].
vectors
total_result
=
[]
# result = search_index.top_k(result_list, k)
return
result_list
...
...
pyengine/engine/controller/tests/test_vector_engine.py
浏览文件 @
5616ec74
...
...
@@ -11,7 +11,9 @@ logger = logging.getLogger(__name__)
class
TestVectorEngine
:
def
setup_class
(
self
):
self
.
__vector
=
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
]
self
.
__limit
=
3
self
.
__vector_2
=
[
1.2
,
2.2
,
3.3
,
4.5
,
5.5
,
6.6
,
7.8
,
8.8
]
self
.
__query_vector
=
[[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],[
1.2
,
2.2
,
3.3
,
4.5
,
5.5
,
6.6
,
7.8
,
8.8
]]
self
.
__limit
=
1
def
teardown_class
(
self
):
...
...
@@ -39,6 +41,7 @@ class TestVectorEngine:
# Check the group list
code
,
group_list
=
VectorEngine
.
GetGroupList
()
assert
code
==
VectorEngine
.
SUCCESS_CODE
print
(
"group_list: "
,
group_list
)
assert
group_list
==
[{
'group_name'
:
'test_group'
,
'file_number'
:
0
}]
# Add Vector for not exist group
...
...
@@ -46,11 +49,23 @@ class TestVectorEngine:
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector_2
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector_2
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector_2
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector_2
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
# Check search vector interface
code
,
vector_id
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
code
,
vector_id
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__
query_
vector
,
self
.
__limit
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
0
...
...
pyengine/engine/controller/tests/test_views.py
浏览文件 @
5616ec74
...
...
@@ -52,12 +52,22 @@ class TestViews:
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
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
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
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
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
resp
=
test_client
.
post
(
'/vector/index/6'
)
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
limit
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],
"limit"
:
3
}
resp
=
test_client
.
ge
t
(
'/vector/search/6'
,
data
=
json
.
dumps
(
limit
))
limit
=
{
"vector"
:
[
1.1
,
2.2
,
3.3
,
4.4
,
5.5
,
6.6
,
7.7
,
8.8
],
"limit"
:
1
}
resp
=
test_client
.
pos
t
(
'/vector/search/6'
,
data
=
json
.
dumps
(
limit
))
assert
resp
.
status_code
==
200
assert
self
.
loads
(
resp
)[
'code'
]
==
0
assert
self
.
loads
(
resp
)[
'vector_id'
]
==
0
...
...
pyengine/engine/controller/vector_engine.py
浏览文件 @
5616ec74
...
...
@@ -94,7 +94,7 @@ class VectorEngine(object):
# check if the file can be indexed
if
file
.
row_number
+
1
>=
ROW_LIMIT
:
raw_data
=
GetVectorListFromRawFile
(
group_id
)
raw_data
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
)
d
=
group
.
dimension
# create index
...
...
@@ -144,7 +144,7 @@ class VectorEngine(object):
index_keys
=
[
i
.
filename
for
i
in
files
if
i
.
type
==
'index'
]
index_map
=
{}
index_map
[
'index'
]
=
index_keys
index_map
[
'raw'
]
=
GetVectorListFromRawFile
(
group_id
)
index_map
[
'raw'
]
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
,
"fakename"
)
index_map
[
'dimension'
]
=
group
.
dimension
scheduler_instance
=
Scheduler
()
...
...
@@ -189,6 +189,7 @@ class VectorEngine(object):
@
staticmethod
def
GetVectorListFromRawFile
(
group_id
,
filename
=
"todo"
):
return
VectorEngine
.
group_dict
[
group_id
]
# return serialize.to_array(VectorEngine.group_dict[group_id])
@
staticmethod
def
ClearRawFile
(
group_id
):
...
...
pyengine/engine/controller/views.py
浏览文件 @
5616ec74
...
...
@@ -28,9 +28,9 @@ class VectorSearch(Resource):
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
self
.
__parser
.
add_argument
(
'limit'
,
type
=
int
,
action
=
'append'
,
location
=
[
'json'
])
def
ge
t
(
self
,
group_id
):
def
pos
t
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
print
(
'vector: '
,
args
[
'vector'
])
print
(
'
VectorSearch
vector: '
,
args
[
'vector'
])
# go to search every thing
code
,
vector_id
=
VectorEngine
.
SearchVector
(
group_id
,
args
[
'vector'
],
args
[
'limit'
])
return
jsonify
({
'code'
:
code
,
'vector_id'
:
vector_id
})
...
...
pyengine/engine/ingestion/build_index.py
浏览文件 @
5616ec74
...
...
@@ -15,7 +15,7 @@ def FactoryIndex(index_name="DefaultIndex"):
class
Index
():
def
build
(
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
def
build
(
self
,
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
pass
@
staticmethod
...
...
pyengine/engine/ingestion/serialize.py
浏览文件 @
5616ec74
import
faiss
import
numpy
as
np
def
write_index
(
index
,
file_name
):
faiss
.
write_index
(
index
,
file_name
)
def
read_index
(
file_name
):
return
faiss
.
read_index
(
file_name
)
\ No newline at end of file
return
faiss
.
read_index
(
file_name
)
def
to_array
(
vec
):
return
np
.
asarray
(
vec
).
astype
(
'float32'
)
\ No newline at end of file
pyengine/engine/model/group_table.py
浏览文件 @
5616ec74
...
...
@@ -12,7 +12,6 @@ class GroupTable(db.Model):
self
.
group_name
=
group_name
self
.
dimension
=
dimension
self
.
file_number
=
0
self
.
dimension
=
0
def
__repr__
(
self
):
...
...
pyengine/engine/settings.py
浏览文件 @
5616ec74
...
...
@@ -6,4 +6,4 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_DATABASE_URI
=
"mysql+pymysql://vecwise@127.0.0.1:3306/vecdata"
ROW_LIMIT
=
10000000
DATABASE_DIRECTORY
=
'/home/jinhai/disk0/vecwise/db'
\ No newline at end of file
DATABASE_DIRECTORY
=
'/tmp'
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录