Class ListRandomAccessVectorValues

java.lang.Object
io.github.jbellis.jvector.graph.ListRandomAccessVectorValues
All Implemented Interfaces:
RandomAccessVectorValues<float[]>

public class ListRandomAccessVectorValues extends Object implements RandomAccessVectorValues<float[]>
A List-backed implementation of the RandomAccessVectorValues interface.

It is acceptable to provide this class to a GraphBuilder, and then continue to add vectors to it as you add to the graph.

This will be as threadsafe as the provided List.

  • Constructor Details

    • ListRandomAccessVectorValues

      public ListRandomAccessVectorValues(List<float[]> vectors, int dimension)
      Construct a new instance of ListRandomAccessVectorValues.
      Parameters:
      vectors - a (potentially mutable) list of float vectors.
      dimension - the dimension of the vectors.
  • Method Details

    • size

      public int size()
      Description copied from interface: RandomAccessVectorValues
      Return the number of vector values.

      All copies of a given RAVV should have the same size. Typically this is achieved by either (1) implementing a threadsafe, un-shared RAVV, where `copy` returns `this`, or (2) implementing a fixed-size RAVV.

      Specified by:
      size in interface RandomAccessVectorValues<float[]>
    • dimension

      public int dimension()
      Description copied from interface: RandomAccessVectorValues
      Return the dimension of the returned vector values
      Specified by:
      dimension in interface RandomAccessVectorValues<float[]>
    • vectorValue

      public float[] vectorValue(int targetOrd)
      Description copied from interface: RandomAccessVectorValues
      Return the vector value indexed at the given ordinal.

      For performance, implementations are free to re-use the same object across invocations. That is, you will get back the same float[] reference (for instance) for every requested ordinal. If you want to use those values across calls, you should make a copy.

      Specified by:
      vectorValue in interface RandomAccessVectorValues<float[]>
      Parameters:
      targetOrd - a valid ordinal, ≥ 0 and < RandomAccessVectorValues.size().
    • isValueShared

      public boolean isValueShared()
      Specified by:
      isValueShared in interface RandomAccessVectorValues<float[]>
      Returns:
      true iff the vector returned is shared. A shared vector will only be valid until the next call to vectorValue overwrites it.
    • copy

      Description copied from interface: RandomAccessVectorValues
      Creates a new copy of this RandomAccessVectorValues. This is helpful when you need to access different values at once, to avoid overwriting the underlying float vector returned by a shared RandomAccessVectorValues.vectorValue(int).

      Un-shared implementations may simply return `this`.

      Specified by:
      copy in interface RandomAccessVectorValues<float[]>