类 Document
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.
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明double[]Gets the embedding vector.getId()Gets the document ID.Gets the document metadata.Gets the custom payload from document metadata.getPayloadValue(String key) Gets a specific payload value by key.<T> TgetPayloadValueAs(String key, Class<T> targetClass) Gets a specific payload value by key and converts it to the specified type.getScore()Gets the similarity score.Gets the document vector name.booleanhasPayloadKey(String key) Checks if the document payload contains a specific key.voidsetEmbedding(double[] embedding) Sets the embedding vector.voidSets the similarity score.voidsetVectorName(String vectorName) Sets the document vector name.toString()
-
构造器详细资料
-
Document
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
Gets the document ID.- 返回:
- the document ID (UUID string)
-
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
Gets the similarity score.- 返回:
- the similarity score, or null if not set
-
setScore
Sets the similarity score.- 参数:
score- the similarity score
-
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
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
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 keytargetClass- 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 typeNullPointerException- if key or clazz is null
-
hasPayloadKey
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
Gets the document vector name.- 返回:
- the document name, or null if not set
-
setVectorName
Sets the document vector name.- 参数:
vectorName- the document name
-
toString
-