类 Document

java.lang.Object
io.agentscope.core.rag.model.Document

public class Document extends Object
Document class representing a document chunk in the RAG system.

This is the core data structure for RAG operations. Each document contains metadata, an optional embedding vector, and an optional similarity score.

The document ID is automatically generated as a deterministic UUID based on the document metadata (doc_id, chunk_id, and content), ensuring consistent IDs for the same content across different runs.

  • 构造器详细资料

    • Document

      public Document(DocumentMetadata metadata)
      Creates a new Document instance.

      The document ID is automatically generated as a deterministic UUID based on the metadata (doc_id, chunk_id, and content).

      参数:
      metadata - the document metadata
  • 方法详细资料

    • getId

      public String getId()
      Gets the document ID.
      返回:
      the document ID (UUID string)
    • getMetadata

      public DocumentMetadata getMetadata()
      Gets the document metadata.
      返回:
      the document metadata
    • getEmbedding

      public double[] getEmbedding()
      Gets the embedding vector.
      返回:
      the embedding vector, or null if not set
    • setEmbedding

      public void setEmbedding(double[] embedding)
      Sets the embedding vector.
      参数:
      embedding - the embedding vector
    • getScore

      public Double getScore()
      Gets the similarity score.
      返回:
      the similarity score, or null if not set
    • setScore

      public void setScore(Double score)
      Sets the similarity score.
      参数:
      score - the similarity score
    • getPayload

      public Map<String,Object> getPayload()
      Gets the custom payload from document metadata.

      This is a convenience method that delegates to the metadata's getPayload(). The payload contains business-specific fields such as filename, department, author, tags, and other custom metadata.

      返回:
      an unmodifiable map of custom metadata fields (never null)
    • getPayloadValue

      public Object getPayloadValue(String key)
      Gets a specific payload value by key.

      This is a convenience method that delegates to the metadata's getPayloadValue(). Use this to retrieve individual payload values without accessing the entire map.

      参数:
      key - the payload key
      返回:
      the payload value, or null if the key doesn't exist
      抛出:
      NullPointerException - if key is null
    • getPayloadValueAs

      public <T> T getPayloadValueAs(String key, Class<T> targetClass)
      Gets a specific payload value by key and converts it to the specified type.

      This method is useful when the payload contains complex objects (like custom POJOs) that were serialized to Map during storage. It uses Jackson's ObjectMapper to convert the Map back to the original type.

      类型参数:
      T - the target type
      参数:
      key - the payload key
      targetClass - the target class to convert to
      返回:
      the payload value converted to the specified type, or null if the key doesn't exist
      抛出:
      IllegalArgumentException - if the value cannot be converted to the target type
      NullPointerException - if key or clazz is null
    • hasPayloadKey

      public boolean hasPayloadKey(String key)
      Checks if the document payload contains a specific key.

      This is a convenience method that delegates to the metadata's hasPayloadKey(). Use this to safely check for the existence of a payload field before retrieving it.

      参数:
      key - the payload key to check
      返回:
      true if the key exists in the payload, false otherwise
      抛出:
      NullPointerException - if key is null
    • getVectorName

      public String getVectorName()
      Gets the document vector name.
      返回:
      the document name, or null if not set
    • setVectorName

      public void setVectorName(String vectorName)
      Sets the document vector name.
      参数:
      vectorName - the document name
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object