Skip to content

feat: Phase 1 B-1 scope-aware BM25 neighbor expansion for reflection slices#3

Closed
jlin53882 wants to merge 1 commit intomasterfrom
feat/proposal-b1-neighbor-expansion
Closed

feat: Phase 1 B-1 scope-aware BM25 neighbor expansion for reflection slices#3
jlin53882 wants to merge 1 commit intomasterfrom
feat/proposal-b1-neighbor-expansion

Conversation

@jlin53882
Copy link
Copy Markdown
Owner

Summary

Implements Phase 1 B-1 from Issue CortexReach#445 (AliceLJY reviewer feedback).

Changes

  • File: src/reflection-slices.ts
  • Function: loadAgentReflectionSlicesWithBm25Expansion()

Adds a new function that performs scope-aware BM25 neighbor expansion for reflection slices:

  1. For each reflection slice entry, performs BM25 search with scopeFilter=[entry.scope] (not undefined which does global expansion)
  2. Finds topK=2 neighbors per entry
  3. Merges and deduplicates original entries with their neighbors

Config Options

  • opK: number of neighbor results per entry (default: 2)
  • minScore: minimum BM25 score threshold (default: 0.1)

Issue Reference

Testing

  • Verify BM25 expansion is scoped to each entry's own scope
  • Verify deduplication works correctly
  • Verify minScore threshold filters low-quality neighbors

Issue: CortexReach#445 (AliceLJY reviewer feedback)

Changes:
- Add loadAgentReflectionSlicesWithBm25Expansion() function to src/reflection-slices.ts
- This function performs scope-aware BM25 expansion: for each reflection slice entry,
  it does bm25Search(text, topK=2, scopeFilter=[entry.scope]) instead of global expansion
- Uses [entry.scope] instead of undefined to scope neighbors to the same scope as the original entry
- Merges and deduplicates original entries with their neighbors

Config options:
- topK: number of neighbor results per entry (default: 2)
- minScore: minimum BM25 score threshold (default: 0.1)
@jlin53882 jlin53882 closed this Apr 2, 2026
jlin53882 pushed a commit that referenced this pull request Apr 4, 2026
…CortexReach#417)

- Fix #1: buildAutoCaptureConversationKeyFromIngress — DM fallback to channelId
  (fixes pendingIngressTexts never being written for Discord DM)
- Fix #2: cumulative counting — autoCaptureSeenTextCount accumulates, not overwrites
  (fixes eligibleTexts.length always 1 for DM, extractMinMessages never satisfied)
- Fix #3: REPLACE vs APPEND — use pendingIngressTexts as-is when present
  (avoids deduplication issues from text appearing in both sources)
- Fix #5: isExplicitRememberCommand guard with lastPending fallback
  (preserves explicit remember command behavior in DM context)
- Fix #6: Math.min cap on extractMinMessages (max 100) — prevents misconfiguration
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard in message_received hook
- Smart extraction threshold now uses currentCumulativeCount (turn count)
  instead of cleanTexts.length (per-event message count)
- Debug logs updated to show cumulative count context

All 29 test suites pass. Based on official latest (5669b08).
jlin53882 pushed a commit that referenced this pull request Apr 4, 2026
…CortexReach#417)

- Fix #1: buildAutoCaptureConversationKeyFromIngress — DM fallback to channelId
  (fixes pendingIngressTexts never being written for Discord DM)
- Fix #2: cumulative counting — autoCaptureSeenTextCount accumulates, not overwrites
  (fixes eligibleTexts.length always 1 for DM, extractMinMessages never satisfied)
- Fix #3: REPLACE vs APPEND — use pendingIngressTexts as-is when present
  (avoids deduplication issues from text appearing in both sources)
- Fix #5: isExplicitRememberCommand guard with lastPending fallback
  (preserves explicit remember command behavior in DM context)
- Fix #6: Math.min cap on extractMinMessages (max 100) — prevents misconfiguration
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard in message_received hook
- Smart extraction threshold now uses currentCumulativeCount (turn count)
  instead of cleanTexts.length (per-event message count)
- Debug logs updated to show cumulative count context

All 29 test suites pass. Based on official latest (5669b08).
jlin53882 pushed a commit that referenced this pull request Apr 4, 2026
…turn counting test + changelog

- Fix #1: buildAutoCaptureConversationKeyFromIngress DM fallback
- Fix #2: currentCumulativeCount (cumulative per-event counting)
- Fix #3: REPLACE vs APPEND + cum count threshold for smart extraction
- Fix #4: remove pendingIngressTexts.delete()
- Fix #5: isExplicitRememberCommand lastPending guard
- Fix #6: Math.min extractMinMessages cap (max 100)
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard
- Add test: 2 sequential agent_end events with extractMinMessages=2
- Add changelog: Unreleased section with issue details
jlin53882 pushed a commit that referenced this pull request Apr 5, 2026
…turn counting test + changelog

- Fix #1: buildAutoCaptureConversationKeyFromIngress DM fallback
- Fix #2: currentCumulativeCount (cumulative per-event counting)
- Fix #3: REPLACE vs APPEND + cum count threshold for smart extraction
- Fix #4: remove pendingIngressTexts.delete()
- Fix #5: isExplicitRememberCommand lastPending guard
- Fix #6: Math.min extractMinMessages cap (max 100)
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard
- Add test: 2 sequential agent_end events with extractMinMessages=2
- Add changelog: Unreleased section with issue details
jlin53882 pushed a commit that referenced this pull request Apr 7, 2026
…CortexReach#417)

