- 重构了 rag_controller.go 中的逻辑,使用新的 DocumentHub 结构 - 修改了 encounter.go 中的 Encounter 结构,增加了 explain 标签 - 重写了 rag_websocket.go 中的逻辑,使用新的 DocumentHub 结构 - 新增了 curd_es/encounter_es_curd.go 文件,实现了 Encounter 的 CURD 操作 - 更新了 nlp/func.go 中的 ChatRAG 函数,使用新的 DocumentHub 结构 - 新增了 curd/docs_hub.go 文件,实现了 DocumentHub 的 TopK 方法 - 新增了 utils/data_explain/data_explain_rag.go 文件,实现了结构体到解释字符串的转换
39 lines
830 B
Go
39 lines
830 B
Go
package nlp
|
|
|
|
import (
|
|
"catface/app/global/variable"
|
|
"catface/app/utils/micro_service"
|
|
"context"
|
|
|
|
"github.com/carlmjohnson/requests"
|
|
)
|
|
|
|
type EmbeddingRes struct {
|
|
Status int `json:"status"`
|
|
Message string `json:"message"`
|
|
Embedding []float64 `json:"embedding"`
|
|
}
|
|
|
|
func GetEmbedding(text []string) ([]float64, bool) {
|
|
body := map[string]interface{}{
|
|
"text": text,
|
|
}
|
|
var res EmbeddingRes
|
|
err := requests.URL(micro_service.FetchPythonServiceUrl("rag/bge_embedding")).
|
|
BodyJSON(&body).
|
|
ToJSON(&res).
|
|
Fetch(context.Background())
|
|
if err != nil {
|
|
variable.ZapLog.Error("获取嵌入向量失败: " + err.Error())
|
|
}
|
|
if res.Status != 200 {
|
|
return nil, false
|
|
} else {
|
|
return res.Embedding, true
|
|
}
|
|
}
|
|
|
|
func GetEmbeddingOneString(str string) ([]float64, bool) {
|
|
return GetEmbedding([]string{str})
|
|
}
|