37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
#ifndef HUMANUS_MEMORY_MEM0_VECTOR_STORE_HNSWLIB_H
|
|
#define HUMANUS_MEMORY_MEM0_VECTOR_STORE_HNSWLIB_H
|
|
|
|
#include "base.h"
|
|
#include "hnswlib/hnswlib.h"
|
|
|
|
namespace humanus::mem0 {
|
|
|
|
class HNSWLibVectorStore : public VectorStore {
|
|
private:
|
|
std::shared_ptr<hnswlib::HierarchicalNSW<float>> hnsw;
|
|
std::shared_ptr<hnswlib::SpaceInterface<float>> space; // 保持space对象的引用以确保其生命周期
|
|
std::unordered_map<size_t, json> metadata_store; // 存储向量的元数据
|
|
|
|
public:
|
|
HNSWLibVectorStore(const std::shared_ptr<VectorStoreConfig>& config) : VectorStore(config) {
|
|
reset();
|
|
}
|
|
|
|
void reset() override;
|
|
|
|
void insert(const std::vector<float>& vector, const size_t vector_id, const json& metadata) override;
|
|
|
|
std::vector<MemoryItem> search(const std::vector<float>& query, int limit, const std::string& filters) override;
|
|
|
|
void delete_vector(size_t vector_id) override;
|
|
|
|
void update(size_t vector_id, const std::vector<float> vector, const json& metadata) override;
|
|
|
|
MemoryItem get(size_t vector_id) override;
|
|
|
|
std::vector<MemoryItem> list(const std::string& filters, int limit) override;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // HUMANUS_MEMORY_MEM0_VECTOR_STORE_HNSWLIB_H
|