NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
store.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <neograph/api.h>
11#include <neograph/types.h>
12#include <string>
13#include <vector>
14#include <optional>
15#include <mutex>
16#include <map>
17#include <chrono>
18#include <tuple>
19
20namespace neograph::graph {
21
28using Namespace = std::vector<std::string>;
29
33struct StoreItem {
35 std::string key;
36 json value;
37 int64_t created_at;
38 int64_t updated_at;
39};
40
49class NEOGRAPH_API Store {
50public:
51 virtual ~Store() = default;
52
59 virtual void put(const Namespace& ns, const std::string& key, const json& value) = 0;
60
67 virtual std::optional<StoreItem> get(const Namespace& ns, const std::string& key) const = 0;
68
75 virtual std::vector<StoreItem> search(const Namespace& ns_prefix, int limit = 100) const = 0;
76
82 virtual void delete_item(const Namespace& ns, const std::string& key) = 0;
83
89 virtual std::vector<Namespace> list_namespaces(const Namespace& prefix = {}) const = 0;
90};
91
98class NEOGRAPH_API InMemoryStore : public Store {
99public:
100 void put(const Namespace& ns, const std::string& key, const json& value) override;
101 std::optional<StoreItem> get(const Namespace& ns, const std::string& key) const override;
102 std::vector<StoreItem> search(const Namespace& ns_prefix, int limit = 100) const override;
103 void delete_item(const Namespace& ns, const std::string& key) override;
104 std::vector<Namespace> list_namespaces(const Namespace& prefix = {}) const override;
105
110 size_t size() const;
111
112private:
113 static std::string make_key(const Namespace& ns, const std::string& key);
114 static std::string ns_to_string(const Namespace& ns);
115 static bool starts_with(const std::string& str, const std::string& prefix);
116
117 mutable std::mutex mutex_;
118 std::map<std::string, StoreItem> items_;
119};
120
121} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
In-memory store implementation for testing and single-process use.
Definition store.h:98
std::vector< StoreItem > search(const Namespace &ns_prefix, int limit=100) const override
Search items under a namespace prefix.
size_t size() const
Get the total number of stored items.
std::optional< StoreItem > get(const Namespace &ns, const std::string &key) const override
Retrieve a single item.
std::vector< Namespace > list_namespaces(const Namespace &prefix={}) const override
List all namespaces under a prefix.
void put(const Namespace &ns, const std::string &key, const json &value) override
Store a value (create or update).
void delete_item(const Namespace &ns, const std::string &key) override
Delete a single item.
Abstract interface for cross-thread shared memory.
Definition store.h:49
virtual void delete_item(const Namespace &ns, const std::string &key)=0
Delete a single item.
virtual void put(const Namespace &ns, const std::string &key, const json &value)=0
Store a value (create or update).
virtual std::vector< Namespace > list_namespaces(const Namespace &prefix={}) const =0
List all namespaces under a prefix.
virtual std::vector< StoreItem > search(const Namespace &ns_prefix, int limit=100) const =0
Search items under a namespace prefix.
virtual std::optional< StoreItem > get(const Namespace &ns, const std::string &key) const =0
Retrieve a single item.
std::vector< std::string > Namespace
Hierarchical namespace path for store items.
Definition store.h:28
A single item stored in the cross-thread Store.
Definition store.h:33
int64_t updated_at
Last update timestamp (Unix epoch milliseconds).
Definition store.h:38
std::string key
Item key within the namespace.
Definition store.h:35
Namespace ns
Hierarchical namespace path.
Definition store.h:34
json value
Stored JSON value.
Definition store.h:36
int64_t created_at
Creation timestamp (Unix epoch milliseconds).
Definition store.h:37
Foundation types for NeoGraph: messages, tool calls, and LLM completions.