Object ExtensionsKnn(Object, String, String, Knn Options) Method
Perform a KNN search on the float vector attribute name="floatVectorAttributeName"/> (Manticore only).
Definition
Namespace: SphinxConnector.FluentApi.Util
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.4.0
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.4.0
C#
public static bool Knn(
this Object document,
string floatVectorAttributeName,
string query,
KnnOptions options
)VB
<ExtensionAttribute>
Public Shared Function Knn (
document As Object,
floatVectorAttributeName As String,
query As String,
options As KnnOptions
) As BooleanParameters
- document Object
- The document containing the float vector attribute.
- floatVectorAttributeName String
- The name of the vector attribute containing vector data.
- query String
- The search query.
- options KnnOptions
- The options to use for the search.
Return Value
BooleanUsage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type Object. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Example
C#
var knnOptions = new KnnOptions { Rescore = true, EarlyTermination = false, Oversampling = 2, Ef = 9 };
var results = await fulltextSession.Query<Document>().
Match("Machine Learning").
Where(x => x.Knn("embedding_vector", "Machine Learning", knnOptions)).
Select(x => new
{
x.Id,
Dist = Function.KnnDist()
}).
OrderBy(x => x.Dist).
ToListAsync();