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

92 lines
2.7 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 "hnswlib/hnswlib.h"
namespace humanus {
namespace mem0 {
struct VectorStoreConfig {
int dim = 16; // Dimension of the elements
int max_elements = 10000; // Maximum number of elements, should be known beforehand
int M = 16; // Tightly connected with internal dimensionality of the data
// strongly affects the memory consumption
int ef_construction = 200; // Controls index search speed/build speed tradeoff
enum class Metric {
L2,
IP
};
Metric metric = Metric::L2;
};
struct VectorStoreBase {
VectorStoreConfig config;
VectorStoreBase(const VectorStoreConfig& config) : config(config) {
reset();
}
virtual void reset() = 0;
/**
* @brief
* @param vectors
* @param payloads
* @param ids ID
* @return ID
*/
virtual std::vector<size_t> insert(const std::vector<std::vector<float>>& vectors,
const std::vector<std::string>& payloads = {},
const std::vector<size_t>& ids = {}) = 0;
/**
* @brief
* @param query
* @param limit
* @param filters
* @return ID
*/
std::vector<std::pair<size_t, std::vector<float>>> search(const std::vector<float>& query,
int limit = 5,
const std::string& filters = "") = 0;
/**
* @brief ID
* @param vector_id ID
*/
virtual void delete_vector(size_t vector_id) = 0;
/**
* @brief
* @param vector_id ID
* @param vector
* @param payload
*/
virtual void update(size_t vector_id,
const std::vector<float>* vector = nullptr,
const std::string* payload = nullptr) = 0;
/**
* @brief ID
* @param vector_id ID
* @return
*/
virtual std::vector<float> get(size_t vector_id) = 0;
/**
* @brief
* @param filters
* @param limit
* @return ID
*/
virtual std::vector<size_t> list(const std::string& filters = "", int limit = 0) = 0;
};
}
}
#endif // HUMANUS_MEMORY_MEM0_VECTOR_STORE_BASE_H