Repository navigation
Conversation
…ebuilds a record The decoder used field.validation_alias only when it was a str and otherwise fell back to the stored field name, so an alias-only field (AliasChoices) was rejected by pydantic when InMemoryCollection.get() re-validated a stored record: upsert() succeeded and get() raised ValidationError. Pick the first usable alias.
There was a problem hiding this comment.
🟡 Changes recommended
The alias remapping can silently collapse overlapping choices and corrupt record IDs, while also breaking retrieval for models with alias validation disabled or AliasPath-based inputs.
3 open issues
What changed in this PR
This PR addresses #10230 by updating the Python vector-store default decoder to support Pydantic AliasChoices fields containing a string choice.
Changes:
- Adds a helper that selects a string validation alias when rebuilding records.
- Adds an
InMemoryCollectionround-trip regression test covering the record ID, text, and vector.
| File | Description |
|---|---|
python/packages/core/tests/core/test_vectors.py |
Adds collection round-trip coverage for an alias-only AliasChoices field. |
python/packages/core/agent_framework/_vectors.py |
Uses a validation-key helper to select aliases during Pydantic record reconstruction. |
Review effort: Balanced
| else field.alias | ||
| if isinstance(field.alias, str) | ||
| else name: value[name] | ||
| _pydantic_validation_key(name, field): value[name] |
| Pydantic accepts, so it is used unchanged. ``AliasChoices`` declares several accepted aliases and | ||
| validates on any one of them, so the first string choice is used; keying such a field by its own | ||
| name only validates when the model also allows population by name, which declaring an alias does | ||
| not require. Nested ``AliasPath`` aliases keep the previous field-name fallback. |
| else field.alias | ||
| if isinstance(field.alias, str) | ||
| else name: value[name] | ||
| _pydantic_validation_key(name, field): value[name] |
`record_id` is a validation alias, so the generated constructor only advertises `id` and pyright/mypy/pyrefly all reject the call. Validate the aliased dict instead, which is the same path the decoder takes in this test.
|
Understood — #10230 stays the link, and I'll wait for One thing fixed in the meantime: the new test constructed the record with |


Fixes #10230
Problem
_default_vector_model_decoder.decode_pydanticrebuilds the validation mapping with:An
AliasChoicesvalidation alias is not astrandfield.aliasisNonefor an alias-only field, so the stored field name is handed to pydantic - which only accepts the declared alias choices.InMemoryCollection.upsert()(and every connector using the default decoder) therefore persists a record that cannot be read back:Fix
Pick the first usable alias (
AliasChoices-> its first choice,AliasPath-> its path, plain string alias -> itself), falling back to the field name.Tests
python/packages/core/tests/core/test_vectors.py:The new test round-trips a record whose id field declares only
validation_alias=AliasChoices(...)throughInMemoryCollection.