45 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 let you add a vector property to your own classes the same way that you would add any other property, by 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.

Security Prerequisites

Validate vector dimension and index parameters before calling native index code. Treat imported index files and native buffers as untrusted inputs unless their origin and integrity are established. A successful Java deserialization check does not validate a native index’s dimensions, capacity or file format.

For the complete configuration and policy, see Protecting Memcached Values and Native Indexes in Securing Oracle Coherence.

Vector Shape and Portability

Choose vector types, dimensions and serialization consistently across embedding generation, storage and search. Validate input lengths before native calls. Changing an embedding model or dimension requires rebuilding compatible stored vectors and indexes; it is not a transparent dependency-version change.