fuwencai vor 8 Monaten
Ursprung
Commit
3da8ba7944

+ 4 - 45
rpc/knowledge/internal/service/knowledgeService.go

@@ -94,7 +94,7 @@ func (k *KnowledgeService) KnowledgeAdd(param *knowledgeclient.AddRequest, segme
 				"mod_time":       time.Now().Unix(),
 				"answer":         param.Answer,
 				"question":       param.Question,
-				"id":             answerId,
+				"_id":            answerId,
 				"entId":          param.EntId,
 				"questionVector": questionVector,
 			}
@@ -168,26 +168,6 @@ func (k *KnowledgeService) KnowledgeEdit(param *knowledgeclient.KnowledgeEditReq
 		}
 		ok1 := elastic.Del(Index, Type, query)
 		ok2 := elastic.Save(Index, Type, newKnowledge)
-		//  查询出来
-		queryByAid := fmt.Sprintf(`{
-    "query": {
-        "bool": {
-            "must": [
-                {
-                    "term": {
-                        "id": %v
-                    }
-                }
-            ]
-        }
-    },
-    "size": 1
-}`, param.AnswerId)
-		rs := ESV7.Get(ESV7Index, ESV7Type, queryByAid)
-		_id := ""
-		if rs != nil && len(*rs) > 0 {
-			_id = cm.InterfaceToStr((*rs)[0]["_id"])
-		}
 		questionVector, err := util.EncodeVector(param.Question)
 		if err != nil {
 			log.Println("001 获取 向量失败 :" + err.Error())
@@ -199,13 +179,10 @@ func (k *KnowledgeService) KnowledgeEdit(param *knowledgeclient.KnowledgeEditReq
 			"mod_time":       time.Now().Unix(),
 			"answer":         param.Answer,
 			"question":       param.Question,
-			"id":             param.AnswerId,
+			"_id":            param.AnswerId,
 			"entId":          param.EntId,
 			"questionVector": questionVector,
 		}
-		if _id != "" {
-			knowledgeV["_id"] = _id
-		}
 		if !ESV7.Save(ESV7Index, ESV7Type, knowledgeV) {
 			logx.Error("知识库添加向量失败:", knowledgeV)
 		}
@@ -270,26 +247,8 @@ func (k *KnowledgeService) KnowledgeDel(answerId int64) (ok bool) {
 		//删除es数据
 		query := `{"query":{"bool":{"must":[{"term":{"answerId":"` + strconv.Itoa(int(answerId)) + `"}}],"must_not":[],"should":[]}},"from":0,"size":1,"sort":[],"facets":{}}`
 		ok = elastic.Del(Index, Type, query)
-		queryByAid := fmt.Sprintf(`{
-    "query": {
-        "bool": {
-            "must": [
-                {
-                    "term": {
-                        "id": %v
-                    }
-                }
-            ]
-        }
-    },
-    "size": 1
-}`, answerId)
-		rs := ESV7.Get(ESV7Index, ESV7Type, queryByAid)
-		if rs != nil && len(*rs) > 0 {
-			_id := cm.InterfaceToStr((*rs)[0]["_id"])
-			if !ESV7.DelById(ESV7Index, ESV7Type, _id) {
-				logx.Error("删除向量库失败:", _id, answerId)
-			}
+		if !ESV7.DelById(ESV7Index, ESV7Type, cm.InterfaceToStr(answerId)) {
+			logx.Error("删除向量库失败:", answerId)
 		}
 	}
 

+ 1 - 1
rpc/knowledge/util/elasticsearch_dsl.go

@@ -93,7 +93,7 @@ func GetQueryOT(tags, question, keywords, repositoryId string) (qstr string) {
 	return qstr
 }
 
-var queryStr = `{"_source": ["question","intention","answer"],"size": %d, "min_score":%v,"query": {"bool": {"must": [{"term":{"entId":%v}"},{"script_score": {"query": {"match_all": {}},"script": {"source": "cosineSimilarity(params.queryVector,'questionVector')+1", "params": {"queryVector": %v}}}}]}}}`
+var queryStr = `{"_source": ["question","intention","answer"],"size": %d, "min_score":%v,"query": {"bool": {"must": [{"term":{"entId":%v}},{"script_score": {"query": {"match_all": {}},"script": {"source": "cosineSimilarity(params.queryVector,'questionVector')+1", "params": {"queryVector": %v}}}}]}}}`
 
 func GetAnswerQueryStr(question string, entId string, size int, minScore float64) string {
 	qv, _ := EncodeVector(question)