AS AgentScopeAPI 手册 / API Reference

Document

@Deprecated(forRemoval = true, since = "2.0.0") public class Document
源码Source io/agentscope/core/rag/model/Document.java:37–238

文档,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.rag.model 包。核心成员包括 getId、getMetadata、getEmbedding、setEmbedding、getScore、setScore。

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.

构造器摘要Constructor Summary

构造器Constructor说明Description
public Document(DocumentMetadata metadata)
创建新的文档实例。
Creates a new Document instance.

方法摘要Method Summary

方法Method说明Description
public String getId()
获取文档标识。
Gets the document ID.
public DocumentMetadata getMetadata()
获取文档元数据。
Gets the document metadata.
public double[] getEmbedding()
获取向量化向量。
Gets the embedding vector.
public void setEmbedding(double[] embedding)
设置向量化向量。
Sets the embedding vector.
public Double getScore()
获取分数。
Gets the similarity score.
public void setScore(Double score)
设置分数。
Sets the similarity score.
public Map<String, Object> getPayload()
获取自定义负载来自文档元数据。
Gets the custom payload from document metadata.
public Object getPayloadValue(String key)
获取特定负载值通过密钥。
Gets a specific payload value by key.
public T T getPayloadValueAs(String key, Class<T> targetClass)
获取负载值 As。
Gets a specific payload value by key and converts it to the specified type.
public boolean hasPayloadKey(String key)
判断是否具有负载键。
Checks if the document payload contains a specific key.
public String getVectorName()
获取文档向量名称。
Gets the document vector name.
public void setVectorName(String vectorName)
设置文档向量名称。
Sets the document vector name.
public String toString()
返回 `toString` 结果。
Returns the to string.

构造器详情Constructor Detail

Document

public Document(DocumentMetadata metadata)

创建新的文档实例。

Creates a new Document instance.

参数Parameters
名称Name类型Type说明Description
metadataDocumentMetadata文档元数据。the document metadata
源码Source io/agentscope/core/rag/model/Document.java:54–60

方法详情Method Detail

getId

public String getId()

获取文档标识。

Gets the document ID.

返回Returns String
返回字符串结果。the document ID (UUID string)
源码Source io/agentscope/core/rag/model/Document.java:67–69

getMetadata

public DocumentMetadata getMetadata()

获取文档元数据。

Gets the document metadata.

返回Returns DocumentMetadata
文档元数据。the document metadata
源码Source io/agentscope/core/rag/model/Document.java:76–78

getEmbedding

public double[] getEmbedding()

获取向量化向量。

Gets the embedding vector.

返回Returns double[]
返回double[]。the embedding vector, or null if not set
源码Source io/agentscope/core/rag/model/Document.java:85–87

setEmbedding

public void setEmbedding(double[] embedding)

设置向量化向量。

Sets the embedding vector.

参数Parameters
名称Name类型Type说明Description
embeddingdouble[]向量化向量。the embedding vector
源码Source io/agentscope/core/rag/model/Document.java:94–96

getScore

public Double getScore()

获取分数。

Gets the similarity score.

返回Returns Double
返回数值结果。the similarity score, or null if not set
源码Source io/agentscope/core/rag/model/Document.java:103–105

setScore

public void setScore(Double score)

设置分数。

Sets the similarity score.

参数Parameters
名称Name类型Type说明Description
scoreDouble分数(类型 `Double`)。the similarity score
源码Source io/agentscope/core/rag/model/Document.java:112–114

getPayload

public Map<String, Object> getPayload()

获取自定义负载来自文档元数据。

Gets the custom payload from document metadata.

返回Returns Map<String, Object>
返回映射。an unmodifiable map of custom metadata fields (never null)
源码Source io/agentscope/core/rag/model/Document.java:125–127

getPayloadValue

public Object getPayloadValue(String key)

获取特定负载值通过密钥。

Gets a specific payload value by key.

参数Parameters
名称Name类型Type说明Description
keyString负载密钥。the payload key
返回Returns Object
返回对象。the payload value, or null if the key doesn't exist
抛出Throws
  • NullPointerException 可能抛出 `NullPointerException`。if key is null
源码Source io/agentscope/core/rag/model/Document.java:139–141

getPayloadValueAs

public T T getPayloadValueAs(String key, Class<T> targetClass)

获取负载值 As。

Gets a specific payload value by key and converts it to the specified type.

参数Parameters
名称Name类型Type说明Description
keyString负载密钥。the payload key
targetClassClass<T>目标类到转换到。the target class to convert to
返回Returns T
返回T。the payload value converted to the specified type, or null if the key doesn't exist
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if the value cannot be converted to the target type
  • NullPointerException 可能抛出 `NullPointerException`。if key or clazz is null
源码Source io/agentscope/core/rag/model/Document.java:157–171

hasPayloadKey

public boolean hasPayloadKey(String key)

判断是否具有负载键。

Checks if the document payload contains a specific key.

参数Parameters
名称Name类型Type说明Description
keyString负载密钥到检查。the payload key to check
返回Returns boolean
返回布尔值,表示判断结果。true if the key exists in the payload, false otherwise
抛出Throws
  • NullPointerException 可能抛出 `NullPointerException`。if key is null
源码Source io/agentscope/core/rag/model/Document.java:183–185

getVectorName

public String getVectorName()

获取文档向量名称。

Gets the document vector name.

返回Returns String
返回字符串结果。the document name, or null if not set
源码Source io/agentscope/core/rag/model/Document.java:192–194

setVectorName

public void setVectorName(String vectorName)

设置文档向量名称。

Sets the document vector name.

参数Parameters
名称Name类型Type说明Description
vectorNameString文档名称。the document name
源码Source io/agentscope/core/rag/model/Document.java:201–203

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/rag/model/Document.java:229–237
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.