Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
2542f67c
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,发现更多精彩内容 >>
提交
2542f67c
编写于
3月 26, 2019
作者:
J
jinhai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update interface, part 1
上级
def1503c
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
74 addition
and
43 deletion
+74
-43
pyengine/engine/controller/scheduler.py
pyengine/engine/controller/scheduler.py
+2
-1
pyengine/engine/controller/tests/test_scheduler.py
pyengine/engine/controller/tests/test_scheduler.py
+8
-3
pyengine/engine/controller/tests/test_vector_engine.py
pyengine/engine/controller/tests/test_vector_engine.py
+17
-10
pyengine/engine/controller/vector_engine.py
pyengine/engine/controller/vector_engine.py
+38
-23
pyengine/engine/controller/views.py
pyengine/engine/controller/views.py
+2
-2
pyengine/engine/ingestion/build_index.py
pyengine/engine/ingestion/build_index.py
+3
-3
pyengine/engine/ingestion/serialize.py
pyengine/engine/ingestion/serialize.py
+4
-1
未找到文件。
pyengine/engine/controller/scheduler.py
浏览文件 @
2542f67c
...
@@ -26,9 +26,10 @@ class Scheduler(metaclass=Singleton):
...
@@ -26,9 +26,10 @@ class Scheduler(metaclass=Singleton):
if
'raw'
in
index_data_key
:
if
'raw'
in
index_data_key
:
raw_vectors
=
index_data_key
[
'raw'
]
raw_vectors
=
index_data_key
[
'raw'
]
raw_vector_ids
=
index_data_key
[
'raw_id'
]
d
=
index_data_key
[
'dimension'
]
d
=
index_data_key
[
'dimension'
]
index_builder
=
build_index
.
FactoryIndex
()
index_builder
=
build_index
.
FactoryIndex
()
index
=
index_builder
().
build
(
d
,
raw_vectors
)
index
=
index_builder
().
build
(
d
,
raw_vectors
,
raw_vector_ids
)
searcher
=
search_index
.
FaissSearch
(
index
)
searcher
=
search_index
.
FaissSearch
(
index
)
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
result_list
.
append
(
searcher
.
search_by_vectors
(
vectors
,
k
))
...
...
pyengine/engine/controller/tests/test_scheduler.py
浏览文件 @
2542f67c
...
@@ -23,20 +23,25 @@ class TestScheduler(unittest.TestCase):
...
@@ -23,20 +23,25 @@ class TestScheduler(unittest.TestCase):
index2
=
faiss
.
read_index
(
file_name
)
index2
=
faiss
.
read_index
(
file_name
)
sch
u
duler_instance
=
Scheduler
()
sch
e
duler_instance
=
Scheduler
()
# query args 1
# query args 1
query_index
=
dict
()
query_index
=
dict
()
query_index
[
'index'
]
=
[
file_name
]
query_index
[
'index'
]
=
[
file_name
]
vectors
=
sch
u
duler_instance
.
Search
(
query_index
,
vectors
=
xq
,
k
=
5
)
vectors
=
sch
e
duler_instance
.
Search
(
query_index
,
vectors
=
xq
,
k
=
5
)
assert
np
.
all
(
vectors
==
Iref
)
assert
np
.
all
(
vectors
==
Iref
)
# query args 2
# query args 2
query_index
=
dict
()
query_index
=
dict
()
query_index
[
'raw'
]
=
xt
query_index
[
'raw'
]
=
xt
# Xiaojun TODO: 'raw_id' part
# query_index['raw_id'] =
query_index
[
'dimension'
]
=
d
query_index
[
'dimension'
]
=
d
query_index
[
'index'
]
=
[
file_name
]
query_index
[
'index'
]
=
[
file_name
]
vectors
=
schuduler_instance
.
Search
(
query_index
,
vectors
=
xq
,
k
=
5
)
# Xiaojun TODO: once 'raw_id' part added, open below
# vectors = scheduler_instance.Search(query_index, vectors=xq, k=5)
# print("success")
# print("success")
...
...
pyengine/engine/controller/tests/test_vector_engine.py
浏览文件 @
2542f67c
...
@@ -44,29 +44,34 @@ class TestVectorEngine:
...
@@ -44,29 +44,34 @@ 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
=
VectorEngine
.
AddVector
(
'not_exist_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'not_exist_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
vector_id
==
'invalid'
# Add vector for exist group
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.0'
# Add vector for exist group
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.1'
# Add vector for exist group
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
'test_group.2'
# Add vector for exist group
# Add vector for exist group
code
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
'test_group'
,
self
.
__vector
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
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
)
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
vector_id
==
0
assert
vector_id
==
{
0
}
# Check create index interface
# Check create index interface
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
...
@@ -85,8 +90,9 @@ class TestVectorEngine:
...
@@ -85,8 +90,9 @@ class TestVectorEngine:
assert
file_number
==
0
assert
file_number
==
0
# Check SearchVector interface
# Check SearchVector interface
code
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
code
,
vector_ids
=
VectorEngine
.
SearchVector
(
'test_group'
,
self
.
__vector
,
self
.
__limit
)
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
code
==
VectorEngine
.
GROUP_NOT_EXIST
assert
vector_ids
==
{}
# Create Index for not exist group id
# Create Index for not exist group id
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
code
=
VectorEngine
.
CreateIndex
(
'test_group'
)
...
@@ -97,17 +103,18 @@ class TestVectorEngine:
...
@@ -97,17 +103,18 @@ class TestVectorEngine:
assert
code
==
VectorEngine
.
SUCCESS_CODE
assert
code
==
VectorEngine
.
SUCCESS_CODE
def
test_raw_file
(
self
):
def
test_raw_file
(
self
):
filename
=
VectorEngine
.
InsertVectorIntoRawFile
(
'test_group'
,
'test_group.raw'
,
self
.
__vector
)
filename
=
VectorEngine
.
InsertVectorIntoRawFile
(
'test_group'
,
'test_group.raw'
,
self
.
__vector
,
'test_group.0'
)
assert
filename
==
'test_group.raw'
assert
filename
==
'test_group.raw'
expected_list
=
[
self
.
__vector
]
expected_list
=
[
self
.
__vector
]
vector_list
=
VectorEngine
.
GetVectorListFromRawFile
(
'test_group'
,
filename
)
vector_list
,
vector_id_list
=
VectorEngine
.
GetVectorListFromRawFile
(
'test_group'
,
filename
)
print
(
'expected_list: '
,
expected_list
)
print
(
'expected_list: '
,
expected_list
)
print
(
'vector_list: '
,
vector_list
)
print
(
'vector_list: '
,
vector_list
)
expected_list
=
np
.
asarray
(
expected_list
).
astype
(
'float32'
)
print
(
'vector_id_list: '
,
vector_id_list
)
expected_list
=
np
.
asarray
(
expected_list
).
astype
(
'float32'
)
assert
np
.
all
(
vector_list
==
expected_list
)
assert
np
.
all
(
vector_list
==
expected_list
)
code
=
VectorEngine
.
ClearRawFile
(
'test_group'
)
code
=
VectorEngine
.
ClearRawFile
(
'test_group'
)
...
...
pyengine/engine/controller/vector_engine.py
浏览文件 @
2542f67c
...
@@ -12,7 +12,8 @@ from engine.ingestion import serialize
...
@@ -12,7 +12,8 @@ from engine.ingestion import serialize
import
sys
,
os
import
sys
,
os
class
VectorEngine
(
object
):
class
VectorEngine
(
object
):
group_dict
=
None
group_vector_dict
=
None
group_vector_id_dict
=
None
SUCCESS_CODE
=
0
SUCCESS_CODE
=
0
FAULT_CODE
=
1
FAULT_CODE
=
1
GROUP_NOT_EXIST
=
2
GROUP_NOT_EXIST
=
2
...
@@ -83,23 +84,25 @@ class VectorEngine(object):
...
@@ -83,23 +84,25 @@ class VectorEngine(object):
print
(
group_id
,
vector
)
print
(
group_id
,
vector
)
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
return
VectorEngine
.
GROUP_NOT_EXIST
,
'invalid'
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
vector_id
=
group_id
+
'.'
+
(
str
)(
file
.
seq_no
+
1
)
# insert into raw file
# insert into raw file
VectorEngine
.
InsertVectorIntoRawFile
(
group_id
,
file
.
filename
,
vector
)
VectorEngine
.
InsertVectorIntoRawFile
(
group_id
,
file
.
filename
,
vector
,
vector_id
)
# check if the file can be indexed
# check if the file can be indexed
if
file
.
row_number
+
1
>=
ROW_LIMIT
:
if
file
.
row_number
+
1
>=
ROW_LIMIT
:
raw_
data
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
)
raw_
vector_array
,
raw_vector_id_array
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
)
d
=
group
.
dimension
d
=
group
.
dimension
# create index
# create index
index_builder
=
build_index
.
FactoryIndex
()
index_builder
=
build_index
.
FactoryIndex
()
index
=
index_builder
().
build
(
d
,
raw_
data
)
index
=
index_builder
().
build
(
d
,
raw_
vector_array
,
raw_vector_id_array
)
# TODO(jinhai): store index into Cache
# TODO(jinhai): store index into Cache
index_filename
=
file
.
filename
+
'_index'
index_filename
=
file
.
filename
+
'_index'
...
@@ -107,12 +110,14 @@ class VectorEngine(object):
...
@@ -107,12 +110,14 @@ class VectorEngine(object):
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
,
'type'
:
'index'
,
'type'
:
'index'
,
'filename'
:
index_filename
})
'filename'
:
index_filename
,
'seq_no'
:
file
.
seq_no
+
1
})
pass
pass
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
,
'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
pass
...
@@ -121,13 +126,15 @@ class VectorEngine(object):
...
@@ -121,13 +126,15 @@ class VectorEngine(object):
print
(
'add a new raw file'
)
print
(
'add a new raw file'
)
# first raw file
# first raw file
raw_filename
=
group_id
+
'.raw'
raw_filename
=
group_id
+
'.raw'
# create vector id
vector_id
=
group_id
+
'.'
+
(
str
)(
0
)
# create and insert vector into raw file
# create and insert vector into raw file
VectorEngine
.
InsertVectorIntoRawFile
(
group_id
,
raw_filename
,
vector
)
VectorEngine
.
InsertVectorIntoRawFile
(
group_id
,
raw_filename
,
vector
,
vector_id
)
# insert a record into database
# insert a record into database
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
()
return
VectorEngine
.
SUCCESS_CODE
return
VectorEngine
.
SUCCESS_CODE
,
vector_id
@
staticmethod
@
staticmethod
...
@@ -135,7 +142,7 @@ class VectorEngine(object):
...
@@ -135,7 +142,7 @@ class VectorEngine(object):
# Check the group exist
# Check the group exist
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
return
VectorEngine
.
GROUP_NOT_EXIST
,
{}
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
group
=
GroupTable
.
query
.
filter
(
GroupTable
.
group_name
==
group_id
).
first
()
...
@@ -144,7 +151,7 @@ class VectorEngine(object):
...
@@ -144,7 +151,7 @@ class VectorEngine(object):
index_keys
=
[
i
.
filename
for
i
in
files
if
i
.
type
==
'index'
]
index_keys
=
[
i
.
filename
for
i
in
files
if
i
.
type
==
'index'
]
index_map
=
{}
index_map
=
{}
index_map
[
'index'
]
=
index_keys
index_map
[
'index'
]
=
index_keys
index_map
[
'raw'
]
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
,
"fakename"
)
#TODO: pass by key, get from storage
index_map
[
'raw'
]
,
index_map
[
'raw_id'
]
=
VectorEngine
.
GetVectorListFromRawFile
(
group_id
,
"fakename"
)
#TODO: pass by key, get from storage
index_map
[
'dimension'
]
=
group
.
dimension
index_map
[
'dimension'
]
=
group
.
dimension
scheduler_instance
=
Scheduler
()
scheduler_instance
=
Scheduler
()
...
@@ -152,7 +159,7 @@ class VectorEngine(object):
...
@@ -152,7 +159,7 @@ 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_id
=
{
0
}
return
VectorEngine
.
SUCCESS_CODE
,
vector_id
return
VectorEngine
.
SUCCESS_CODE
,
vector_id
...
@@ -172,29 +179,37 @@ class VectorEngine(object):
...
@@ -172,29 +179,37 @@ class VectorEngine(object):
@
staticmethod
@
staticmethod
def
InsertVectorIntoRawFile
(
group_id
,
filename
,
vector
):
def
InsertVectorIntoRawFile
(
group_id
,
filename
,
vector
,
vector_id
):
# print(sys._getframe().f_code.co_name, group_id, vector)
# print(sys._getframe().f_code.co_name, group_id, vector)
# path = GroupHandler.GetGroupDirectory(group_id) + '/' + filename
# path = GroupHandler.GetGroupDirectory(group_id) + '/' + filename
if
VectorEngine
.
group_dict
is
None
:
if
VectorEngine
.
group_vector_dict
is
None
:
# print("VectorEngine.group_dict is None")
# print("VectorEngine.group_vector_dict is None")
VectorEngine
.
group_dict
=
dict
()
VectorEngine
.
group_vector_dict
=
dict
()
if
VectorEngine
.
group_vector_id_dict
is
None
:
VectorEngine
.
group_vector_id_dict
=
dict
()
if
not
(
group_id
in
VectorEngine
.
group_vector_dict
):
VectorEngine
.
group_vector_dict
[
group_id
]
=
[]
if
not
(
group_id
in
VectorEngine
.
group_dict
):
if
not
(
group_id
in
VectorEngine
.
group_
vector_id_
dict
):
VectorEngine
.
group_dict
[
group_id
]
=
[]
VectorEngine
.
group_
vector_id_
dict
[
group_id
]
=
[]
VectorEngine
.
group_dict
[
group_id
].
append
(
vector
)
VectorEngine
.
group_vector_dict
[
group_id
].
append
(
vector
)
VectorEngine
.
group_vector_id_dict
[
group_id
].
append
(
vector_id
)
print
(
'InsertVectorIntoRawFile: '
,
VectorEngine
.
group_dict
[
group_id
])
print
(
'InsertVectorIntoRawFile: '
,
VectorEngine
.
group_
vector_dict
[
group_id
],
VectorEngine
.
group_vector_id_
dict
[
group_id
])
return
filename
return
filename
@
staticmethod
@
staticmethod
def
GetVectorListFromRawFile
(
group_id
,
filename
=
"todo"
):
def
GetVectorListFromRawFile
(
group_id
,
filename
=
"todo"
):
return
serialize
.
to_array
(
VectorEngine
.
group_dict
[
group_id
])
return
serialize
.
to_array
(
VectorEngine
.
group_
vector_dict
[
group_id
]),
serialize
.
to_str_array
(
VectorEngine
.
group_vector_id_
dict
[
group_id
])
@
staticmethod
@
staticmethod
def
ClearRawFile
(
group_id
):
def
ClearRawFile
(
group_id
):
print
(
"VectorEngine.group_dict: "
,
VectorEngine
.
group_dict
)
print
(
"VectorEngine.group_vector_dict: "
,
VectorEngine
.
group_vector_dict
)
del
VectorEngine
.
group_dict
[
group_id
]
del
VectorEngine
.
group_vector_dict
[
group_id
]
del
VectorEngine
.
group_vector_id_dict
[
group_id
]
return
VectorEngine
.
SUCCESS_CODE
return
VectorEngine
.
SUCCESS_CODE
pyengine/engine/controller/views.py
浏览文件 @
2542f67c
...
@@ -18,8 +18,8 @@ class Vector(Resource):
...
@@ -18,8 +18,8 @@ class Vector(Resource):
def
post
(
self
,
group_id
):
def
post
(
self
,
group_id
):
args
=
self
.
__parser
.
parse_args
()
args
=
self
.
__parser
.
parse_args
()
vector
=
args
[
'vector'
]
vector
=
args
[
'vector'
]
code
=
VectorEngine
.
AddVector
(
group_id
,
vector
)
code
,
vector_id
=
VectorEngine
.
AddVector
(
group_id
,
vector
)
return
jsonify
({
'code'
:
code
})
return
jsonify
({
'code'
:
code
,
'vector_id'
:
vector_id
})
class
VectorSearch
(
Resource
):
class
VectorSearch
(
Resource
):
...
...
pyengine/engine/ingestion/build_index.py
浏览文件 @
2542f67c
...
@@ -15,7 +15,7 @@ def FactoryIndex(index_name="DefaultIndex"):
...
@@ -15,7 +15,7 @@ def FactoryIndex(index_name="DefaultIndex"):
class
Index
():
class
Index
():
def
build
(
self
,
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
def
build
(
self
,
d
,
vectors
,
vector_ids
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
pass
pass
@
staticmethod
@
staticmethod
...
@@ -35,7 +35,7 @@ class DefaultIndex(Index):
...
@@ -35,7 +35,7 @@ class DefaultIndex(Index):
# maybe need to specif parameters
# maybe need to specif parameters
pass
pass
def
build
(
self
,
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
def
build
(
self
,
d
,
vectors
,
vector_ids
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
index
=
faiss
.
IndexFlatL2
(
d
)
# trained
index
=
faiss
.
IndexFlatL2
(
d
)
# trained
index
.
add
(
vectors
)
index
.
add
(
vectors
)
return
index
return
index
...
@@ -47,7 +47,7 @@ class LowMemoryIndex(Index):
...
@@ -47,7 +47,7 @@ class LowMemoryIndex(Index):
self
.
__bytes_per_vector
=
8
self
.
__bytes_per_vector
=
8
self
.
__bits_per_sub_vector
=
8
self
.
__bits_per_sub_vector
=
8
def
build
(
d
,
vectors
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
def
build
(
d
,
vectors
,
vector_ids
,
DEVICE
=
INDEX_DEVICES
.
CPU
):
# quantizer = faiss.IndexFlatL2(d)
# quantizer = faiss.IndexFlatL2(d)
# index = faiss.IndexIVFPQ(quantizer, d, self.nlist,
# index = faiss.IndexIVFPQ(quantizer, d, self.nlist,
# self.__bytes_per_vector, self.__bits_per_sub_vector)
# self.__bytes_per_vector, self.__bits_per_sub_vector)
...
...
pyengine/engine/ingestion/serialize.py
浏览文件 @
2542f67c
...
@@ -9,3 +9,6 @@ def read_index(file_name):
...
@@ -9,3 +9,6 @@ def read_index(file_name):
def
to_array
(
vec
):
def
to_array
(
vec
):
return
np
.
asarray
(
vec
).
astype
(
'float32'
)
return
np
.
asarray
(
vec
).
astype
(
'float32'
)
def
to_str_array
(
vec
):
return
np
.
asarray
(
vec
).
astype
(
'str'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录