refactor(model_es): 优化 Encounter.TopK 函数并添加注释
- 在 Encounter.TopK 函数中添加了处理 ES 中 embedding 为 null 的情况的注释 - 调整了 body 字符串的格式,提高了可读性 - 移除了 web.go 中的多余导入和注释
This commit is contained in:
		
							parent
							
								
									609e02dfd2
								
							
						
					
					
						commit
						72ba8efb25
					
				@ -192,6 +192,7 @@ func (e *Encounter) TopK(embedding []float64, k int) ([]Encounter, error) {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// UPDATE 这里无法处理 ES 中 embedding 为 null 的情况。
 | 
			
		||||
	body := fmt.Sprintf(`{
 | 
			
		||||
		"size": %d,
 | 
			
		||||
		"query": {
 | 
			
		||||
 | 
			
		||||
@ -3,12 +3,10 @@ package routers
 | 
			
		||||
import (
 | 
			
		||||
	"catface/app/global/consts"
 | 
			
		||||
	"catface/app/global/variable"
 | 
			
		||||
 | 
			
		||||
	// "catface/app/http/controller/captcha"	// 验证码组件
 | 
			
		||||
	// "catface/app/http/middleware/authorization"
 | 
			
		||||
	"catface/app/http/middleware/cors"
 | 
			
		||||
	validatorFactory "catface/app/http/validator/core/factory"
 | 
			
		||||
 | 
			
		||||
	// TODO validatorFactory "catface/app/http/validator/core/factory"
 | 
			
		||||
	"catface/app/utils/gin_release"
 | 
			
		||||
	"net/http"
 | 
			
		||||
@ -16,6 +14,7 @@ import (
 | 
			
		||||
	"github.com/gin-contrib/pprof"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"go.uber.org/zap"
 | 
			
		||||
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 该路由主要设置 后台管理系统等后端应用路由
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								test/es/encounter_embedding/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								test/es/encounter_embedding/main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	embedding := make([]float64, 768)
 | 
			
		||||
	for i := range embedding {
 | 
			
		||||
		embedding[i] = rand.Float64()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 将嵌入向量转换为字符串,每个元素之间用逗号隔开
 | 
			
		||||
	embeddingStr := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(embedding)), ","), "[]")
 | 
			
		||||
 | 
			
		||||
	// 打印前几个元素以验证
 | 
			
		||||
	fmt.Println(embeddingStr)
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user