Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<PackageVersion Include="PdfPig" Version="0.1.13" />
<PackageVersion Include="Pinecone.Client" Version="3.1.0" />
<PackageVersion Include="Prompty.Core" Version="0.2.3-beta" />
<PackageVersion Include="Scriban" Version="6.6.0" />
<PackageVersion Include="Scriban" Version="7.0.3" />
<PackageVersion Include="PuppeteerSharp" Version="20.2.5" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.2" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ internal class MongoModelBuilder() : CollectionModelBuilder(s_validationOptions)
UsesExternalSerializer = true,
};

[RequiresUnreferencedCode("Traverses the CLR type's properties with reflection, so not compatible with trimming")]
protected override void ProcessTypeProperties(Type type, VectorStoreCollectionDefinition? definition)
protected override void ProcessProperty(PropertyInfo? clrProperty, VectorStoreProperty? definitionProperty, Type? type)
{
base.ProcessTypeProperties(type, definition);
base.ProcessProperty(clrProperty, definitionProperty, type);

foreach (var property in this.Properties)
if (clrProperty?.GetCustomAttribute<BsonElementAttribute>() is { } bsonElementAttribute
&& this.PropertyMap.TryGetValue(clrProperty.Name, out var property))
{
if (property.PropertyInfo?.GetCustomAttribute<BsonElementAttribute>() is { } bsonElementAttribute)
{
property.StorageName = bsonElementAttribute.ElementName;
}
property.StorageName = bsonElementAttribute.ElementName;
}
}

Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/VectorData/CosmosNoSql/CosmosNoSqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public JsonObject MapFromDataToStorageModel(TRecord dataModel, int recordIndex,

// The key property in Azure CosmosDB NoSQL is always named 'id'.
// But the external JSON serializer used just above isn't aware of that, and will produce a JSON object with another name, taking into
// account e.g. naming policies. TemporaryStorageName gets populated in the model builder - containing that name - once VectorStoreModelBuildingOptions.ReservedKeyPropertyName is set
RenameJsonProperty(jsonObject, this._keyProperty.TemporaryStorageName!, CosmosNoSqlConstants.ReservedKeyPropertyName);
// account e.g. naming policies. SerializedKeyName gets populated in the model builder - containing that name - once VectorStoreModelBuildingOptions.ReservedKeyPropertyName is set
RenameJsonProperty(jsonObject, this._keyProperty.SerializedKeyName!, CosmosNoSqlConstants.ReservedKeyPropertyName);

// Go over the vector properties; inject any generated embeddings to overwrite the JSON serialized above.
// Also, for Embedding<T> properties we also need to overwrite with a simple array (since Embedding<T> gets serialized as a complex object).
Expand Down Expand Up @@ -116,7 +116,7 @@ public JsonObject MapFromDataToStorageModel(TRecord dataModel, int recordIndex,
public TRecord MapFromStorageToDataModel(JsonObject storageModel, bool includeVectors)
{
// See above comment.
RenameJsonProperty(storageModel, CosmosNoSqlConstants.ReservedKeyPropertyName, this._keyProperty.TemporaryStorageName!);
RenameJsonProperty(storageModel, CosmosNoSqlConstants.ReservedKeyPropertyName, this._keyProperty.SerializedKeyName!);

foreach (var vectorProperty in this._model.VectorProperties)
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/SqliteVec/SqlitePropertyMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static List<SqliteColumn> GetColumns(IReadOnlyList<PropertyModel> propert
else
{
// The Key column in included in both Vector and Data tables.
Debug.Assert(property is KeyPropertyModel, "property is VectorStoreRecordKeyPropertyModel");
Debug.Assert(property is KeyPropertyModel, "property is not a KeyPropertyModel");

propertyType = GetStorageDataPropertyType(property);
isPrimary = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ protected override void Customize()

if (keyPropertyWithReservedName)
{
// Somewhat hacky:
// Some providers (Weaviate, Cosmos NoSQL) have a fixed, reserved storage name for keys (id), and at the same time use an external
// JSON serializer to serialize the entire user POCO. Since the serializer is unaware of the reserved storage name, it will produce
// a storage name as usual, based on the .NET property's name, possibly with a naming policy applied to it. The connector then needs
// to look that up and replace with the reserved name.
// So we store the policy-transformed name, as StorageName contains the reserved name.
property.TemporaryStorageName = storageName;
((KeyPropertyModel)property).SerializedKeyName = storageName;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Extensions.VectorData.ProviderServices;
public sealed class CollectionModel
{
private readonly Type _recordType;
private readonly IRecordCreator _recordCreator;
private readonly Func<object> _recordFactory;

private KeyPropertyModel? _singleKeyProperty;
private VectorPropertyModel? _singleVectorProperty;
Expand Down Expand Up @@ -57,14 +57,14 @@ public sealed class CollectionModel

internal CollectionModel(
Type recordType,
IRecordCreator recordCreator,
Func<object> recordFactory,
IReadOnlyList<KeyPropertyModel> keyProperties,
IReadOnlyList<DataPropertyModel> dataProperties,
IReadOnlyList<VectorPropertyModel> vectorProperties,
IReadOnlyDictionary<string, PropertyModel> propertyMap)
{
this._recordType = recordType;
this._recordCreator = recordCreator;
this._recordFactory = recordFactory;

this.KeyProperties = keyProperties;
this.DataProperties = dataProperties;
Expand Down Expand Up @@ -97,7 +97,7 @@ public TRecord CreateRecord<TRecord>()
{
Debug.Assert(typeof(TRecord) == this._recordType, "Type mismatch between record type and model type.");

return this._recordCreator.Create<TRecord>();
return (TRecord)this._recordFactory();
}

/// <summary>
Expand Down
Loading
Loading