Docuents

REST 资源:corpora.documents

资源:Document

DocumentChunk 的集合。一个 Corpus 最多可以有 10,000 个 Document

JSON 表示法
{
  "name": string,
  "displayName": string,
  "customMetadata": [
    {
      object (CustomMetadata)
    }
  ],
  "updateTime": string,
  "createTime": string
}
田野
name string

不可变。标识符。Document 资源名称。ID(不含“corpora/*/documents/”前缀的名称)最多可包含 40 个字符,这些字符均为小写字母、数字或短划线 (-)。ID 不能以短划线开头或结尾。如果创建时名称为空,系统将从 displayName 派生一个唯一名称,并附带 12 个字符的随机后缀。示例:corpora/{corpus_id}/documents/my-awesome-doc-123a456b789c

displayName string

可选。直观易懂的 Document 显示名。显示名称的长度不得超过 512 个字符(包括空格)。示例:“语义检索器文档”

customMetadata[] object (CustomMetadata)

可选。用户提供的自定义元数据,存储为用于查询的键值对。一个 Document 最多可以包含 20 个 CustomMetadata

updateTime string (Timestamp format)

仅限输出。上次更新 Document 时的时间戳。

时间戳采用 RFC3339 世界协调时间(UTC,即“祖鲁时”)格式,精确到纳秒,最多九个小数位。示例:"2014-10-02T15:01:23Z""2014-10-02T15:01:23.045123456Z"

createTime string (Timestamp format)

仅限输出。Document 创建时的时间戳。

时间戳采用 RFC3339 世界协调时间(UTC,即“祖鲁时”)格式,精确到纳秒,最多九个小数位。示例:"2014-10-02T15:01:23Z""2014-10-02T15:01:23.045123456Z"

方法:corpora.documents.create

创建一个空的 Document

端点

<ph type="x-smartling-placeholder"></ph> 帖子 https://generativelanguage.googleapis.com/v1beta/{parent=corpora/*}/documents

路径参数

parent string

必需。将在其中创建此 DocumentCorpus 的名称。示例:corpora/my-corpus-123 其格式为 corpora/{corpora}

请求正文

请求正文包含一个 Document 实例。

响应正文

如果成功,响应正文将包含一个新创建的 Document 实例。

方法:corpora.documents.list

列出 Corpus 中的所有 Document

端点

<ph type="x-smartling-placeholder"></ph> 领取 https://generativelanguage.googleapis.com/v1beta/{parent=corpora/*}/documents

路径参数

parent string

必需。包含 DocumentCorpus 的名称。示例:corpora/my-corpus-123 其格式为 corpora/{corpora}

查询参数

pageSize integer

可选。每页返回的 Document 数量上限。服务返回的 Document 数可能会减少。

如果未指定,则最多返回 10 个 Document。大小上限为每页 20 个 Document

pageToken string

可选。从上一次 documents.list 调用收到的页面令牌。

将响应中返回的 nextPageToken 作为参数提供给下一个请求,以检索下一页。

进行分页时,提供给 documents.list 的所有其他参数必须与提供页面令牌的调用匹配。

请求正文

请求正文必须为空。

响应正文

来自 documents.list 的响应,其中包含 Document 的分页列表。Documentdocument.create_time 升序排序。

如果成功,响应正文将包含结构如下的数据:

田野
documents[] object (Document)

返回的 Document

nextPageToken string

可作为 pageToken 发送并用于检索下一页的令牌。如果省略此字段,则不存在其他页面。

JSON 表示法
{
  "documents": [
    {
      object (Document)
    }
  ],
  "nextPageToken": string
}

方法:corpora.documents.query

Document 执行语义搜索。

端点

<ph type="x-smartling-placeholder"></ph> 帖子 https://generativelanguage.googleapis.com/v1beta/{name=corpora/*/documents/*}:query

路径参数

name string

必需。要查询的 Document 的名称。示例:corpora/my-corpus-123/documents/the-doc-abc 其格式为 corpora/{corpora}/documents/{document}

请求正文

请求正文中包含结构如下的数据:

<ph type="x-smartling-placeholder">
</ph> 田野
query string

必需。用于执行语义搜索的查询字符串。

resultsCount integer

可选。要返回的最大 Chunk 数量。服务返回的 Chunk 数可能会减少。

如果未指定,则最多返回 10 个 Chunk。指定的最大结果数为 100。

metadataFilters[] object (MetadataFilter)

可选。过滤出 Chunk 元数据。每个 MetadataFilter 对象都应对应于一个唯一的键。多个 MetadataFilter 对象通过逻辑“AND”连接。

注意:此请求不支持Document级过滤,因为已指定Document名称。

查询示例:(year >= 2020 OR year < 2010) AND (genre = play OR genre = action)

MetadataFilter 对象列表:metadataFilters = [ {key = "chunk.custom_metadata.year"条件 = [{int_value = 2020, 操作 = GREATER_EQUAL}, {int_value = 2010, 操作 = LESS}}, {key = "chunk.custom_metadata.genre"条件 = [{stringValue = "drama", 操作 = EQUAL}, {stringValue = "action", 操作 = EQUAL}}]

查询数值范围的示例:(year > 2015 AND year <= 2020)

MetadataFilter 对象列表:metadataFilters = [ {key = "chunk.custom_metadata.year"conditions = [{int_value = 2015, operation = GREATER}]}, {key = &quot;chunk.custom_metadata.year&quot;条件 = [{int_value = 2020, 操作 = LESS_EQUAL}]}]

注意:只有数值支持对同一键使用“AND”。字符串值仅支持对同一键使用“OR”。

响应正文

来自 documents.query 的响应,其中包含相关分块的列表。

如果成功,响应正文将包含结构如下的数据:

田野
relevantChunks[] object (RelevantChunk)

返回的相关分块。

JSON 表示法
{
  "relevantChunks": [
    {
      object (RelevantChunk)
    }
  ]
}

方法:corpora.documents.get

获取有关特定 Document 的信息。

端点

<ph type="x-smartling-placeholder"></ph> 领取 https://generativelanguage.googleapis.com/v1beta/{name=corpora/*/documents/*}

路径参数

name string

必需。要检索的 Document 的名称。示例:corpora/my-corpus-123/documents/the-doc-abc 其格式为 corpora/{corpora}/documents/{document}

请求正文

请求正文必须为空。

响应正文

如果成功,则响应正文包含一个 Document 实例。

方法:corpora.documents.patch

更新 Document

端点

<ph type="x-smartling-placeholder"></ph> 补丁 https://generativelanguage.googleapis.com/v1beta/{document.name=corpora/*/documents/*}

PATCH https://generativelanguage.googleapis.com/v1beta/{document.name=corpora/*/documents/*}

路径参数

document.name string

不可变。标识符。Document 资源名称。ID(名称不包含“corpora/*/documents/”前缀)最多可包含 40 个字符,这些字符均为小写字母、数字或短划线 (-)。ID 不能以短划线开头或结尾。如果创建时名称为空,系统将从 displayName 派生一个唯一名称,并附带 12 个字符的随机后缀。示例:corpora/{corpus_id}/documents/my-awesome-doc-123a456b789c 其格式为 corpora/{corpora}/documents/{document}

