Skip to content

.Net: Rename hybrid search and expect single vector property. #10789

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ public async Task VectorizedSearchThrowsExceptionWithInvalidVectorTypeAsync(obje
}

[Theory]
[InlineData(null, "TestEmbedding1", 1, 1)]
[InlineData("", "TestEmbedding1", 2, 2)]
[InlineData("TestEmbedding1", "TestEmbedding1", 3, 3)]
[InlineData("TestEmbedding2", "test_embedding_2", 4, 4)]
public async Task VectorizedSearchUsesValidQueryAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.SemanticKernel.Connectors.AzureAISearch;
public sealed class AzureAISearchVectorStoreRecordCollection<TRecord> :
IVectorStoreRecordCollection<string, TRecord>,
IVectorizableTextSearch<TRecord>,
IKeywordVectorizedHybridSearch<TRecord>
IKeywordHybridSearch<TRecord>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>The name of this database for telemetry purposes.</summary>
Expand Down Expand Up @@ -72,7 +72,7 @@ public sealed class AzureAISearchVectorStoreRecordCollection<TRecord> :
private static readonly VectorData.VectorSearchOptions s_defaultVectorSearchOptions = new();

/// <summary>The default options for hybrid vector search.</summary>
private static readonly KeywordVectorizedHybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();
private static readonly HybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();

/// <summary>Azure AI Search client that can be used to manage the list of indices in an Azure AI Search Service.</summary>
private readonly SearchIndexClient _searchIndexClient;
Expand Down Expand Up @@ -326,7 +326,7 @@ public Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(TVector

// Resolve options.
var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);
var vectorPropertyName = this._propertyReader.GetJsonPropertyName(vectorProperty!.DataModelPropertyName);

// Configure search settings.
Expand Down Expand Up @@ -367,7 +367,7 @@ public Task<VectorSearchResults<TRecord>> VectorizableTextSearchAsync(string sea

// Resolve options.
var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);
var vectorPropertyName = this._propertyReader.GetJsonPropertyName(vectorProperty!.DataModelPropertyName);

// Configure search settings.
Expand Down Expand Up @@ -397,16 +397,16 @@ public Task<VectorSearchResults<TRecord>> VectorizableTextSearchAsync(string sea
}

/// <inheritdoc />
public Task<VectorSearchResults<TRecord>> KeywordVectorizedHybridSearch<TVector>(TVector vector, ICollection<string> keywords, KeywordVectorizedHybridSearchOptions? options = null, CancellationToken cancellationToken = default)
public Task<VectorSearchResults<TRecord>> HybridSearchAsync<TVector>(TVector vector, ICollection<string> keywords, HybridSearchOptions? options = null, CancellationToken cancellationToken = default)
{
Verify.NotNull(keywords);
var floatVector = VerifyVectorParam(vector);

// Resolve options.
var internalOptions = options ?? s_defaultKeywordVectorizedHybridSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);
var vectorPropertyName = this._propertyReader.GetJsonPropertyName(vectorProperty.DataModelPropertyName);
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(internalOptions.FullTextPropertyName);
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(internalOptions.AdditionalPropertyName);
var textDataPropertyName = this._propertyReader.GetJsonPropertyName(textDataProperty.DataModelPropertyName);

// Configure search settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
};

var searchOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);
var vectorPropertyName = this._storagePropertyNames[vectorProperty.DataModelPropertyName];

var filter = AzureCosmosDBMongoDBVectorStoreCollectionSearchMapping.BuildFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL;
public sealed class AzureCosmosDBNoSQLVectorStoreRecordCollection<TRecord> :
IVectorStoreRecordCollection<string, TRecord>,
IVectorStoreRecordCollection<AzureCosmosDBNoSQLCompositeKey, TRecord>,
IKeywordVectorizedHybridSearch<TRecord>
IKeywordHybridSearch<TRecord>
#pragma warning restore CA1711 // Identifiers should not have incorrect
{
/// <summary>The name of this database for telemetry purposes.</summary>
Expand Down Expand Up @@ -73,7 +73,7 @@ public sealed class AzureCosmosDBNoSQLVectorStoreRecordCollection<TRecord> :
private static readonly VectorSearchOptions s_defaultVectorSearchOptions = new();

/// <summary>The default options for hybrid vector search.</summary>
private static readonly KeywordVectorizedHybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();
private static readonly HybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();

/// <summary><see cref="Database"/> that can be used to manage the collections in Azure CosmosDB NoSQL.</summary>
private readonly Database _database;
Expand Down Expand Up @@ -372,7 +372,7 @@ public Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
this.VerifyVectorType(vector);

var searchOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);
var vectorPropertyName = this._storagePropertyNames[vectorProperty.DataModelPropertyName];

