Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
4cc5b8d5
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,发现更多精彩内容 >>
提交
4cc5b8d5
编写于
4月 30, 2019
作者:
X
Xu Peng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(db): replace faiss with execution engine
Former-commit-id: 7e7949541e39bc18f30c5aafa7968fdacf709719
上级
a724141e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
12 deletion
+29
-12
cpp/src/db/DBImpl.cpp
cpp/src/db/DBImpl.cpp
+8
-12
cpp/src/db/ExecutionEngine.h
cpp/src/db/ExecutionEngine.h
+2
-0
cpp/src/db/FaissExecutionEngine.cpp
cpp/src/db/FaissExecutionEngine.cpp
+17
-0
cpp/src/db/FaissExecutionEngine.h
cpp/src/db/FaissExecutionEngine.h
+2
-0
未找到文件。
cpp/src/db/DBImpl.cpp
浏览文件 @
4cc5b8d5
...
...
@@ -11,9 +11,11 @@
#include <easylogging++.h>
#include <wrapper/IndexBuilder.h>
#include <cache/CpuCacheMgr.h>
#include "DBImpl.h"
#include "DBMetaImpl.h"
#include "Env.h"
#include "FaissExecutionEngine.h"
namespace
zilliz
{
namespace
vecwise
{
...
...
@@ -220,30 +222,25 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date,
return
status
;
}
std
::
shared_ptr
<
faiss
::
Index
>
index
(
faiss
::
index_factory
(
group_file
.
dimension
,
"IDMap,Flat"
));
std
::
shared_ptr
<
ExecutionEngine
>
execution_engine
(
new
FaissExecutionEngine
(
group_file
.
dimension
,
group_file
.
location
));
meta
::
GroupFilesSchema
updated
;
long
index_size
=
0
;
for
(
auto
&
file
:
files
)
{
auto
to_merge
=
zilliz
::
vecwise
::
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
file
.
location
);
if
(
!
to_merge
)
{
to_merge
=
read_index
(
file
.
location
);
}
auto
file_index
=
dynamic_cast
<
faiss
::
IndexIDMap
*>
(
to_merge
->
data
().
get
());
index
->
add_with_ids
(
file_index
->
ntotal
,
dynamic_cast
<
faiss
::
IndexFlat
*>
(
file_index
->
index
)
->
xb
.
data
(),
file_index
->
id_map
.
data
());
execution_engine
->
Merge
(
file
.
location
);
auto
file_schema
=
file
;
file_schema
.
file_type
=
meta
::
GroupFileSchema
::
TO_DELETE
;
updated
.
push_back
(
file_schema
);
/* LOG(DEBUG) << "About to merge file " << file_schema.file_id << */
/* " of size=" << file_schema.rows; */
index_size
=
group_file
.
dimension
*
index
->
ntotal
;
index_size
=
execution_engine
->
Size
()
;
if
(
index_size
>=
_options
.
index_trigger_size
)
break
;
}
faiss
::
write_index
(
index
.
get
(),
group_file
.
location
.
c_str
()
);
execution_engine
->
Serialize
(
);
if
(
index_size
>=
_options
.
index_trigger_size
)
{
group_file
.
file_type
=
meta
::
GroupFileSchema
::
TO_INDEX
;
...
...
@@ -256,8 +253,7 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date,
/* LOG(DEBUG) << "New merged file " << group_file.file_id << */
/* " of size=" << group_file.rows; */
zilliz
::
vecwise
::
cache
::
CpuCacheMgr
::
GetInstance
()
->
InsertItem
(
group_file
.
location
,
std
::
make_shared
<
Index
>
(
index
));
execution_engine
->
Cache
();
return
status
;
}
...
...
cpp/src/db/ExecutionEngine.h
浏览文件 @
4cc5b8d5
...
...
@@ -22,6 +22,8 @@ public:
virtual
Status
Serialize
()
=
0
;
virtual
Status
Merge
(
const
std
::
string
&
location
)
=
0
;
virtual
Status
Cache
()
=
0
;
virtual
~
ExecutionEngine
()
{}
...
...
cpp/src/db/FaissExecutionEngine.cpp
浏览文件 @
4cc5b8d5
#include <easylogging++.h>
#include <faiss/AutoTune.h>
#include <faiss/MetaIndexes.h>
#include <faiss/IndexFlat.h>
#include <faiss/index_io.h>
#include <wrapper/Index.h>
#include <cache/CpuCacheMgr.h>
...
...
@@ -34,6 +37,20 @@ Status FaissExecutionEngine::Serialize() {
return
Status
::
OK
();
}
Status
FaissExecutionEngine
::
Merge
(
const
std
::
string
&
location
)
{
if
(
location
==
location_
)
{
return
Status
::
Error
(
"Cannot Merge Self"
);
}
auto
to_merge
=
zilliz
::
vecwise
::
cache
::
CpuCacheMgr
::
GetInstance
()
->
GetIndex
(
location
);
if
(
!
to_merge
)
{
to_merge
=
read_index
(
location
);
}
auto
file_index
=
dynamic_cast
<
faiss
::
IndexIDMap
*>
(
to_merge
->
data
().
get
());
pIndex_
->
add_with_ids
(
file_index
->
ntotal
,
dynamic_cast
<
faiss
::
IndexFlat
*>
(
file_index
->
index
)
->
xb
.
data
(),
file_index
->
id_map
.
data
());
return
Status
::
OK
();
}
Status
FaissExecutionEngine
::
Cache
()
{
zilliz
::
vecwise
::
cache
::
CpuCacheMgr
::
GetInstance
(
)
->
InsertItem
(
location_
,
std
::
make_shared
<
Index
>
(
pIndex_
));
...
...
cpp/src/db/FaissExecutionEngine.h
浏览文件 @
4cc5b8d5
...
...
@@ -22,6 +22,8 @@ public:
virtual
size_t
Size
()
const
override
;
virtual
Status
Merge
(
const
std
::
string
&
location
)
override
;
virtual
Status
Serialize
()
override
;
virtual
Status
Cache
()
override
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录