ObjectExtensionsKnn(Object, String, Single, KnnOptions) Method

Perform a KNN search on the float vector attribute floatVectorAttributeName (Manticore only).

Definition

Namespace: SphinxConnector.FluentApi.Util
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.4.0
C#
public static bool Knn(
	this Object document,
	string floatVectorAttributeName,
	float[] queryVector,
	KnnOptions options
)

Parameters

document  Object
The document containing the float vector attribute.
floatVectorAttributeName  String
The name of the float vector attribute containing vector data.
queryVector  Single
The search vector as an array of floats.
options  KnnOptions
The options to use for the search.

Return Value

Boolean

Usage 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 };
float[] vectors = new float[384];

using var fulltextSession = fulltextStore.StartSession();
var results = await fulltextSession.Query<Document>().
                                    Match("Machine Learning").
                                    Where(x => x.Knn("embedding_vector", vectors, knnOptions)).
                                    ToListAsync();

See Also