Continuum C++ API
Unified runtime for token + tensor execution
Loading...
Searching...
No Matches
memory_graph.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <mutex>
5#include <optional>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace continuum::runtime {
11
12enum class MemoryNodeType : std::uint8_t {
13 Prompt = 0,
14 Completion = 1,
15 Entity = 2,
16};
17
18struct MemoryNode {
19 std::uint64_t id = 0;
21 std::string content;
22 std::vector<float> embedding;
23 std::string session_id;
24 std::int64_t created_ns = 0;
25};
26
34 public:
35 explicit MemoryGraphStore(std::size_t max_nodes = 8192);
36
37 std::uint64_t add_node(MemoryNode node);
38 std::optional<MemoryNode> get_node(std::uint64_t id) const;
39
42 float similarity = 0.0f;
43 };
44
45 std::vector<RetrievalResult> retrieve_similar(
46 const std::vector<float>& query_embedding,
47 std::size_t max_results = 5,
48 float min_similarity = 0.7f,
49 const std::string& cache_namespace = {}) const;
50
51 void clear();
52 std::size_t size() const;
54 std::size_t max_nodes() const { return max_nodes_; }
56 std::size_t estimated_bytes() const;
57
58 private:
59 mutable std::mutex mu_;
60 std::unordered_map<std::uint64_t, MemoryNode> nodes_;
61 std::uint64_t next_id_ = 1;
62 std::size_t max_nodes_;
63};
64
65} // namespace continuum::runtime
Definition memory_graph.hpp:33
std::optional< MemoryNode > get_node(std::uint64_t id) const
std::size_t estimated_bytes() const
Approximate resident bytes: content, embeddings, ids, and per-node overhead.
MemoryGraphStore(std::size_t max_nodes=8192)
std::uint64_t add_node(MemoryNode node)
std::vector< RetrievalResult > retrieve_similar(const std::vector< float > &query_embedding, std::size_t max_results=5, float min_similarity=0.7f, const std::string &cache_namespace={}) const
std::size_t max_nodes() const
Capacity in nodes passed at construction.
Definition memory_graph.hpp:54
Definition checkpoint.hpp:12
MemoryNodeType
Definition memory_graph.hpp:12
MemoryNode node
Definition memory_graph.hpp:41
float similarity
Definition memory_graph.hpp:42
Definition memory_graph.hpp:18
MemoryNodeType type
Definition memory_graph.hpp:20
std::string session_id
Definition memory_graph.hpp:23
std::vector< float > embedding
Definition memory_graph.hpp:22
std::string content
Definition memory_graph.hpp:21
std::int64_t created_ns
Definition memory_graph.hpp:24