fix(core): prevent embedding cache collisions between distinct texts

PE
13d ago
+144-25

PR Checklist

  • The commit message follows the contribution guidelines.

Bugs / Features

  • Related issue: none; reproduced directly against current main.
  • Tests for the changes have been added.
  • Docs: no public API or configuration changes.
  • Changeset added for @voltagent/core.

What is the current behavior?

The embedding cache uses a 32-bit hash plus input length. Distinct texts such as Aa and BB share a key, so a cached embedding can be returned for the wrong input. Batch processing then treats unseen text as cached, and semantic search returns incorrect matches.

What is the new behavior?

Use the full input text as the cache key. Preserve the existing TTL and LRU behavior, including eviction of an empty-string key. Add single/batch cache regressions and public Memory semantic-search coverage.

Notes for reviewers

  • Before the fix, 9 new regression cases failed; after the fix, both affected test files pass (24 tests).
  • Core type checking, CJS/ESM/declaration builds, strict publint, and built CJS/ESM semantic-search checks pass.
  • Full-repository Biome CI passes with LF checkouts; upstream and patched versions have the same 5 existing warnings. Syncpack passes.
  • Full Core suite on Windows/Node 24.13.1: 1,405 passed, 5 failed, 2 skipped, 1 todo. Clean upstream: 1,395 passed with the exact same 5 sandbox failures. Node 24.19.0: 1,408 passed, 2 failed; both failures also reproduce on clean upstream and concern Windows sandbox command parsing/cleanup.
  • Prepared with AI assistance; all verification used offline adapters and local files.

Summary by cubic

Fixes embedding cache collisions in @voltagent/core so distinct texts can no longer return each other's cached embeddings.

  • Replaced the 32-bit hash plus input-length cache key with the full input text; TTL and LRU behavior, including eviction of an empty-string key, are unchanged.
  • Added single and batch cache regression tests plus public Memory semantic-search coverage.
  • @voltagent/core gets a patch changeset.

Summary by CodeRabbit

  • Bug Fixes
    • Embedding cache entries are now keyed by the full input text, preventing distinct messages with colliding hashes from sharing embeddings.
    • Cache expiration and least-recently-used eviction continue to work correctly, including for empty-text inputs.