Class DocumentChunk

java.lang.Object
com.tangosol.io.AbstractEvolvable
com.oracle.coherence.ai.DocumentChunk
All Implemented Interfaces:
Evolvable, ExternalizableLite, EvolvablePortableObject, PortableObject, Serializable

public final class DocumentChunk extends AbstractEvolvable implements EvolvablePortableObject, ExternalizableLite
A chunk of text extracted from a document.
See Also:
  • Field Details

    • IMPL_VERSION

      public static final int IMPL_VERSION
      The POF implementation version.
      See Also:
  • Constructor Details

    • DocumentChunk

      public DocumentChunk()
      Default constructor for serialization.
    • DocumentChunk

      public DocumentChunk(String text)
      Create a DocumentChunk.
      Parameters:
      text - the chunk of text extracted from a document
    • DocumentChunk

      public DocumentChunk(String text, Vector<float[]> vector)
      Create a DocumentChunk.
      Parameters:
      text - the chunk of text extracted from a document
      vector - the vector associated with the document chunk
    • DocumentChunk

      public DocumentChunk(String text, Map<String,Object> metadata)
      Create a DocumentChunk.
      Parameters:
      text - the chunk of text extracted from a document
      metadata - optional document metadata
    • DocumentChunk

      public DocumentChunk(String text, Map<String,Object> metadata, Vector<float[]> vector)
      Create a DocumentChunk.
      Parameters:
      text - the chunk of text extracted from a document
      metadata - optional document metadata
      vector - the vector associated with the document chunk
  • Method Details

    • text

      public String text()
      Return the text chunk extracted from the document.
      Returns:
      the text chunk extracted from the document
    • metadata

      public Map<String,Object> metadata()
      Returns the optional metadata associated with this document chunk.
      Returns:
      the optional metadata associated with this document chunk
    • isEmbedded

      public boolean isEmbedded()
      Return true if this chunk has a vector embedding.
      Returns:
      true if this chunk has a vector embedding; false otherwise
    • vector

      public Vector<float[]> vector()
      Get the float vector for this chunk.
      Returns:
      the float vector for this chunk
    • setVector

      public DocumentChunk setVector(float[] vector)
      Set the float vector for this chunk.
      Parameters:
      vector - the float vector for this chunk
    • setVector

      public DocumentChunk setVector(Vector<float[]> vector)
      Set the float vector for this chunk.
      Parameters:
      vector - the float vector for this chunk
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getImplVersion

      public int getImplVersion()
      Description copied from class: AbstractEvolvable
      Determine the serialization version supported by the implementing class.
      Specified by:
      getImplVersion in interface Evolvable
      Specified by:
      getImplVersion in class AbstractEvolvable
      Returns:
      the serialization version supported by this object
    • readExternal

      public void readExternal(PofReader in) throws IOException
      Description copied from interface: PortableObject
      Restore the contents of a user type instance by reading its state using the specified PofReader object.
      Specified by:
      readExternal in interface PortableObject
      Parameters:
      in - the PofReader from which to read the object's state
      Throws:
      IOException - if an I/O error occurs
    • writeExternal

      public void writeExternal(PofWriter out) throws IOException
      Description copied from interface: PortableObject
      Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
      Specified by:
      writeExternal in interface PortableObject
      Parameters:
      out - the PofWriter to which to write the object's state
      Throws:
      IOException - if an I/O error occurs
    • readExternal

      public void readExternal(DataInput in) throws IOException
      Description copied from interface: ExternalizableLite
      Restore the contents of this object by loading the object's state from the passed DataInput object.
      Specified by:
      readExternal in interface ExternalizableLite
      Parameters:
      in - the DataInput stream to read data from in order to restore the state of this object
      Throws:
      IOException - if an I/O exception occurs
    • writeExternal

      public void writeExternal(DataOutput out) throws IOException
      Description copied from interface: ExternalizableLite
      Save the contents of this object by storing the object's state into the passed DataOutput object.
      Specified by:
      writeExternal in interface ExternalizableLite
      Parameters:
      out - the DataOutput stream to write the state of this object to
      Throws:
      IOException - if an I/O exception occurs
    • id

      public static DocumentChunk.Id id(String sDocId, int nIndex)
      Create an DocumentChunk.Id.
      Parameters:
      sDocId - the document identifier
      nIndex - the chunk index
      Returns:
      an DocumentChunk.Id with the specified document identifier and chunk index