DocumentMetadata
@Deprecated(forRemoval = true, since = "2.0.0") public class DocumentMetadata
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
content | ContentBlock | 内容(类型 `ContentBlock`)。the content block (text, image, video, etc.) |
docId | String | 文档标识。the document ID |
chunkId | String | 分块标识(类型 `String`)。the chunk ID within the document |
io/agentscope/core/rag/model/DocumentMetadata.java:74–76DocumentMetadata
public DocumentMetadata(ContentBlock content, String docId, String chunkId, Map<String, Object> payload)
创建新的DocumentMetadata 实例使用自定义负载。
Creates a new DocumentMetadata instance with custom payload.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
content | ContentBlock | 内容(类型 `ContentBlock`)。the content block (text, image, video, etc.) |
docId | String | 文档标识。the document ID |
chunkId | String | 分块标识(类型 `String`)。the chunk ID within the document |
payload | Map<String, Object> | 负载(类型 `Map`)。the custom metadata fields (can be null or empty) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if content, docId, or chunkId is null
io/agentscope/core/rag/model/DocumentMetadata.java:90–109方法详情Method Detail
getContent
public ContentBlock getContent()
获取内容块。
Gets the content block.
ContentBlockio/agentscope/core/rag/model/DocumentMetadata.java:116–118getDocId
public String getDocId()
获取文档标识。
Gets the document ID.
Stringio/agentscope/core/rag/model/DocumentMetadata.java:125–127getChunkId
public String getChunkId()
获取分块标识。
Gets the chunk ID.
Stringio/agentscope/core/rag/model/DocumentMetadata.java:134–136getPayload
public Map<String, Object> getPayload()
获取自定义负载元数据。
Gets the custom payload metadata.
Map<String, Object>io/agentscope/core/rag/model/DocumentMetadata.java:147–149getPayloadValue
public Object getPayloadValue(String key)
获取特定负载值通过密钥。
Gets a specific payload value by key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 负载密钥。the payload key |
ObjectNullPointerException可能抛出 `NullPointerException`。if key is null
io/agentscope/core/rag/model/DocumentMetadata.java:161–166hasPayloadKey
public boolean hasPayloadKey(String key)
判断是否具有负载键。
Checks if the payload contains a specific key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 负载密钥到检查。the payload key to check |
booleanNullPointerException可能抛出 `NullPointerException`。if key is null
io/agentscope/core/rag/model/DocumentMetadata.java:178–183getContentText
public String getContentText()
获取文本内容来自内容块。
Gets the text content from the content block.
Stringio/agentscope/core/rag/model/DocumentMetadata.java:194–199builder
public static Builder builder()
返回构建器实例。
Creates a new builder for constructing DocumentMetadata instances.
Builderio/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.