expand_context is silently ignored by the event backend's REST search path · Issue #1540 · MemMachine/MemMachine · GitHub
Skip to content

expand_context is silently ignored by the event backend's REST search path #1540

Description

@edwinyyyu

Summary

On the event backend, the expand_context parameter of POST /api/v2/memories/search has no effect on the response in the default (reranker-less) configuration. The expansion work is performed and then discarded.

Evidence

Responses are byte-identical for expand_context: 0 and expand_context: 5 against a live server (event backend, reranker: null, 2k-episode project) — verified by direct comparison of parsed response bodies.

Mechanism

expand_context threads correctly all the way down: spec → MemMachine.query_searchLongTermMemory._search_scored_eventEventMemory.query, which fetches up to N timeline-neighbor segments per seed (a LATERAL query per direction), decodes and materializes all of them into ScoredSegmentContext.segments.

The only consumer of those contexts is LongTermMemory._search_scored_event, which reads exactly one segment per context (the seed, located by seed_segment_uuid) and exactly one property of it (_episode_uid), plus the score. The neighbor segments are never referenced. The response schema (EpisodicSearchResult) also has no field that could carry context.

So on this path the parameter's entire effect is extra Postgres work and materialization per request.

Where it is not inert: with a reranker configured, the windows feed the reranker's candidate texts, so expand_context does change scoring there; and library callers of EventMemory.query receive the windows directly.

Expected behavior

The declarative backend treats matched episodes as nuclei, attaches timeline-neighbor episodes as context, and folds them into the returned list with a fill-to-limit algorithm (DeclarativeMemory._unify_scored_anchored_episode_contexts): contexts of the best matches are included whole while they fit, then filled by index-proximity to the nucleus until max_num_episodes is reached.

The event backend should do the equivalent: derive the neighbor episodes from the expanded segment windows (each segment carries its _episode_uid) and unify them into the returned episodes the same way, so expand_context returns surrounding context episodes as the parameter implies.

Environment

Observed at current main (231ce17); the consuming code is packages/server/src/memmachine_server/episodic_memory/long_term_memory/long_term_memory.py (_search_scored_event).


🤖 Written by Claude Code (Opus 5) on behalf of @edwinyyyu.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions