45 Vector Types
To support arbitrary vector types, Coherence provides the
com.oracle.coherence.ai.Vector<T> interface, with three built-in
implementations:
BitVector, which internally uses ajava.util.Bitsetto represent each vector element using a single bit.Int8Vector, which internally uses abyte[].Float32Vector, which internally uses afloat[].
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.
@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.
Parent topic: Storing and Searching Vectors in Coherence