Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24kchengYe MemoMind aggregate source fields

From Leeroopedia
Knowledge Sources
Domains Knowledge_Management, domain:Data_Processing
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for aggregating temporal fields from source memories when creating or updating observations during consolidation.

Description

The _aggregate_source_fields function computes the temporal fields inherited by an observation from its source memories. When the LLM creates or updates an observation, the observation's temporal metadata must be derived from the facts that support it.

Temporal aggregation rules:

  • event_date: earliest (min) across source memories
  • occurred_start: earliest (min) across source memories
  • occurred_end: latest (max) across source memories
  • mentioned_at: latest (max) across source memories
  • tags: defaults to the first source memory's tags (all memories in a consolidation batch share the same tag set)

Fields remain None when no source memory carries that information, so observations are never stamped with an artificial timestamp.

Usage

This is an internal helper called by the consolidation engine when processing LLM-generated create and update actions. It is not typically called directly by users.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/engine/consolidation/consolidator.py
  • Lines: L96-118

Signature

def _aggregate_source_fields(
    source_mems: list[dict[str, Any]],
    tags: list[str] | None = None,
) -> _SourceAggregation:

Import

from hindsight_api.engine.consolidation.consolidator import _aggregate_source_fields

I/O Contract

Inputs

Name Type Required Description
source_mems list[dict[str, Any]] Yes Source memory dicts with event_date, occurred_start, occurred_end, mentioned_at, tags
tags list[str] No Tags for the observation (defaults to first source memory's tags)

Outputs

Name Type Description
aggregation _SourceAggregation Dataclass with event_date (min), occurred_start (min), occurred_end (max), mentioned_at (max), tags

Usage Examples

Aggregating Temporal Fields

from hindsight_api.engine.consolidation.consolidator import _aggregate_source_fields

source_mems = [
    {"event_date": "2024-06-01", "occurred_start": "2024-06-01", "occurred_end": "2024-06-01",
     "mentioned_at": "2024-06-01", "tags": ["work"]},
    {"event_date": "2024-06-15", "occurred_start": "2024-06-15", "occurred_end": "2024-06-20",
     "mentioned_at": "2024-06-15", "tags": ["work"]},
]

agg = _aggregate_source_fields(source_mems)
# agg.event_date = "2024-06-01" (min)
# agg.occurred_start = "2024-06-01" (min)
# agg.occurred_end = "2024-06-20" (max)
# agg.mentioned_at = "2024-06-15" (max)
# agg.tags = ["work"]

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment