Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
a6833b17
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,发现更多精彩内容 >>
提交
a6833b17
编写于
3月 20, 2019
作者:
J
jinhai
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'jinhai' into 'develop'
Jinhai See merge request jinhai/vecwise_engine!3
上级
86b9134b
25d18944
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
166 addition
and
30 deletion
+166
-30
README.md
README.md
+20
-0
pyengine/engine/controller/IndexManage.py
pyengine/engine/controller/IndexManage.py
+29
-25
pyengine/engine/controller/VectorEngine.py
pyengine/engine/controller/VectorEngine.py
+106
-0
pyengine/engine/model/FileTable.py
pyengine/engine/model/FileTable.py
+6
-3
pyengine/engine/model/GroupTable.py
pyengine/engine/model/GroupTable.py
+1
-1
pyengine/engine/settings.py
pyengine/engine/settings.py
+4
-1
未找到文件。
README.md
浏览文件 @
a6833b17
...
...
@@ -25,3 +25,23 @@
-
`python`
# enter python3 interaction environment
-
`from engine import db`
-
`db.create_all()`
-
table desc
group_table
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| group_name | varchar(100) | YES | | NULL | |
| file_number | int(11) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
file_table
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| group_name | varchar(100) | YES | | NULL | |
| filename | varchar(100) | YES | | NULL | |
| row_number | int(11) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
pyengine/engine/controller/IndexManage.py
浏览文件 @
a6833b17
from
flask
import
Flask
from
flask
import
Flask
,
jsonify
,
request
from
flask_restful
import
Resource
,
Api
from
engine
import
app
,
db
from
engine.model.GroupTable
import
GroupTable
from
engine.controller.VectorEngine
import
VectorEngine
# app = Flask(__name__)
api
=
Api
(
app
)
from
flask_restful
import
reqparse
from
flask_restful
import
request
class
Vector
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'groupid'
,
type
=
str
)
self
.
__parser
.
add_argument
(
'vec'
,
type
=
str
)
self
.
__parser
.
add_argument
(
'vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
])
def
post
(
self
):
# args = self.__parser.parse_args()
# vec = args['vec']
# groupid = args['groupid']
return
"vector post"
def
post
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
vector
=
args
[
'vector'
]
return
VectorEngine
.
AddVector
(
group_id
,
vector
)
class
VectorSearch
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'
groupid'
,
type
=
str
)
self
.
__parser
.
add_argument
(
'
vector'
,
type
=
float
,
action
=
'append'
,
location
=
[
'json'
]
)
def
post
(
self
):
def
post
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
print
(
'vector: '
,
args
[
'vector'
])
# go to search every thing
return
"vectorSearch post"
class
Index
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'group
id'
,
type
=
str
)
# self.__parser.add_argument('group_
id', type=str)
def
post
(
self
):
return
"index post"
def
post
(
self
,
group_id
):
return
VectorEngine
.
CreateIndex
(
group_id
)
class
Group
(
Resource
):
def
__init__
(
self
):
self
.
__parser
=
reqparse
.
RequestParser
()
self
.
__parser
.
add_argument
(
'groupid'
,
type
=
str
)
self
.
__parser
.
add_argument
(
'group
_
id'
,
type
=
str
)
def
post
(
self
,
groupid
):
return
"group post"
def
post
(
self
,
group
_
id
):
return
VectorEngine
.
AddGroup
(
group_id
)
def
get
(
self
,
groupid
):
return
"group get"
def
get
(
self
,
group
_
id
):
return
VectorEngine
.
GetGroup
(
group_id
)
def
delete
(
self
,
groupid
):
return
"group delete"
def
delete
(
self
,
group
_
id
):
return
VectorEngine
.
DeleteGroup
(
group_id
)
class
GroupList
(
Resource
):
def
get
(
self
):
return
"grouplist get"
return
VectorEngine
.
GetGroupList
()
api
.
add_resource
(
Vector
,
'/vector'
)
api
.
add_resource
(
Group
,
'/vector/group/<groupid>'
)
api
.
add_resource
(
Vector
,
'/vector
/add/<group_id>
'
)
api
.
add_resource
(
Group
,
'/vector/group/<group
_
id>'
)
api
.
add_resource
(
GroupList
,
'/vector/group'
)
api
.
add_resource
(
Index
,
'/vector/index'
)
api
.
add_resource
(
VectorSearch
,
'/vector/search'
)
api
.
add_resource
(
Index
,
'/vector/index
/<group_id>
'
)
api
.
add_resource
(
VectorSearch
,
'/vector/search
/<group_id>
'
)
# if __name__ == '__main__':
...
...
pyengine/engine/controller/VectorEngine.py
0 → 100644
浏览文件 @
a6833b17
from
engine.model.GroupTable
import
GroupTable
from
engine.model.FileTable
import
FileTable
from
flask
import
jsonify
from
engine
import
db
import
sys
class
VectorEngine
(
object
):
@
staticmethod
def
AddGroup
(
group_id
):
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
if
(
group
):
return
jsonify
({
'code'
:
1
,
'group_name'
:
group_id
,
'file_number'
:
group
.
file_number
})
else
:
new_group
=
GroupTable
(
group_id
)
db
.
session
.
add
(
new_group
)
db
.
session
.
commit
()
return
jsonify
({
'code'
:
0
,
'group_name'
:
group_id
,
'file_number'
:
0
})
@
staticmethod
def
GetGroup
(
group_id
):
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
if
(
group
):
return
jsonify
({
'code'
:
0
,
'group_name'
:
group_id
,
'file_number'
:
group
.
file_number
})
else
:
return
jsonify
({
'code'
:
1
,
'group_name'
:
group_id
,
'file_number'
:
0
})
# not found
@
staticmethod
def
DeleteGroup
(
group_id
):
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
if
(
group
):
# old_group = GroupTable(group_id)
db
.
session
.
delete
(
group
)
db
.
session
.
commit
()
return
jsonify
({
'code'
:
0
,
'group_name'
:
group_id
,
'file_number'
:
group
.
file_number
})
else
:
return
jsonify
({
'code'
:
0
,
'group_name'
:
group_id
,
'file_number'
:
0
})
@
staticmethod
def
GetGroupList
():
group
=
GroupTable
.
query
.
all
()
group_list
=
[]
for
group_tuple
in
group
:
group_item
=
{}
group_item
[
'group_name'
]
=
group_tuple
.
group_name
group_item
[
'file_number'
]
=
group_tuple
.
file_number
group_list
.
append
(
group_item
)
print
(
group_list
)
return
jsonify
(
results
=
group_list
)
@
staticmethod
def
AddVector
(
group_id
,
vector
):
print
(
group_id
,
vector
)
file
=
FileTable
.
query
.
filter
(
and_
(
FileTable
.
group_name
==
group_id
,
FileTable
.
type
==
'raw'
).
first
()
if
(
file
):
if
(
file
.
row_number
>=
ROW_LIMIT
):
# create index
index_filename
=
file
.
filename
+
"_index"
CreateIndex
(
group_id
,
index_filename
)
# create another raw file
raw_filename
=
file
.
group_id
+
'_'
+
file
.
seq_no
InsertVectorIntoRawFile
(
raw_filename
,
vector
)
# insert a record into database
db
.
session
.
add
(
FileTable
(
group_id
,
raw_filename
,
'raw'
,
1
))
db
.
session
.
commit
()
else
:
# we still can insert into exist raw file
InsertVectorIntoRawFile
(
file
.
filename
,
vector
)
# update database
# FileTable.query.filter_by(FileTable.group_name == group_id).filter_by(FileTable.type == 'raw').update('row_number':file.row_number + 1)
else
:
# first raw file
raw_filename
=
group_id
+
'_0'
# create and insert vector into raw file
InsertVectorIntoRawFile
(
raw_filename
,
vector
)
# insert a record into database
db
.
session
.
add
(
FileTable
(
group_id
,
raw_filename
,
'raw'
,
1
))
db
.
session
.
commit
()
return
jsonify
({
'code'
:
0
})
@
staticmethod
def
SearchVector
(
group_id
,
vector
,
limit
):
# find all files
# according to difference files get topk of each
# reduce the topk from them
# construct response and send back
return
jsonify
({
'code'
:
0
})
@
staticmethod
def
CreateIndex
(
group_id
):
print
(
group_id
)
return
jsonify
({
'code'
:
0
})
@
staticmethod
def
CreateIndex
(
group_id
,
filename
):
print
(
group_id
,
filename
)
return
jsonify
({
'code'
:
0
})
@
staticmethod
def
InsertVectorIntoRawFile
(
filename
,
vector
):
print
(
sys
.
_getframe
().
f_code
.
co_name
)
return
filename
\ No newline at end of file
pyengine/engine/model/FileTable.py
浏览文件 @
a6833b17
...
...
@@ -5,14 +5,17 @@ class FileTable(db.Model):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
group_name
=
db
.
Column
(
db
.
String
(
100
))
filename
=
db
.
Column
(
db
.
String
(
100
))
type
=
(
db
.
Integer
)
type
=
db
.
Column
(
db
.
String
(
100
)
)
row_number
=
db
.
Column
(
db
.
Integer
)
seq_no
=
db
.
Column
(
db
.
Integer
)
def
__init__
(
self
,
group_name
,
filename
,
type
):
def
__init__
(
self
,
group_name
,
filename
,
type
,
row_number
):
self
.
group_name
=
group_name
self
.
filename
=
filename
self
.
type
=
type
self
.
row_number
=
0
self
.
row_number
=
row_number
self
.
type
=
type
self
.
seq_no
=
0
def
__repr__
(
self
):
return
'<FileTable $r>'
%
self
.
tablename
\ No newline at end of file
pyengine/engine/model/GroupTable.py
浏览文件 @
a6833b17
...
...
@@ -11,4 +11,4 @@ class GroupTable(db.Model):
self
.
file_number
=
0
def
__repr__
(
self
):
return
'<GroupTable $r>'
%
self
.
group_name
\ No newline at end of file
return
'<GroupTable $s>'
%
self
.
group_name
\ No newline at end of file
pyengine/engine/settings.py
浏览文件 @
a6833b17
...
...
@@ -3,4 +3,7 @@
DEBUG
=
True
SQLALCHEMY_TRACK_MODIFICATIONS
=
False
# SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
SQLALCHEMY_DATABASE_URI
=
"mysql+pymysql://vecwise@127.0.0.1:3306/vecdata"
\ No newline at end of file
SQLALCHEMY_DATABASE_URI
=
"mysql+pymysql://vecwise@127.0.0.1:3306/vecdata"
ROW_LIMIT
=
10000000
DATABASE_DIRECTORY
=
'/home/jinhai/Document/development/vecwise_engine/db'
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录