fix: embedding cache migration preserves the legacy document version
Description
BasicEmbeddingCache._document_loader() migrates 0.1.0 cache documents to the current shape by adding creation_utc, but it copies d[version] into the migrated document. The result therefore still reports version 0.1.0 even though BasicEmbeddingCache.VERSION is 0.2.0.
This leaves collection documents out of sync with the store metadata. Persistent database adapters treat the loader output as migrated and rewrite it, but the next startup sees the same legacy version and repeats the migration/rewrite.
Reproduction
from typing import cast
from parlant.adapters.db.transient import TransientDocumentDatabase
from parlant.core.common import Version
from parlant.core.nlp.embedding import BasicEmbeddingCache
from parlant.core.persistence.common import ObjectId
from parlant.core.persistence.document_database import BaseDocument
cache = BasicEmbeddingCache(TransientDocumentDatabase())
document = cast(
BaseDocument,
{
id: ObjectId(cache-entry),
version: Version.String(0.1.0),
vectors: [[1.0, 2.0]],
},
)
migrated = await cache._document_loader(document)
assert migrated
assert migrated[version] == cache.VERSION.to_string()On current develop (ea737442), the final assertion fails with 0.1.0 != 0.2.0.
Expected behavior
A successfully migrated cache document should be stamped with BasicEmbeddingCache.VERSION, consistent with the other document migrations.
Proposed fix
Set the migrated document's version to self.VERSION.to_string() and add a focused regression test.
Verification
The regression fails before the one-line fix and passes afterward. Ruff and format checks pass on the changed files.
Disclosure: I used AI assistance to help audit and prepare this report. I reviewed and reproduced the behavior locally.
Source: emcie-co/parlant