Processors.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <mutex>
5#include <optional>
6#include <set>
7#include <string>
8#include <vector>
9
11
15#include "extractor/Extractor.h"
16#include "filter/Filter.h"
17
19{
20 /// all necessary classes to filter and convert an entry of the ltm to some other format(s)
22 {
23 public:
24 Processors() = default;
25
26 void configure(const nlohmann::json& config);
27
28 /**
29 * @brief Decide whether a snapshot of the given segment should be stored to LTM.
30 *
31 * Combines two mechanisms configured via the LTM `configuration` JSON:
32 * 1. Segment whitelist (`storeSegments`): if set, the snapshot is rejected unless its
33 * segment is admitted. A core segment is admitted if either its core-segment name
34 * (`"Core"`) or its provider-segment path (`"Core/Provider"`) is listed.
35 * 2. Snapshot filters: per-segment filter overrides (`segments`) are applied if present
36 * for this segment (provider path takes precedence over core), otherwise the global
37 * `snapFilters` are applied.
38 *
39 * If neither `storeSegments` nor `segmentSnapFilters` is configured, this falls back to
40 * the global snapshot filters only, reproducing the previous behavior.
41 */
42 bool acceptSnapshotForSegment(const std::string& coreSegmentName,
43 const std::string& providerSegmentName,
44 const armem::wm::EntitySnapshot& snapshot,
45 bool simulatedVersion = false);
46
47 /**
48 * @brief Whether any segment-based selection or per-segment filtering is configured.
49 *
50 * When false, callers may use the global `snapFilters` directly.
51 */
52 bool hasSegmentSelection() const;
53
54 std::map<std::string, processor::SnapshotFilter::FilterStatistics>
56
57 /**
58 * @brief resetFilterStatisticsForNewEpisode runs resetFilterStatisticsForNewEpisode on all
59 * snapshot filters
60 */
62
63 private:
64 /// Build a list of snapshot filters from a JSON config block (keyed by filter NAME).
65 std::vector<std::unique_ptr<processor::SnapshotFilter>>
66 buildSnapshotFilters(const nlohmann::json& config);
67
68 /// Whether the given segment is admitted by the `storeSegments` whitelist (or no whitelist).
69 bool isSegmentWhitelisted(const std::string& coreSegmentName,
70 const std::string& providerSegmentName) const;
71
72 public:
73 // Unique Memory Filters
74 std::vector<std::unique_ptr<processor::MemoryFilter>> memFilters;
75
76 // Unique Snapshot filters (global / default set)
77 std::vector<std::unique_ptr<processor::SnapshotFilter>> snapFilters;
78
79 /// Optional whitelist of segments to store. Absent => store all segments.
80 /// Entries are either "CoreSegment" or "CoreSegment/ProviderSegment".
81 std::optional<std::set<std::string>> storeSegments;
82
83 /// Per-segment snapshot filter overrides, keyed by "CoreSegment" or
84 /// "CoreSegment/ProviderSegment". A segment without an entry uses `snapFilters`.
85 std::map<std::string, std::vector<std::unique_ptr<processor::SnapshotFilter>>>
87
88 // Special Extractors
89 std::vector<std::unique_ptr<processor::Extractor>> extractors;
90
91 // Special Converters
92 std::vector<std::unique_ptr<processor::DataConverter>> converters;
93
94 // Default converters
97 };
98} // namespace armarx::armem::server::ltm
std::vector< std::unique_ptr< processor::SnapshotFilter > > snapFilters
Definition Processors.h:77
std::vector< std::unique_ptr< processor::Extractor > > extractors
Definition Processors.h:89
std::vector< std::unique_ptr< processor::MemoryFilter > > memFilters
Definition Processors.h:74
std::optional< std::set< std::string > > storeSegments
Optional whitelist of segments to store.
Definition Processors.h:81
void configure(const nlohmann::json &config)
std::vector< std::unique_ptr< processor::DataConverter > > converters
Definition Processors.h:92
bool acceptSnapshotForSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, const armem::wm::EntitySnapshot &snapshot, bool simulatedVersion=false)
Decide whether a snapshot of the given segment should be stored to LTM.
std::map< std::string, std::vector< std::unique_ptr< processor::SnapshotFilter > > > segmentSnapFilters
Per-segment snapshot filter overrides, keyed by "CoreSegment" or "CoreSegment/ProviderSegment".
Definition Processors.h:86
processor::converter::data::object::JsonConverter defaultObjectConverter
Definition Processors.h:95
std::map< std::string, processor::SnapshotFilter::FilterStatistics > getSnapshotFilterStatistics()
processor::converter::type::object::JsonConverter defaultTypeConverter
Definition Processors.h:96
bool hasSegmentSelection() const
Whether any segment-based selection or per-segment filtering is configured.
void resetFilterStatisticsForNewEpisode()
resetFilterStatisticsForNewEpisode runs resetFilterStatisticsForNewEpisode on all snapshot filters
Client-side working memory entity snapshot.