const psqlDB = require("./psql.service"); class FaceService{ async getSameReportList(feat68,limit){ limit = limit || 10; // cosine_similarity let sql = ` select "objectId" as id,"photo","createdAt", array_agg(item)::vector(128) <=> $1::vector(128) as cos from ( SELECT *, jsonb_array_elements("feat68")::float AS item from ( SELECT "objectId","photo","feat68","createdAt" FROM "FaceReport" WHERE "feat68" is not null ORDER BY "createdAt" DESC limit ${limit} ) as rt1 ) as rt GROUP BY "objectId",rt."photo","createdAt" ` let params = [feat68] let result = await psqlDB.any(sql,params) // 人物不同 0.08 0.09 0.06 0.059 // 人物不同 长相像 0.046 0.045 0.043 0.039 // 人物相同 仰角/光照有变化 0.03846 // 人物相同 > 0.0214 0.0188 0.00218 0.038 0.023 result = result.filter(item=>item.cos<0.0385 && item.id!=report.id) result.sort((a,b)=>a.createdAt-b.createdAt) if(result?.length>0){ console.log(result) } return result } } module.exports.FaceService = FaceService