- Fix #1: buildAutoCaptureConversationKeyFromIngress — DM fallback to channelId
  (fixes pendingIngressTexts never being written for Discord DM)
- Fix #2: cumulative counting — autoCaptureSeenTextCount accumulates, not overwrites
  (fixes eligibleTexts.length always 1 for DM, extractMinMessages never satisfied)
- Fix #3: REPLACE vs APPEND — use pendingIngressTexts as-is when present
  (avoids deduplication issues from text appearing in both sources)
- Fix #5: isExplicitRememberCommand guard with lastPending fallback
  (preserves explicit remember command behavior in DM context)
- Fix #6: Math.min cap on extractMinMessages (max 100) — prevents misconfiguration
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard in message_received hook
- Smart extraction threshold now uses currentCumulativeCount (turn count)
  instead of cleanTexts.length (per-event message count)
- Debug logs updated to show cumulative count context

All 29 test suites pass. Based on official latest (5669b08).
jlin53882 pushed a commit that referenced this pull request Apr 7, 2026
…turn counting test + changelog

- Fix #1: buildAutoCaptureConversationKeyFromIngress DM fallback
- Fix #2: currentCumulativeCount (cumulative per-event counting)
- Fix #3: REPLACE vs APPEND + cum count threshold for smart extraction
- Fix #4: remove pendingIngressTexts.delete()
- Fix #5: isExplicitRememberCommand lastPending guard
- Fix #6: Math.min extractMinMessages cap (max 100)
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard
- Add test: 2 sequential agent_end events with extractMinMessages=2
- Add changelog: Unreleased section with issue details
jlin53882 pushed a commit that referenced this pull request Apr 8, 2026
…CortexReach#417)

- Fix #1: buildAutoCaptureConversationKeyFromIngress — DM fallback to channelId
  (fixes pendingIngressTexts never being written for Discord DM)
- Fix #2: cumulative counting — autoCaptureSeenTextCount accumulates, not overwrites
  (fixes eligibleTexts.length always 1 for DM, extractMinMessages never satisfied)
- Fix #3: REPLACE vs APPEND — use pendingIngressTexts as-is when present
  (avoids deduplication issues from text appearing in both sources)
- Fix #5: isExplicitRememberCommand guard with lastPending fallback
  (preserves explicit remember command behavior in DM context)
- Fix #6: Math.min cap on extractMinMessages (max 100) — prevents misconfiguration
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard in message_received hook
- Smart extraction threshold now uses currentCumulativeCount (turn count)
  instead of cleanTexts.length (per-event message count)
- Debug logs updated to show cumulative count context

All 29 test suites pass. Based on official latest (5669b08).
jlin53882 pushed a commit that referenced this pull request Apr 8, 2026
…turn counting test + changelog

- Fix #1: buildAutoCaptureConversationKeyFromIngress DM fallback
- Fix #2: currentCumulativeCount (cumulative per-event counting)
- Fix #3: REPLACE vs APPEND + cum count threshold for smart extraction
- Fix #4: remove pendingIngressTexts.delete()
- Fix #5: isExplicitRememberCommand lastPending guard
- Fix #6: Math.min extractMinMessages cap (max 100)
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard
- Add test: 2 sequential agent_end events with extractMinMessages=2
- Add changelog: Unreleased section with issue details
jlin53882 pushed a commit that referenced this pull request Apr 9, 2026
…CortexReach#417)

- Fix #1: buildAutoCaptureConversationKeyFromIngress — DM fallback to channelId
  (fixes pendingIngressTexts never being written for Discord DM)
- Fix #2: cumulative counting — autoCaptureSeenTextCount accumulates, not overwrites
  (fixes eligibleTexts.length always 1 for DM, extractMinMessages never satisfied)
- Fix #3: REPLACE vs APPEND — use pendingIngressTexts as-is when present
  (avoids deduplication issues from text appearing in both sources)
- Fix #5: isExplicitRememberCommand guard with lastPending fallback
  (preserves explicit remember command behavior in DM context)
- Fix #6: Math.min cap on extractMinMessages (max 100) — prevents misconfiguration
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard in message_received hook
- Smart extraction threshold now uses currentCumulativeCount (turn count)
  instead of cleanTexts.length (per-event message count)
- Debug logs updated to show cumulative count context

All 29 test suites pass. Based on official latest (5669b08).
jlin53882 pushed a commit that referenced this pull request Apr 9, 2026
…turn counting test + changelog

- Fix #1: buildAutoCaptureConversationKeyFromIngress DM fallback
- Fix #2: currentCumulativeCount (cumulative per-event counting)
- Fix #3: REPLACE vs APPEND + cum count threshold for smart extraction
- Fix #4: remove pendingIngressTexts.delete()
- Fix #5: isExplicitRememberCommand lastPending guard
- Fix #6: Math.min extractMinMessages cap (max 100)
- Fix #7: MAX_MESSAGE_LENGTH=5000 guard
- Add test: 2 sequential agent_end events with extractMinMessages=2
- Add changelog: Unreleased section with issue details
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.

[RFC] Proposal A & B Implementation Analysis

2 participants