Today we’re thrilled to announce support for Hybrid search with Semantic Kernel Vector Stores for .NET.
What is Hybrid Search?
Hybrid search performs two parallel searches on a vector database. The union of the results of these two searches are then returned to callers with a combined rank, based on the rankings from each of the constituent searches. The two searches typically consist of 1. a vector similarity search and 2. a keyword search over the source text of the vector from search 1.
Using hybrid search typically results in much better RAG performance than just using regular vector similarity search.
Using Hybrid Search:
To use Hybrid Search with the Semantic Kernel Vector Stores, your schema will require two properties:
- The vector field that the vector similarity search would target
- The text field that the keyword search would target
Typically, the vector field and the text field are interrelated. The embedding that was generated from the text is stored in the vector field.
Here is an example data model class with annotations to mark the DescriptionEmbedding field as our Vector and the Description field as our text field. Note that the text field is marked as FullTextSearchable. This is required to index the Description field for keyword search when creating the collection.
public sealed class Product
{
[VectorStoreRecordKey]
public int Key { get; set; }
[VectorStoreRecordData(IsFullTextSearchable = true)]
public string Description { get; set; }
[VectorStoreRecordVector(1536)]
public ReadOnlyMemory<float> DescriptionEmbedding { get; set; }
}
var hybridSearchCollection = (IKeywordHybridSearch<Product>)vectorStore.GetCollection<int, Product>("skproducts");
var searchResult = await hybridSearchCollection.HybridSearchAsync(searchVector, ["powertool", "sander", "electric"]);
Documentation & Samples
Check out the following page for more detailed documentation on how to use Hybrid Search: https://learn.microsoft.com/semantic-kernel/concepts/vector-store-connectors/hybrid-search
We also have an end to end sample using Azure AI Search with Hybrid Search here: https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Memory/VectorStore_HybridSearch_Simple_AzureAISearch.cs
For information on which connectors currently support Hybrid Search, please consult the page for each connector: https://learn.microsoft.com/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors
Coming Soon
Watch this space for announcements around support for hybrid search for Python.
0 comments