查询参数

updateMask string (FieldMask format)

必需。要更新的字段列表。目前,此方法仅支持更新 displayNamecustomMetadata

这是完全限定字段名称的逗号分隔列表。示例:"user.displayName,photo"

请求正文

请求正文包含一个 Document 实例。

响应正文

如果成功,则响应正文包含一个 Document 实例。

方法:corpora.documents.delete

删除 Document

端点

<ph type="x-smartling-placeholder"></ph> 删除 https://generativelanguage.googleapis.com/v1beta/{name=corpora/*/documents/*}

路径参数

name string

必需。要删除的 Document 的资源名称。示例:corpora/my-corpus-123/documents/the-doc-abc 其格式为 corpora/{corpora}/documents/{document}

查询参数

force boolean

可选。如果设置为 true,则与此 Document 相关的所有 Chunk 和对象也会被删除。

如果为 false(默认值),则当 Document 包含任何 Chunk 时,系统会返回 FAILED_PRECONDITION 错误。

请求正文

请求正文必须为空。

响应正文

如果成功,则响应正文为空。

CustomMetadata

存储为键值对的用户提供的元数据。

JSON 表示法
{
  "key": string,

  // Union field value can be only one of the following:
  "stringValue": string,
  "stringListValue": {
    object (StringList)
  },
  "numericValue": number
  // End of list of possible types for union field value.
}
田野
key string

必需。要存储的元数据的键。

联合字段 value

value 只能是下列其中一项:

stringValue string

要存储的元数据的字符串值。

stringListValue object (StringList)

要存储的元数据的 StringList 值。

numericValue number

要存储的元数据的数值。

StringList

分配给单个元数据键的用户提供的字符串值。

JSON 表示法
{
  "values": [
    string
  ]
}
田野
values[] string

要存储的元数据的字符串值。