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 链接,示例:
|
参数 | 类型 | 参数说明 | 备注 |
|---|---|---|---|
Code | int | 状态码 | |
Message | string | 返回信息 | |
RequestID | string | 标识每个请求的唯一标识符 | |
Data | *AddDocResponseData | AddDocResponseData |
字段 | 类型 | 参数说明 |
|---|---|---|
CollectionName | *string | 知识库的名字 |
ResourceID | *string | 知识库唯一标识 |
Project | *string | 项目名 |
DocID | *string | 文档唯一标识 |
TaskID | *int64 | 任务 id |
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 函数的基础使用方法,使用前需配置 AK/SK 鉴权参数。
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 ( accessKey = os.Getenv("VIKINGDB_AK") secretKey = os.Getenv("VIKINGDB_SK") endpoint = "https://api-knowledgebase.mlp.cn-beijing.volces.com" region = "cn-beijing" ) client, err := knowledge.New( knowledge.AuthIAM(accessKey, secretKey), 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, 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)) }