add_doc_v2 用于向已创建的知识库添加文档。
| 参数 | 类型 | 是否必传 | 默认值 | 参数说明 |
|---|---|---|---|---|
| CollectionName | string | 否 | -- | 知识库名称 |
ProjectName | string | 否 | default | 知识库所属项目,获取方式参考文档 API 接入与技术支持 |
ResourceID | string | 否 | -- | 知识库唯一 ID |
DocID | *string | 是 | -- | 知识库下的文档唯一标识
|
DocName | *string | 否 | -- | 文档名称
|
DocType | *string | 否 | -- | 上传文档的类型
|
Description | *string | 否 | -- | 文档描述
|
TagList | []model.MetaItem | 否 | -- | Tag 为结构体,包含
|
URI | *string | 是 | -- | 待上传的文件 uri 链接,示例:
|
| path_segments | []string | 否 | -- | 文档所在的目录路径,数组元素按目录层级顺序填写。例如:[]string{"产品文档", "V2.0", "使用手册"} |
| 参数 | 类型 | 参数说明 | 备注 |
|---|---|---|---|
| Code | int | 状态码 | |
| Message | string | 返回信息 | |
| RequestID | string | 标识每个请求的唯一标识符 | |
| Data | *AddDocResponseData | AddDocResponseData |
| 字段 | 类型 | 参数说明 |
|---|---|---|
| CollectionName | *string | 知识库的名字 |
| ResourceID | *string | 知识库唯一标识 |
| Project | *string | 项目名 |
| DocID | *string | 文档唯一标识 |
| DedupInfo | *DedupInfo | DedupInfo |
| MoreInfo | *string | 更多信息 |
| 字段 | 类型 | 参数说明 |
|---|---|---|
| Skip | *bool | 是否跳过(去重命中) |
| SameDocIDs | []string | 重复的文档 ID 列表 |
| 状态码 | HTTP 状态码 | 返回信息 | 状态码说明 |
|---|---|---|---|
| 0 | 200 | success | 成功 |
| 1000001 | 401 | unauthorized | 鉴权失败 |
| 1000002 | 403 | no permission | 权限不足 |
| 1000003 | 400 | invalid request:%s | 非法参数 |
| 1000005 | 400 | collection not exist | collection 不存在 |
| 1001002 | 400 | invalid request: doc_id:xxx is duplicated with doc_ids:xxx | 文档内容与现有文档重复 |
| 1001010 | 400 | doc num is exceed 3000000 | doc 数量已达限额,点击详情查看知识库配额限制 |
首次使用知识库 SDK,可参考 使用说明
本示例演示了知识库 Go SDK 中 AddDocV2 函数的基础使用方法,使用前需配置 API Key 鉴权参数。
package main import ( "context" "encoding/json" "fmt" "os" "time" "github.com/volcengine/vikingdb-go-sdk/knowledge" "github.com/volcengine/vikingdb-go-sdk/knowledge/model" ) func main() { var ( apiKey = os.Getenv("VIKINGDB_API_KEY") endpoint = "https://api-knowledgebase.mlp.cn-beijing.volces.com" region = "cn-beijing" ) client, err := knowledge.New( knowledge.AuthAPIKey(apiKey), knowledge.WithEndpoint(endpoint), knowledge.WithRegion(region), knowledge.WithTimeout(time.Second*30), ) if err != nil { fmt.Printf("New client failed, err: %v\n", err) return } ctx := context.Background() collection := client.Collection(model.CollectionMeta{ CollectionName: os.Getenv("VIKING_COLLECTION_NAME"), ProjectName: os.Getenv("VIKING_PROJECT"), }) docId := "<YOUR_DOC_ID>" docName := "<YOUR_DOC_NAME>" docType := "doc" uri := "<YOUR_DOC_LINK_URL>" resp, err := collection.AddDocV2(ctx, model.AddDocV2Request{ DocID: &docId, DocName: &docName, DocType: &docType, URI: &uri, PathPrefix: []string{"产品文档", "V2.0", "使用手册"}, TagList: []model.MetaItem{ { FieldName: func() *string { s := "category"; return &s }(), FieldType: func() *string { s := "string"; return &s }(), FieldValue: "financial_report", }, }, }) if err != nil { fmt.Printf("AddDocV2 failed, err: %v\n", err) return } jsonData, _ := json.Marshal(resp) fmt.Printf("Response: %s\n", string(jsonData)) }