Skip to content

Python: [Bug]: AliasChoices vector records fail to round-trip through InMemoryCollection #10230

Description

@FOWEPJF255

Observed Behavior

A valid Pydantic vector record using Field(validation_alias=AliasChoices("record_id", "document_id")) is accepted by model construction and InMemoryCollection.upsert(), but reading the returned key raises a missing-field ValidationError for record_id.

The default vector-model decoder builds its validation mapping with logical field names when the validation alias is not a string. Pydantic rejects the resulting id input for this alias-only field.

Expected Behavior

A record accepted by the default vector model and successfully upserted should round-trip through get(). If this alias shape is intentionally unsupported, rejection at registration would make the contract explicit instead of failing after a successful write. Please confirm the intended AliasChoices support boundary and preferred direction before implementation.

Steps to Reproduce

  1. Install core from main 098214127152b3bf26159c3e17ac0a019aa025b6 in an isolated environment.
  2. Run the following offline script. No model, credentials, embeddings service or database server is used.
  3. Observe successful upsert followed by a missing-field validation error.

Minimal Reproduction

import asyncio
from typing import Annotated
from pydantic import AliasChoices, BaseModel, Field
from agent_framework import InMemoryCollection, VectorStoreField, vectorstoremodel

@vectorstoremodel(collection_name="alias-choice-repro")
class Record(BaseModel):
    id: Annotated[str, VectorStoreField("key")] = Field(
        validation_alias=AliasChoices("record_id", "document_id")
    )
    text: Annotated[str, VectorStoreField("data")]
    vector: Annotated[list[float], VectorStoreField("vector", dimensions=2)] = Field(default_factory=list)

async def main():
    collection = InMemoryCollection(Record)
    await collection.ensure_collection_exists()
    record = Record(record_id="one", text="plain sample", vector=[0.25, 0.75])
    keys = await collection.upsert([record], generate_vectors=False)
    print("upsert:", keys)
    try:
        print("get:", await collection.get(keys, include_vectors=True))
    except Exception as error:
        print(type(error).__name__ + ":", error)

asyncio.run(main())

Error Messages and Stack Traces

upsert: ['one']
ValidationError: 1 validation error for Record
record_id
  Field required [type=missing, input_value={'id': 'one', ...}, input_type=dict]

Package Versions

agent-framework-core 1.25.0, installed editable from the exact source above; Pydantic 2.14.3; msgspec 0.22.0.

Python Version

Python 3.14.3

Operating System

Windows

Regression

Unknown.

Additional Context

Controls using a dataclass and a Pydantic string alias both round-trip with the same fields, data, source and environment. The AliasChoices case fails through public CRUD, without invoking the decoder directly.

The same offline reproduction and both controls were rerun on current main e59c25956063af1d2dde1df66415957d4938b3de with the same results. _vectors.py is unchanged between the initial revision and this recheck.

All-state issue and PR searches for AliasChoices and vector/validation_alias found no matching vector decoder report or implementation. Related PR #9250 changes nested registered-value restoration in _sessions.py only; Milvus PR #9346 adds a connector and does not change the core vector decoder. Existing issues #9060 (native UUID lookup/delete keys), #8625 (null auto-generated keys in upsert tools), and #1188 (vector connector roadmap) concern different behavior.

This report requests agreement on the problem and direction. No framework implementation or fix PR has been prepared. Any proposed support must preserve the declared Pydantic dependency range.

AI assistance: a coding assistant prepared and executed the offline reproductions and source analysis. The human submitter has personally verified the reported behavior and confirmed the authenticity of the reproduction details.

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 10, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Nov 10, 2026
  3. github-actions commented on Nov 10, 2026

    @github-actions
    Contributor

    Reproduced on current main (e59c259) using an independently written offline script based on the described behavior: upsert returns ['one'], then get() raises ValidationError ... record_id Field required. The decoder in python/packages/core/agent_framework/_vectors.py (~L580) only uses string aliases, so an AliasChoices field is fed the logical name id.

    Support boundary: unclear. I found no maintained doc or decision record covering AliasChoices on vector models, so whether to support it or reject it at registration is a maintainer decision. This does not imply acceptance or priority.

    Run: https://github.com/microsoft/agent-framework/actions/runs/42821678220

    Generated by Issue Routing for #10230 · copilot · auto · ~19 AIC · ⌖ ~1 AIC · ⊞ 5.4K · ◷

  4. eavanvalkenburg commented on Nov 11, 2026

    @eavanvalkenburg
    Member

    I'm a bit unsure of the scenario here, we already support a storage_name in case you want to have different names in the model and the storage, so you could do:

    @vectorstoremodel(collection_name="alias-choice-repro")
    class Record(BaseModel):
        record_id: Annotated[str, VectorStoreField("key", storage_name="id")] = Field(
            validation_alias=AliasChoices("document_id")
        )
        text: Annotated[str, VectorStoreField("data")]
        vector: Annotated[list[float], VectorStoreField("vector", dimensions=2)] = Field(default_factory=list)

    which should work, will that not give you the same?

  5. FOWEPJF255 commented on Nov 12, 2026

    @FOWEPJF255
    ContributorAuthor

    Thanks for the example. The scenario is accepting multiple external payload names for the same Pydantic field, rather than choosing a different database column name. For example, both record_id and document_id payloads construct the original model successfully; the failure happens when decoding the stored record.

    Rechecking on main b230c8c5e2d8e206c4f293d16b7ba771e584470a, the proposed model with record_id, storage_name="id", and validation_alias=AliasChoices("document_id") still fails at get(). Construction and upsert succeed, but validation requires document_id while the decoder supplies record_id.

    Using the Record class from your comment:

    async def main():
        collection = InMemoryCollection(Record)
        await collection.ensure_collection_exists()
        record = Record(document_id="one", text="plain sample", vector=[0.25, 0.75])
        keys = await collection.upsert([record], generate_vectors=False)
        print(keys)  # ['one']
        await collection.get(keys, include_vectors=True)  # ValidationError: document_id is required

    The offline comparisons were:

    Model configuration Construct / upsert Get
    record_id with storage_name="id", no validation alias Pass Pass
    Same field/storage names, string validation_alias="document_id" Pass Pass
    Your example with AliasChoices("document_id") Pass Missing document_id
    Original AliasChoices("record_id", "document_id"), either accepted input name Pass Missing record_id

    The environment was Windows, Python 3.14.3, Pydantic 2.14.3, and msgspec 0.22.0, using the existing editable core installation with source updated to that exact main revision. No embedding generation, external database, or model service was involved.

    Could you confirm whether this alias shape should round-trip, or whether unsupported alias shapes should instead be rejected when registering the vector model? That would establish the intended contract before a fix is prepared.

    AI assistance: a coding assistant prepared and executed these additional offline comparisons and helped draft this reply.

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

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowtriageUsage: [Issues], Target: All issues that still need to be triaged

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions