AS AgentScopeAPI 手册 / API Reference

DocumentMetadata

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

文档元数据,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.rag.model 包。核心成员包括 getContent、getDocId、getChunkId、getPayload、getPayloadValue、hasPayloadKey。

Document metadata containing content and chunking information.

This class stores metadata about a document chunk, including the content (which can be text, image, video, etc.), document ID, chunk ID, and optional custom payload fields.

The content field uses ContentBlock which is a sealed hierarchy supporting different content types (TextBlock, ImageBlock, VideoBlock, etc.).

The payload field allows storing custom metadata such as file name, department, author, creation time, tags, and other business-specific fields. These fields are stored as key-value pairs and will be persisted to vector databases along with the document content.

Example usage with payload:

`Map<String, Object> payload = new HashMap<>();
payload.put("filename", "report.pdf");
payload.put("department", "Finance");
payload.put("author", "John Doe");
payload.put("created_at", "2024-01-15T10:30:00Z");
payload.put("tags", Arrays.asList("urgent", "quarterly"));

TextBlock content = TextBlock.builder().text("Document content").build();
DocumentMetadata metadata = new DocumentMetadata(content, "doc-123", "chunk-0", payload);
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Builder for constructing DocumentMetadata instances with fluent API.

构造器摘要Constructor Summary

构造器Constructor说明Description
public DocumentMetadata(ContentBlock content, String docId, String chunkId)
创建新的DocumentMetadata 实例不使用自定义负载。
Creates a new DocumentMetadata instance without custom payload.
public DocumentMetadata(ContentBlock content, String docId, String chunkId, Map<String, Object> payload)
创建新的DocumentMetadata 实例使用自定义负载。
Creates a new DocumentMetadata instance with custom payload.

方法摘要Method Summary

方法Method说明Description
public ContentBlock getContent()
获取内容块。
Gets the content block.
public String getDocId()
获取文档标识。
Gets the document ID.
public String getChunkId()
获取分块标识。
Gets the chunk ID.
public Map<String, Object> getPayload()
获取自定义负载元数据。
Gets the custom payload metadata.
public Object getPayloadValue(String key)
获取特定负载值通过密钥。
Gets a specific payload value by key.
public boolean hasPayloadKey(String key)
判断是否具有负载键。
Checks if the payload contains a specific key.
public String getContentText()
获取文本内容来自内容块。
Gets the text content from the content block.
public static Builder builder()
static
返回构建器实例。
Creates a new builder for constructing DocumentMetadata instances.

构造器详情Constructor Detail

DocumentMetadata

public DocumentMetadata(ContentBlock content, String docId, String chunkId)

创建新的DocumentMetadata 实例不使用自定义负载。

Creates a new DocumentMetadata instance without custom payload.

参数Parameters
名称Name类型Type说明Description
contentContentBlock内容(类型 `ContentBlock`)。the content block (text, image, video, etc.)
docIdString文档标识。the document ID
chunkIdString分块标识(类型 `String`)。the chunk ID within the document
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:74–76

DocumentMetadata

public DocumentMetadata(ContentBlock content, String docId, String chunkId, Map<String, Object> payload)

创建新的DocumentMetadata 实例使用自定义负载。

Creates a new DocumentMetadata instance with custom payload.

参数Parameters
名称Name类型Type说明Description
contentContentBlock内容(类型 `ContentBlock`)。the content block (text, image, video, etc.)
docIdString文档标识。the document ID
chunkIdString分块标识(类型 `String`)。the chunk ID within the document
payloadMap<String, Object>负载(类型 `Map`)。the custom metadata fields (can be null or empty)
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if content, docId, or chunkId is null
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:90–109

方法详情Method Detail

getContent

public ContentBlock getContent()

获取内容块。

Gets the content block.

返回Returns ContentBlock
内容块。the content block
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:116–118

getDocId

public String getDocId()

获取文档标识。

Gets the document ID.

返回Returns String
文档标识。the document ID
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:125–127

getChunkId

public String getChunkId()

获取分块标识。

Gets the chunk ID.

返回Returns String
分块标识。the chunk ID
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:134–136

getPayload

public Map<String, Object> getPayload()

获取自定义负载元数据。

Gets the custom payload metadata.

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

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/DocumentMetadata.java:161–166

hasPayloadKey

public boolean hasPayloadKey(String key)

判断是否具有负载键。

Checks if the 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/DocumentMetadata.java:178–183

getContentText

public String getContentText()

获取文本内容来自内容块。

Gets the text content from the content block.

返回Returns String
返回字符串结果。the text content, or empty string if not available
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:194–199

builder

public static Builder builder()
static

返回构建器实例。

Creates a new builder for constructing DocumentMetadata instances.

返回Returns Builder
一种新的构建器实例。a new builder instance
源码Source io/agentscope/core/rag/model/DocumentMetadata.java:221–223

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.rag.model 包。核心成员包括 content、docId、chunkId、payload、addPayload、build。

Builder for constructing DocumentMetadata instances with fluent API.

This builder provides a convenient way to create DocumentMetadata objects, especially when working with custom payload fields. All fields can be set independently, and the builder validates required fields when #build() is called.

基于官方固定版本源码静态生成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.