8

Infinispan kNN Vector Search

 9 months ago
source link: https://infinispan.org/blog/2023/12/13/infinispan-vector-search
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

With Infinispan 15.0.0.Dev06, we have started to expose vector search capabilities using Infinispan’s indexed queries. Using the newly introduced kNN predicate, it is possible to find and order results by the k nearest neighbors of a given vector.

Mapping the embeddings

The new @Vector indexing annotation is used to mark a field as an embedding. Embeddings are vector representations of data, according to a defined model.

The vector dimension is mandatory and should be defined at mapping time. Other options that can be specified during mapping are:

  • the similarity (distance) function

  • the beam width

  • the maximum number of connections.

Bear in mind that these values affect the performance of the approximation algorithm that is used to compute the kNN search.

We support byte[] embeddings. Here is an example of mapping:

That corresponds to the Proto schema:

We also support float[] embeddings. Here is an example of mapping:

That corresponds to the Proto schema:

Searching the embeddings

The following query shows how to perform a kNN search using a supplied vector and a specific distance

The query can be parameterized in several ways:

Or you can pass the entire vector as a single parameter:

If the cache is distributed, the query will be a broadcast query, and it will aggregate all the results from all the nodes that contain shards of the indexes that are related to the search. When we get the result as usual we get all the metadata from the corresponding entities, so that the returning items can easily relate to the application domain.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK