humanus.cpp/memory/mem0/vector_store/base.h

84 lines
2.5 KiB
C
Raw Normal View History

2025-03-23 14:35:54 +08:00
#ifndef HUMANUS_MEMORY_MEM0_VECTOR_STORE_BASE_H
#define HUMANUS_MEMORY_MEM0_VECTOR_STORE_BASE_H
#include "config.h"
#include <memory>
#include <unordered_map>
#include <string>
namespace humanus::mem0 {
class VectorStore {
private:
static std::unordered_map<std::string, std::shared_ptr<VectorStore>> instances_;
protected:
std::shared_ptr<VectorStoreConfig> config_;
2025-03-23 14:35:54 +08:00
// Constructor
VectorStore(const std::shared_ptr<VectorStoreConfig>& config) : config_(config) {}
2025-03-23 14:35:54 +08:00
public:
// Get the singleton instance
static std::shared_ptr<VectorStore> get_instance(const std::string& config_name = "default", const std::shared_ptr<VectorStoreConfig>& config = nullptr);
2025-03-23 14:35:54 +08:00
virtual ~VectorStore() = default;
virtual void reset() = 0;
2025-03-23 14:35:54 +08:00
/**
* @brief
* @param vector
* @param vector_id ID
2025-03-26 19:28:02 +08:00
* @param metadata
2025-03-23 14:35:54 +08:00
*/
virtual void insert(const std::vector<float>& vector,
const size_t vector_id,
2025-03-26 19:28:02 +08:00
const MemoryItem& metadata) = 0;
2025-03-23 14:35:54 +08:00
/**
* @brief
* @param query
* @param limit
2025-03-26 19:28:02 +08:00
* @param filter
* @return MemoryItem
2025-03-23 14:35:54 +08:00
*/
virtual std::vector<MemoryItem> search(const std::vector<float>& query,
2025-03-26 19:28:02 +08:00
size_t limit = 5,
const FilterFunc& filter = nullptr) = 0;
2025-03-23 14:35:54 +08:00
/**
* @brief ID
* @param vector_id ID
*/
virtual void delete_vector(size_t vector_id) = 0;
/**
* @brief
* @param vector_id ID
2025-03-26 19:28:02 +08:00
* @param vector
* @param metadata
2025-03-23 14:35:54 +08:00
*/
2025-03-26 19:28:02 +08:00
virtual void update(size_t vector_id, const std::vector<float>& vector = std::vector<float>(), const MemoryItem& metadata = MemoryItem()) = 0;
2025-03-23 14:35:54 +08:00
/**
* @brief ID
* @param vector_id ID
* @return
*/
virtual MemoryItem get(size_t vector_id) = 0;
2025-03-23 14:35:54 +08:00
/**
* @brief
* @param limit
2025-03-26 19:28:02 +08:00
* @param filter isIDAllowed
2025-03-23 14:35:54 +08:00
* @return ID
*/
2025-03-26 19:28:02 +08:00
virtual std::vector<MemoryItem> list(size_t limit = 0, const FilterFunc& filter = nullptr) = 0;
2025-03-23 14:35:54 +08:00
};
} // namespace humanus::mem0
2025-03-23 14:35:54 +08:00
#endif // HUMANUS_MEMORY_MEM0_VECTOR_STORE_BASE_H