@GetMapping("/search")
    @CrossOrigin
    public SseEmitter search(ChatQueryRequest queryRequest, @RequestHeader Map<String, String> headers)
            throws Exception {
        // request embedding
        FastChatEmbeddingResponse response = distributeAIEmbedding(queryRequest.getMessage());
        List<List<BigDecimal>> contentVector = new ArrayList<>();
        contentVector.add(response.getData().get(0).getEmbedding());

        // search embedding
        KnowledgeRequest knowledgeRequest = new KnowledgeRequest();
        knowledgeRequest.setContentVector(contentVector);
        DataResult<KnowledgeResponse> result = gatewayClientService.knowledgeVectorSearch(knowledgeRequest);
        queryRequest.setPromptType(PromptType.TEXT_GENERATION.getCode());
        String prompt = queryRequest.getMessage();
        if (CollectionUtils.isNotEmpty(result.getData().getKnowledgeList())) {
            List<String> contents = new ArrayList<>();
            for(Knowledge data: result.getData().getKnowledgeList()){
                contents.add(data.getContent());
            }

            prompt = String.format("Based on %s. Please answer %s.", JSON.toJSONString(contents), prompt);
            queryRequest.setMessage(prompt);
        }

        // chat with AI
        SseEmitter sseEmitter = new SseEmitter(CHAT_TIMEOUT);
        String uid = headers.get("uid");
        if (StrUtil.isBlank(uid)) {
            throw new ParamBusinessException("uid");
        }

        if (StringUtils.isBlank(queryRequest.getMessage())) {
            throw new ParamBusinessException("message");
        }

        return distributeAISql(queryRequest, sseEmitter, uid);
    }
search knowledge

@param queryRequest
@return
@throws IOException
chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/KnowledgeController.java