var fields = new List<string>(searchOptions.IncludeVectors ? this._storagePropertyNames.Values : this._nonVectorStoragePropertyNames);
Expand Down Expand Up @@ -400,18 +400,18 @@ public Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
}

/// <inheritdoc />
public Task<VectorSearchResults<TRecord>> KeywordVectorizedHybridSearch<TVector>(TVector vector, ICollection<string> keywords, KeywordVectorizedHybridSearchOptions? options = null, CancellationToken cancellationToken = default)
public Task<VectorSearchResults<TRecord>> HybridSearchAsync<TVector>(TVector vector, ICollection<string> keywords, HybridSearchOptions? options = null, CancellationToken cancellationToken = default)
{
const string OperationName = "VectorizedSearch";
const string ScorePropertyName = "SimilarityScore";

this.VerifyVectorType(vector);

var searchOptions = options ?? s_defaultKeywordVectorizedHybridSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);
var vectorPropertyName = this._storagePropertyNames[vectorProperty.DataModelPropertyName];

var textProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(searchOptions.FullTextPropertyName);
var textProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(searchOptions.AdditionalPropertyName);
var textPropertyName = this._storagePropertyNames[textProperty.DataModelPropertyName];

var fields = new List<string>(searchOptions.IncludeVectors ? this._storagePropertyNames.Values : this._nonVectorStoragePropertyNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T

// Resolve options and get requested vector property or first as default.
var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);

// Filter records using the provided filter before doing the vector comparison.
var filteredRecords = InMemoryVectorStoreCollectionSearchMapping.FilterRecords(internalOptions.Filter, this.GetCollectionDictionary().Values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.SemanticKernel.Connectors.MongoDB;
/// </summary>
/// <typeparam name="TRecord">The data model to use for adding, updating and retrieving data from storage.</typeparam>
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public sealed class MongoDBVectorStoreRecordCollection<TRecord> : IVectorStoreRecordCollection<string, TRecord>, IKeywordVectorizedHybridSearch<TRecord>
public sealed class MongoDBVectorStoreRecordCollection<TRecord> : IVectorStoreRecordCollection<string, TRecord>, IKeywordHybridSearch<TRecord>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>The name of this database for telemetry purposes.</summary>
Expand All @@ -35,7 +35,7 @@ public sealed class MongoDBVectorStoreRecordCollection<TRecord> : IVectorStoreRe
private static readonly VectorSearchOptions s_defaultVectorSearchOptions = new();

/// <summary>The default options for hybrid vector search.</summary>
private static readonly KeywordVectorizedHybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();
private static readonly HybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();

/// <summary><see cref="IMongoDatabase"/> that can be used to manage the collections in MongoDB.</summary>
private readonly IMongoDatabase _mongoDatabase;
Expand Down Expand Up @@ -259,7 +259,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
Array vectorArray = VerifyVectorParam(vector);

var searchOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);
var vectorPropertyName = this._storagePropertyNames[vectorProperty.DataModelPropertyName];

