Skip to content

[GH-1146] Cap features sent to LLM during semantic ingestion update#1163

Merged
o-love merged 4 commits into
MemMachine:mainfrom
o-love:fix/1146-cap-features-per-ingestion-update
Mar 23, 2026
Merged

[GH-1146] Cap features sent to LLM during semantic ingestion update#1163
o-love merged 4 commits into
MemMachine:mainfrom
o-love:fix/1146-cap-features-per-ingestion-update

Conversation

@o-love

@o-love o-love commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Purpose of the change

Prevent LengthFinishReasonError during semantic memory background ingestion when a profile has accumulated a large number of features. The unbounded feature set was causing the LLM response to overflow its output token budget (16384 tokens), logging errors on every background pass.

Description

The get_feature_set call in the ingestion update path had no page_size limit, sending the entire feature set to llm_feature_update. After many messages (168+ in the reported case), the profile grew large enough (~8034 prompt tokens) that the LLM's structured JSON response exceeded the completion token limit.

This PR adds a configurable max_features_per_update parameter (default 50) that caps the number of existing features sent to the LLM per update call. The parameter flows through the full configuration chain:

  • SemanticMemoryConf (YAML config file) — operator-configurable
  • SemanticService.Params — service layer
  • IngestionService.Params — ingestion layer
  • get_feature_set(page_size=...) — storage query

Files changed:

  • src/memmachine/common/configuration/__init__.py — Add max_features_per_update to SemanticMemoryConf
  • src/memmachine/semantic_memory/semantic_memory.py — Thread through SemanticService.Params and into IngestionService
  • src/memmachine/common/resource_manager/semantic_manager.py — Wire YAML config value into SemanticService.Params
  • src/memmachine/semantic_memory/semantic_ingestion.py — Pass page_size to get_feature_set in the update path
  • tests/memmachine/semantic_memory/test_semantic_ingestion.py — Add test verifying the feature cap

YAML configuration:

semantic_memory:
  max_features_per_update: 50  # default; adjustable per deployment

Fixes/Closes

Fixes #1146

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

New test test_process_single_set_limits_features_sent_to_llm verifies that when 60 features exist, fewer than 60 are passed to the LLM call. Full semantic memory test suite (224 passed, 2 skipped). Ruff and ty checks pass with no new diagnostics.

Checklist

  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Screenshots/Gifs

N/A

Further comments

The default of 50 is conservative — it keeps the feature context well within typical model output limits while still providing enough profile context for meaningful updates. Operators can tune this via the YAML config if their deployment uses models with different token budgets.

@o-love o-love force-pushed the fix/1146-cap-features-per-ingestion-update branch from 74fa23c to 9bf3eb4 Compare March 3, 2026 20:20
@o-love o-love self-assigned this Mar 3, 2026
@o-love o-love force-pushed the fix/1146-cap-features-per-ingestion-update branch from 9bf3eb4 to 8bfc2e9 Compare March 3, 2026 21:04
Add configurable max_features_per_update (default 50) to prevent
LengthFinishReasonError when a large profile causes the LLM response
to overflow its output token budget.

The limit flows from SemanticMemoryConf (YAML) through SemanticService
into IngestionService, and is passed as page_size to get_feature_set
in the update path.
@o-love o-love force-pushed the fix/1146-cap-features-per-ingestion-update branch from 8bfc2e9 to 85a65b4 Compare March 3, 2026 21:08

@sscargal sscargal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI tests are failing with

FAILED packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_ingestion.py::test_process_single_set_limits_features_sent_to_llm[neo4j_semantic_storage-count_cache_episode_storage-sqlalchemy_sqlite_engine] - ModuleNotFoundError: No module named 'memmachine'

This is caused by the package refactor, so the PR needs to be updated to use the new locations and names. Thanks.

@o-love o-love requested a review from sscargal March 9, 2026 17:42
@sscargal

Copy link
Copy Markdown
Contributor

@o-love, please resolve the merge conflicts so we can proceed with the merge process. Thanks.

@sscargal sscargal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflicts need resolving.

…es-per-ingestion-update

# Conflicts:
#	packages/server/server_tests/memmachine_server/semantic_memory/test_semantic_ingestion.py
@o-love o-love requested a review from sscargal March 18, 2026 21:37
@o-love o-love merged commit f8f5a9a into MemMachine:main Mar 23, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: add semantic memory background process hit exception openai.LengthFinishReasonError

4 participants