Skip to content

Conversation

@DAESA24
Copy link
Contributor

@DAESA24 DAESA24 commented Dec 4, 2025

Summary

Fixes the Dashboard AI Chat crash caused by undefined vectors passed to cosineSimilarity().

Fixes #82

Changes

  • Added null check in TextProcessor.cosineSimilarity() before accessing .length
  • Added defensive guard in MemoryClusterer.cluster() before similarity calculations

Root Cause

The computeTfIdf() function stores vectors in a Map keyed by document content. When memory content is empty or duplicated, this can result in undefined entries when iterating vectors by index.

Testing

  • Verified fix locally with 1,000+ memories
  • Chat queries now succeed without TypeError
  • Response generation completes successfully

Additional Observation

While testing the fix, we noticed that after the crash is resolved, the Chat with Memories feature generates responses that may not be semantically relevant to the user's query. For example, asking "What are the largest memories I have?" returned documentation about MCP usage rather than memory size information. This appears to be a separate issue with the retrieval/synthesis logic and is outside the scope of this fix, but we wanted to flag it for the maintainers' awareness.


🤖 Generated with Claude Code

Add null checks to prevent TypeError when TF-IDF computation
produces undefined vectors due to empty or duplicate content.

- Add null guard in cosineSimilarity() before length check
- Add defensive check in cluster() before similarity calculation

Fixes CaviraOSS#82

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

Co-Authored-By: Claude <[email protected]>
@nullure nullure merged commit 0bc2a7a into CaviraOSS:main Dec 5, 2025
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] Dashboard AI Chat crashes with TypeError in cosineSimilarity

2 participants