var filter = MongoDBVectorStoreCollectionSearchMapping.BuildFilter(
Expand Down Expand Up @@ -302,14 +302,14 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(
}

/// <inheritdoc />
public async Task<VectorSearchResults<TRecord>> KeywordVectorizedHybridSearch<TVector>(TVector vector, ICollection<string> keywords, KeywordVectorizedHybridSearchOptions? options = null, CancellationToken cancellationToken = default)
public async Task<VectorSearchResults<TRecord>> HybridSearchAsync<TVector>(TVector vector, ICollection<string> keywords, HybridSearchOptions? options = null, CancellationToken cancellationToken = default)
{
Array vectorArray = VerifyVectorParam(vector);

var searchOptions = options ?? s_defaultKeywordVectorizedHybridSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);
var vectorPropertyName = this._storagePropertyNames[vectorProperty.DataModelPropertyName];
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(searchOptions.FullTextPropertyName);
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(searchOptions.AdditionalPropertyName);
var textDataPropertyName = this._storagePropertyNames[textDataProperty.DataModelPropertyName];

var filter = MongoDBVectorStoreCollectionSearchMapping.BuildFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(TVector
}

var searchOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);

var pgVector = PostgresVectorStoreRecordPropertyMapping.MapVectorForStorageModel(vector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.SemanticKernel.Connectors.Qdrant;
public sealed class QdrantVectorStoreRecordCollection<TRecord> :
IVectorStoreRecordCollection<ulong, TRecord>,
IVectorStoreRecordCollection<Guid, TRecord>,
IKeywordVectorizedHybridSearch<TRecord>
IKeywordHybridSearch<TRecord>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>A set of types that a key on the provided model may have.</summary>
Expand All @@ -35,7 +35,7 @@ public sealed class QdrantVectorStoreRecordCollection<TRecord> :
private static readonly VectorSearchOptions s_defaultVectorSearchOptions = new();

/// <summary>The default options for hybrid vector search.</summary>
private static readonly KeywordVectorizedHybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();
private static readonly HybridSearchOptions s_defaultKeywordVectorizedHybridSearchOptions = new();

/// <summary>The name of this database for telemetry purposes.</summary>
private const string DatabaseName = "Qdrant";
Expand Down Expand Up @@ -469,7 +469,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T

// Resolve options.
var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);

// Build filter object.
var filter = QdrantVectorStoreCollectionSearchMapping.BuildFilter(internalOptions.Filter, this._propertyReader.StoragePropertyNamesMap);
Expand Down Expand Up @@ -516,17 +516,17 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T
}

/// <inheritdoc />
public async Task<VectorSearchResults<TRecord>> KeywordVectorizedHybridSearch<TVector>(TVector vector, ICollection<string> keywords, KeywordVectorizedHybridSearchOptions? options = null, CancellationToken cancellationToken = default)
public async Task<VectorSearchResults<TRecord>> HybridSearchAsync<TVector>(TVector vector, ICollection<string> keywords, HybridSearchOptions? options = null, CancellationToken cancellationToken = default)
{
var floatVector = VerifyVectorParam(vector);

// Resolve options.
var internalOptions = options ?? s_defaultKeywordVectorizedHybridSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);

// Build filter object.
var filter = QdrantVectorStoreCollectionSearchMapping.BuildFilter(internalOptions.Filter, this._propertyReader.StoragePropertyNamesMap);
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(internalOptions.FullTextPropertyName);
var textDataProperty = this._propertyReader.GetFullTextDataPropertyOrSingle(internalOptions.AdditionalPropertyName);
var textDataPropertyName = this._propertyReader.GetStoragePropertyName(textDataProperty.DataModelPropertyName);

// Specify the vector name if named vectors are used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T
Verify.NotNull(vector);

var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);

// Build query & search.
var selectFields = internalOptions.IncludeVectors ? null : this._dataStoragePropertyNamesWithScore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T
Verify.NotNull(vector);

var internalOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(internalOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(internalOptions.VectorPropertyName);

// Build query & search.
byte[] vectorBytes = RedisVectorStoreCollectionSearchMapping.ValidateVectorAndConvertToBytes(vector, "JSON");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(TVector
}

var searchOptions = options ?? s_defaultVectorSearchOptions;
var vectorProperty = this._propertyReader.GetVectorPropertyOrFirst(searchOptions.VectorPropertyName);
var vectorProperty = this._propertyReader.GetVectorPropertyOrSingle(searchOptions.VectorPropertyName);

var mappedArray = SqliteVectorStoreRecordPropertyMapping.MapVectorForStorageModel(vector);

Expand Down
Loading
Loading