Skip to content

fix(recall): collapse duplicate raw facts before truncation#2577

Closed
Cybercommanders wants to merge 1 commit into
vectorize-io:mainfrom
Cybercommanders:fix/recall-dedup-threshold
Closed

fix(recall): collapse duplicate raw facts before truncation#2577
Cybercommanders wants to merge 1 commit into
vectorize-io:mainfrom
Cybercommanders:fix/recall-dedup-threshold

Conversation

@Cybercommanders

Copy link
Copy Markdown

Summary

  • add configurable recall dedup threshold for near-identical raw memory facts
  • collapse duplicates after observation preference and before limit truncation
  • document HINDSIGHT_API_RECALL_DEDUP_THRESHOLD in env examples and developer config

Verification

  • uv run pytest tests/test_recall_dedup.py tests/test_recall_config.py -q
  • ./scripts/hooks/lint.sh
  • uv run ty check hindsight_api/engine/search/dedup.py hindsight_api/engine/memory_engine.py hindsight_api/config.py tests/test_recall_dedup.py tests/test_recall_config.py
  • git diff --cached --check

Copilot AI review requested due to automatic review settings July 6, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a configurable deduplication pass for internal recall results so near-identical raw world/experience facts are collapsed before truncation, improving recall diversity under tight token budgets.

Changes:

  • Introduces recall dedup helpers (normalize_recall_dedup_text, collapse_near_duplicate_raw_facts) and wires them into MemoryEngine recall flow.
  • Adds HINDSIGHT_API_RECALL_DEDUP_THRESHOLD config + validation, and documents it in env templates and developer configuration docs.
  • Adds unit tests for dedup behavior and config wiring/defaults.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
hindsight-embed/hindsight_embed/env.example Documents the new recall dedup env var in the embed template.
hindsight-docs/docs/developer/configuration.md Adds the new HINDSIGHT_API_RECALL_DEDUP_THRESHOLD entry to configuration reference docs.
hindsight-api-slim/tests/test_recall_dedup.py New unit tests covering normalization + dedup collapse behavior across thresholds and fact types.
hindsight-api-slim/tests/test_recall_config.py Extends config tests to include recall_dedup_threshold defaults, env var constant, and env parsing validation.
hindsight-api-slim/hindsight_api/engine/search/dedup.py New implementation of recall raw-fact deduplication helpers.
hindsight-api-slim/hindsight_api/engine/memory_engine.py Reads recall_dedup_threshold from resolved config and applies dedup after observation preference and before truncation/token filtering.
hindsight-api-slim/hindsight_api/config.py Adds env var constant, default, config field, validation, and env parsing for recall dedup threshold.
.env.example Documents the new recall dedup env var in the repo root env template.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +64
is_duplicate = any(
retained_text == normalized_text
or SequenceMatcher(None, retained_text, normalized_text).ratio() >= threshold
for retained_text in retained_texts
)
Comment on lines 4149 to 4152
budget_config_dict = await self._config_resolver.get_bank_config(bank_id, request_context)
thinking_budget = _resolve_thinking_budget(budget_config_dict, budget, max_tokens)
recall_dedup_threshold = float(budget_config_dict.get("recall_dedup_threshold", DEFAULT_RECALL_DEDUP_THRESHOLD))

Comment on lines +4947 to +4953
if recall_dedup_threshold > 0.0 and scored_results:
dedup_start = time.time()
from .search.dedup import collapse_near_duplicate_raw_facts

before_dedup = len(scored_results)
scored_results = collapse_near_duplicate_raw_facts(scored_results, recall_dedup_threshold)
dropped_dedup = before_dedup - len(scored_results)
@Cybercommanders Cybercommanders force-pushed the fix/recall-dedup-threshold branch from a8111fd to e23db8a Compare July 7, 2026 00:29
@Cybercommanders

Copy link
Copy Markdown
Author

Closing at maintainer/requester direction.

@Cybercommanders Cybercommanders deleted the fix/recall-dedup-threshold branch July 7, 2026 03:59
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.

2 participants