Skip to content

.Net: [MEVD] Allow mapping the same .NET property to both data and vector properties in the database #11734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
roji opened this issue Apr 25, 2025 · 0 comments
Labels
msft.ext.vectordata Related to Microsoft.Extensions.VectorData .NET Issue or Pull requests regarding .NET code

Comments

@roji
Copy link
Member

roji commented Apr 25, 2025

In #10492, we're adding the ability to map arbitrary properties to a data store vector property, via an IEmbeddingGenerator:

[VectorStoreRecordVector(Dimensions: 3)]
public string Description { get; set; }

The slight issue here is that currently maps Description only to a vector property; we believe there are non-contrived scenarios out there where users want to fetch back the description (as a string) when searching/getting records. We also believe some users would reasonably expect the above to just roundtrip, and would be a bit surprised when it doesn't.

Option 1 (Current): two .NET properties, one pointing to the other

The current way for users to do this is to have two properties as follows:

[VectorStoreRecordData]
public string Description { get; set; }

[VectorStoreRecordVector(Dimensions: 3)]
public string DescriptionEmbedding => Description;

Note that this also allows easily e.g. concatenating multiple string properties together for embedding generation, or any arbitrary transformation.

Option 2: single .NET property, implicitly mapped to both vector and data

One possible design would be to implicitly map the above single .NET property to two database properties for the user. That is, the single Description .NET property would be mapped to a Description data property, and also to e.g. a Description_Embedding property (via some arbitrary naming convention). We don't like this design because:

  • There's an excess of "magic" (e.g. the naming convention)
  • The data property can't be configured (to e.g. be indexed)
  • Generally because the two-property mapping is non-obvious.

If we did want to do this, we'd need to do it now, since doing it later would be a breaking change.

Option 3: single .NET property, multiple attributes

An alternative would be for the user to simply annotated the same .NET property with two attributes:

[VectorStoreRecordVector(Dimensions: 3, StorageName = "Description_Embedding")]
[VectorStoreRecordData]
public string Description { get; set; }
  • This makes it much more explicit that the same .NET property is mapped to two database properties.
  • It allows configuring each one separately, via the separate attribute (or record definition)
  • This only works in the case where a single string property that's already mapped to a single data property in the databae needs to be embedding-generated. Other scenarios, e.g. concatenating multiple properties still need to be addressed via option 1 above.

Importantly, this is something that we should be able to implement later without any breaking changes. We currently throw in model validation when the same .NET property has more than one attribute - we'd just relax that.

/cc @adamsitnik @eavanvalkenburg hopefully this captures our conversation!
/cc @westey-m @dmytrostruk

@roji roji added .NET Issue or Pull requests regarding .NET code msft.ext.vectordata Related to Microsoft.Extensions.VectorData labels Apr 25, 2025
@roji roji moved this to Backlog in Semantic Kernel Apr 25, 2025
@github-actions github-actions bot changed the title [MEVD] Allow mapping the same .NET property to both data and vector properties in the database .Net: [MEVD] Allow mapping the same .NET property to both data and vector properties in the database Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msft.ext.vectordata Related to Microsoft.Extensions.VectorData .NET Issue or Pull requests regarding .NET code
Projects
Status: Backlog
Development

No branches or pull requests

2 participants