Skip to content

Python: Bug: Python in-memory upsert fails with a key storage_name alias #14547

Description

@fhgffy

Describe the bug

InMemoryCollection.upsert() raises VectorStoreOperationException when a dictionary or dataclass record's key field has a storage_name different from its Python field name.

The record serializer produces the storage name, but _inner_upsert() still indexes the serialized record using the Python name.

To reproduce

import asyncio

from semantic_kernel.connectors.in_memory import InMemoryCollection
from semantic_kernel.data.vector import VectorStoreCollectionDefinition, VectorStoreField


async def main():
    definition = VectorStoreCollectionDefinition(fields=[
        VectorStoreField("key", name="id", type="str", storage_name="stored_id"),
        VectorStoreField("vector", name="vector", type="float", dimensions=2),
    ])
    collection = InMemoryCollection(collection_name="example", record_type=dict, definition=definition)
    print(await collection.upsert({"id": "first", "vector": [1.0, 0.0]}))


asyncio.run(main())

On main at dcb969fbe624dc4efa462c2079831690425b98fd, this raises Error upserting record(s) into collection 'example': 'id'.

Expected behavior

The upsert returns "first", and the record can be retrieved or deleted using that key. Existing Pydantic records that serialize the Python field name should continue to work.

Platform

Python 3.12.2, Windows; Semantic Kernel Python source at the commit above.

Additional context

I can submit a small fix that reads the serialized storage key while preserving the existing logical-key serialization path, with dictionary, dataclass and Pydantic regression tests.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions