MCPcopy Create free account
hub / github.com/coderabbit214/document-ai / updateByJson

Function updateByJson

pkg/api/data.go:12–53  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

10)
11
12func updateByJson(c *gin.Context) {
13 var json []map[string]string
14 if err := c.Bind(&json); err != nil {
15 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
16 return
17 }
18 if len(json) == 0 {
19 c.JSON(http.StatusBadRequest, gin.H{"error": "json is empty"})
20 return
21 }
22 //数据向量化
23 points := make([]qdrant.Point, 0)
24 for _, v := range json {
25 embeddingRequest := openai.EmbeddingRequest{
26 Input: v["text"],
27 Model: openai.TextEmbeddingAda002,
28 }
29 response, err := openai.SendEmbeddings(embeddingRequest)
30 if err != nil {
31 common.Logger.Error(err.Error())
32 c.JSON(http.StatusOK, common.Error(err.Error()))
33 return
34 }
35 points = append(points, qdrant.Point{
36 ID: uuid.New().String(),
37 Payload: v,
38 Vector: response.Data[0].Embedding,
39 })
40 }
41 pr := qdrant.PointRequest{
42 Points: points,
43 }
44
45 //存储
46 err := qdrant.CreatePoints(common.GlobalObject.Qdrant.CollectionName, pr)
47 if err != nil {
48 common.Logger.Error(err.Error())
49 c.JSON(http.StatusOK, common.Error(err.Error()))
50 return
51 }
52 c.JSON(http.StatusOK, common.Success(nil))
53}

Callers

nothing calls this directly

Calls 4

SendEmbeddingsFunction · 0.92
ErrorFunction · 0.92
CreatePointsFunction · 0.92
SuccessFunction · 0.92

Tested by

no test coverage detected