43 Vector Types

To support arbitrary vector types, Coherence provides the com.oracle.coherence.ai.Vector<T> interface, with three built-in implementations:

  1. BitVector, which internally uses a java.util.Bitset to represent each vector element using a single bit.
  2. Int8Vector, which internally uses a byte[].
  3. Float32Vector, which internally uses a float[].

These types allow you to add a vector property to your own classes the same way that you would add any other property, by simply creating a field and accessors for it.

Book.java
@PortableType(id = 2001)
public class Book
    {
    @Portable private String isbn;
    @Portable private String title;
    @Portable private String author;
    @Portable private String summary;
    @Portable private Vector<float[]> summaryEmbedding;

    // constructors, getters and setters omitted
    }

In the preceding example, the summaryEmbedding field is used to store a vector representation of the summary field, so you can use vector similarity to search book summaries.

In subsequent chapters, you'll see how you can use the summaryEmbedding property to define both standard and vector indexes, and how to perform a similarity search against them.