mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-01 00:15:30 +08:00
feat(db): add serializer
Former-commit-id: ab412bbb430e7711ddee0ad26b34f7b3b6c43582
This commit is contained in:
parent
39be106baa
commit
cf19e90af3
24
cpp/src/db/FaissSerializer.cpp
Normal file
24
cpp/src/db/FaissSerializer.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <easylogging++.h>
|
||||
#include <faiss/AutoTune.h>
|
||||
|
||||
#include "FaissSerializer.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace engine {
|
||||
|
||||
const std::string IndexType = "IDMap,Flat";
|
||||
|
||||
FaissSerializer::FaissSerializer(uint16_t dimension)
|
||||
: pIndex_(faiss::index_factory(dimension, IndexType.c_str())) {
|
||||
}
|
||||
|
||||
bool FaissSerializer::AddWithIds(long n, const float *xdata, const long *xids) {
|
||||
pIndex_->add_with_ids(n, xdata, xids);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace engine
|
||||
} // namespace vecwise
|
||||
} // namespace zilliz
|
||||
28
cpp/src/db/FaissSerializer.h
Normal file
28
cpp/src/db/FaissSerializer.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Serializer.h"
|
||||
|
||||
namespace faiss {
|
||||
class Index;
|
||||
}
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace engine {
|
||||
|
||||
class FaissSerializer : public Serializer {
|
||||
public:
|
||||
FaissSerializer(uint16_t dimension);
|
||||
virtual bool AddWithIds(long n, const float *xdata, const long *xids) override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<faiss::Index> pIndex_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace engine
|
||||
} // namespace vecwise
|
||||
} // namespace zilliz
|
||||
21
cpp/src/db/Serializer.cpp
Normal file
21
cpp/src/db/Serializer.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <easylogging++.h>
|
||||
#include "Serializer.h"
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace engine {
|
||||
|
||||
bool Serializer::AddWithIds(const std::vector<float>& vectors, const std::vector<long>& vector_ids) {
|
||||
long n1 = (long)vectors.size();
|
||||
long n2 = (long)vector_ids.size();
|
||||
if (n1 != n2) {
|
||||
LOG(ERROR) << "vectors size is not equal to the size of vector_ids: " << n1 << "!=" << n2;
|
||||
return false;
|
||||
}
|
||||
return AddWithIds(n1, vectors.data(), vector_ids.data());
|
||||
}
|
||||
|
||||
|
||||
} // namespace engine
|
||||
} // namespace vecwise
|
||||
} // namespace zilliz
|
||||
23
cpp/src/db/Serializer.h
Normal file
23
cpp/src/db/Serializer.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace engine {
|
||||
|
||||
class Serializer {
|
||||
public:
|
||||
|
||||
bool AddWithIds(const std::vector<float>& vectors,
|
||||
const std::vector<long>& vector_ids);
|
||||
|
||||
virtual bool AddWithIds(long n, const float *xdata, const long *xids) = 0;
|
||||
|
||||
virtual ~Serializer() {}
|
||||
};
|
||||
|
||||
|
||||
} // namespace engine
|
||||
} // namespace vecwise
|
||||
} // namespace zilliz
|
||||
Loading…
x
Reference in New Issue
Block a user