Class SparseVector

java.lang.Object
com.mcpdbwizard.pub.SparseVector

public final class SparseVector extends Object
A sparse Oracle VECTOR value (23ai): a high-dimensional vector stored as its non-zero entries only. Distinct from a dense VECTOR (read/written as double[]) and a binary VECTOR (read/written as byte[]) — a sparse vector of a million dimensions with a handful of non-zeros must NOT be densified to a million-element array, so it carries its own {length, indices, values} shape.
  • length — the total number of dimensions.
  • indices — the positions (0-based, ascending) of the non-zero entries.
  • values — the non-zero values; values[k] lives at indices[k].

Read from a sparse column/param via ReadOnlyRowSet.getVectorSparse(String); written via WriteableRowSet.setVectorSparse(String, SparseVector) / StatementParameters2.setVectorSparseParam. The value carries only double magnitudes — it binds as a FLOAT64 sparse vector and Oracle coerces to the column/param element format (a FLOAT32 column keeps the value; an INT8 column rounds, as it must).

Fields are public to match the field-visibility JSON mapping the generated MCP server uses, so a sparse vector round-trips as a {"length":…, "indices":[…], "values":[…]} object with no extra mapping.

Requires ojdbc 23.26+ (the sparse oracle.sql.VECTOR accessors); earlier drivers cannot read or write sparse vectors.

Since:
Oracle 23ai Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int[]
    Positions (0-based, ascending) of the non-zero entries.
    int
    Total number of dimensions.
    double[]
    The non-zero values; values[k] lives at indices[k].
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-arg constructor (for the JSON mapper).
    SparseVector(int length, int[] indices, double[] values)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    fromVector(oracle.sql.VECTOR theVector)
    Build a SparseVector from a sparse oracle.sql.VECTOR (its toSparseDoubleArray() view).
    double[]
    The densified form: a double[] of length with values placed at indices and zeros elsewhere.
     
    oracle.sql.VECTOR
    Turn this value into a bindable oracle.sql.VECTOR (a FLOAT64 sparse vector — Oracle coerces to the target column/param element format).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • length

      public int length
      Total number of dimensions.
    • indices

      public int[] indices
      Positions (0-based, ascending) of the non-zero entries.
    • values

      public double[] values
      The non-zero values; values[k] lives at indices[k].
  • Constructor Details

    • SparseVector

      public SparseVector()
      No-arg constructor (for the JSON mapper).
    • SparseVector

      public SparseVector(int length, int[] indices, double[] values)
  • Method Details

    • fromVector

      public static SparseVector fromVector(oracle.sql.VECTOR theVector) throws SQLException
      Build a SparseVector from a sparse oracle.sql.VECTOR (its toSparseDoubleArray() view). Returns null for a null input.
      Throws:
      SQLException - if the VECTOR cannot be read as a sparse double array
    • toVector

      public oracle.sql.VECTOR toVector() throws SQLException
      Turn this value into a bindable oracle.sql.VECTOR (a FLOAT64 sparse vector — Oracle coerces to the target column/param element format).
      Throws:
      SQLException - if the sparse vector cannot be constructed
    • toDenseArray

      public double[] toDenseArray()
      The densified form: a double[] of length with values placed at indices and zeros elsewhere. (Convenience for callers that want the full vector; avoid for very high-dimensional sparse vectors.)
    • toString

      public String toString()
      Overrides:
      toString in class Object