Skip to content

Conversation

@amihos
Copy link
Contributor

@amihos amihos commented Nov 20, 2025

Summary

  • Adds defensive weight clamping in expand_via_waypoints() and hsg_query() scoring loop
  • Protects against corrupted database waypoint records that can inflate scores
  • Fixes issue where memories with trillion-value weights dominated search results

Problem

During debugging, we discovered that some waypoint records in the database had corrupted weights (e.g., 1.4 trillion instead of the expected 0-1 range). This caused irrelevant memories to rank #1 in search results because the hybrid scoring formula:

sigmoid(0.6*sim + 0.2*tok_overlap + 0.15*waypoint_wt + 0.05*recency)

Would be dominated by the massive waypoint weight, effectively ignoring semantic similarity.

Solution

Added Math.min(1.0, Math.max(0, weight || 0)) clamping in two locations:

  1. expand_via_waypoints() - Line 523-524: Clamps neighbor weights before calculating expansion weights
  2. hsg_query() scoring loop - Line 777-778: Clamps waypoint weights before computing hybrid score

This ensures that even if the database contains invalid values, they won't corrupt query results.

Test plan

  • Query test memories with unique keywords to verify correct ranking
  • Verify that memories with high semantic similarity rank above irrelevant ones
  • Check that scores are in expected 0-1 range after sigmoid normalization

🤖 Generated with Claude Code

Database may contain waypoint records with corrupted weights (e.g., 1.4 trillion instead of expected 0-1 range). These corrupted weights cause irrelevant memories to dominate search results due to massive score inflation in the hybrid scoring formula.

This fix adds defensive clamping in two locations:
1. expand_via_waypoints() - when calculating expansion weights from neighbors
2. hsg_query() scoring loop - when using waypoint weights in final score calculation

The clamping ensures that even if database contains invalid values, they won't corrupt query results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@nullure
Copy link
Member

nullure commented Nov 20, 2025

Hey amihos, thanks for your interest in OpenMemory. I appreciate your pull request but it has failed the Build Test, please resolve the issues.

Fixed TypeScript build errors by properly adding AWS_REGION,
AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY properties to
the env configuration object. These properties were being
referenced in embed.ts but were missing from cfg.ts.

Changes:
- Removed incorrect aws_model property with 3-argument str() call
- Added AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  as individual properties with proper default values

Fixes TypeScript errors:
- cfg.ts(53,9): Expected 2 arguments, but got 3
- embed.ts: Property 'AWS_*' does not exist errors

This is the same fix applied to PRs CaviraOSS#54 and CaviraOSS#55.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Member

@nullure nullure left a comment

Choose a reason for hiding this comment

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

LGTM

@nullure nullure merged commit f61d689 into CaviraOSS:main Nov 22, 2025
1 check 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.

2 participants