add_point 用于新增一个知识库下文档的一个切片
参数 | 类型 | 必选 | 默认值 | 备注 |
|---|---|---|---|---|
CollectionName | string | 否 | -- | 知识库名称 |
ProjectName | string | 否 | default | 知识库所属项目,获取方式参见文档API 接入与技术支持 |
ResourceID | string | 否 | -- | 知识库唯一 id
|
DocID | string | 是 | -- | 表示新增切片所属的文档
|
ChunkType | string | 是 | -- | 要添加的切片类型
|
Content | *string | 否 | -- | 新增切片文本内容 |
ChunkTitle | *string | 否 | -- | 切片标题 |
Question | *string | 否 | -- | 新增 faq 切片中的问题字段
|
Fields | []map[string]interface{} | 否 | -- | 表示传入的结构化数据
|
字段 | 类型 | 参数说明 |
|---|---|---|
Code | int | 状态码 |
Message | string | 返回信息 |
RequestID | string | 标识每个请求的唯一标识符 |
Data | *PointAddResult | PointAddResult |
字段 | 类型 | 参数说明 |
|---|---|---|
CollectionName | *string | 知识库的名字 |
ResourceID | *string | 知识库唯一标识 |
Project | *string | 项目名 |
DocID | *string | 文档 id |
ChunkID | *int64 | 切片在文档下的 id,文档下唯一 |
PointID | *string | 切片 id,知识库下唯一 |
首次使用知识库 SDK ,可参考 使用说明
本示例演示了知识库 Go SDK 中 AddPoint 函数的基础使用方法,使用前需配置 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: "your_collection_name", ProjectName: "default", }) content := "example content" question := "example question" chunkTitle := "example chunk title" resp, err := collection.AddPoint(ctx, model.AddPointRequest{ DocID: "your_doc_id", ChunkType: "text", Content: &content, Question: &question, ChunkTitle: &chunkTitle, Fields: []map[string]interface{}{ { "field_name": "example_field", "field_value": "example_value", }, }, }) if err != nil { fmt.Printf("AddPoint failed, err: %v\n", err) return } jsonData, _ := json.Marshal(resp) fmt.Printf("Response: %s\n", string(jsonData)) }