in demo-dotnet/QuantizationAndStorageOptions/Program.cs [91:159]
SearchIndex CreateStorageIndex(string indexName, bool useFloat16, bool noStored, bool useQuantization)
{
const string vectorSearchHnswProfile = "my-vector-profile";
const string vectorSearchHnswConfig = "myHnsw";
const int modelDimensions = 3072;
SearchFieldDataType dataType;
if(useFloat16)
{
dataType = SearchFieldDataType.Collection(SearchFieldDataType.Half);
}
else
{
dataType = SearchFieldDataType.Collection(SearchFieldDataType.Single);
}
SearchIndex searchIndex = new(indexName)
{
VectorSearch = new()
{
Profiles =
{
new VectorSearchProfile(vectorSearchHnswProfile, vectorSearchHnswConfig)
{
CompressionConfigurationName = useQuantization ? "my-compression" : null
}
},
Algorithms =
{
new HnswAlgorithmConfiguration(vectorSearchHnswConfig),
}
},
SemanticSearch = new()
{
Configurations =
{
new SemanticConfiguration("semantic-config", new()
{
TitleField = new SemanticField(fieldName: "title"),
ContentFields =
{
new SemanticField(fieldName: "chunk")
},
})
},
},
Fields =
{
new SearchableField("id") { IsKey = true, IsFilterable = true, IsSortable = true },
new SearchableField("title"),
new SearchableField("chunk"),
new SearchField("embedding", dataType)
{
IsSearchable = true,
IsHidden = noStored,
IsStored = !noStored,
VectorSearchDimensions = modelDimensions,
VectorSearchProfileName = vectorSearchHnswProfile
}
},
};
if (useQuantization)
{
searchIndex.VectorSearch.Compressions.Add(new ScalarQuantizationCompressionConfiguration("my-compression"));
}
return searchIndex;
}