in Elastic.SemanticKernel.Connectors.Elasticsearch/Internal/Helpers/VectorStoreRecordPropertyReader.cs [79:176]
public VectorStoreRecordPropertyReader(
Type dataModelType,
VectorStoreRecordDefinition? vectorStoreRecordDefinition,
VectorStoreRecordPropertyReaderOptions? options)
{
this._dataModelType = dataModelType;
this._options = options ?? new VectorStoreRecordPropertyReaderOptions();
// If a definition is provided, use it. Otherwise, create one from the type.
if (vectorStoreRecordDefinition is not null)
{
// Here we received a definition, which gives us all of the information we need.
// Some mappers though need to set properties on the data model using reflection
// so we may still need to find the PropertyInfo objects on the data model later if required.
this._vectorStoreRecordDefinition = vectorStoreRecordDefinition;
}
else
{
// Here we didn't receive a definition, so we need to derive the information from
// the data model. Since we may need the PropertyInfo objects later to read or write
// property values on the data model, we save them for later in case we need them.
var propertiesInfo = FindPropertiesInfo(dataModelType);
this._vectorStoreRecordDefinition = CreateVectorStoreRecordDefinitionFromType(propertiesInfo);
this._keyPropertiesInfo = propertiesInfo.KeyProperties;
this._dataPropertiesInfo = propertiesInfo.DataProperties;
this._vectorPropertiesInfo = propertiesInfo.VectorProperties;
}
// Verify the definition to make sure it does not have too many or too few of each property type.
(this._keyProperties, this._dataProperties, this._vectorProperties) = SplitDefinitionAndVerify(
dataModelType.Name,
this._vectorStoreRecordDefinition,
this._options.SupportsMultipleKeys,
this._options.SupportsMultipleVectors,
this._options.RequiresAtLeastOneVector);
// Setup lazy initializers.
this._storagePropertyNamesMap = new Lazy<Dictionary<string, string>>(() =>
{
return BuildPropertyNameToStorageNameMap((this._keyProperties, this._dataProperties, this._vectorProperties));
});
this._parameterlessConstructorInfo = new Lazy<ConstructorInfo>(() =>
{
var constructor = dataModelType.GetConstructor(Type.EmptyTypes);
if (constructor == null)
{
throw new ArgumentException($"Type {dataModelType.FullName} must have a parameterless constructor.");
}
return constructor;
});
this._keyPropertyStoragePropertyNames = new Lazy<List<string>>(() =>
{
var storagePropertyNames = this._storagePropertyNamesMap.Value;
return this._keyProperties.Select(x => storagePropertyNames[x.DataModelPropertyName]).ToList();
});
this._dataPropertyStoragePropertyNames = new Lazy<List<string>>(() =>
{
var storagePropertyNames = this._storagePropertyNamesMap.Value;
return this._dataProperties.Select(x => storagePropertyNames[x.DataModelPropertyName]).ToList();
});
this._vectorPropertyStoragePropertyNames = new Lazy<List<string>>(() =>
{
var storagePropertyNames = this._storagePropertyNamesMap.Value;
return this._vectorProperties.Select(x => storagePropertyNames[x.DataModelPropertyName]).ToList();
});
this._jsonPropertyNamesMap = new Lazy<Dictionary<string, string>>(() =>
{
return BuildPropertyNameToJsonPropertyNameMap(
(this._keyProperties, this._dataProperties, this._vectorProperties),
dataModelType,
this._options.JsonSerializerOptions);
});
this._keyPropertyJsonNames = new Lazy<List<string>>(() =>
{
var jsonPropertyNamesMap = this._jsonPropertyNamesMap.Value;
return this._keyProperties.Select(x => jsonPropertyNamesMap[x.DataModelPropertyName]).ToList();
});
this._dataPropertyJsonNames = new Lazy<List<string>>(() =>
{
var jsonPropertyNamesMap = this._jsonPropertyNamesMap.Value;
return this._dataProperties.Select(x => jsonPropertyNamesMap[x.DataModelPropertyName]).ToList();
});
this._vectorPropertyJsonNames = new Lazy<List<string>>(() =>
{
var jsonPropertyNamesMap = this._jsonPropertyNamesMap.Value;
return this._vectorProperties.Select(x => jsonPropertyNamesMap[x.DataModelPropertyName]).ToList();
});
}