anything文本分割优化

1、文本分割优化,建议 200 和40,把文档切得更碎一些方便检索命中。

2、RAG接口进一步优化

 /**
     * RAG知识库接口
     *
     * @param prompt
     * @return
     */
    @GetMapping(value = "/rag/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> ragchat(String prompt) {

        List<Float> floatList = embeddingClient.embed(prompt);
        Map<String, Object> searchParams = Maps.newHashMap();
        searchParams.put("nprobe", 10);

// anythingllm_hhy  anythingllm_test01
        SearchReq searchReq = SearchReq.builder()
                .collectionName("anythingllm_test01")
                .data(Collections.singletonList(new FloatVec(floatList)))
                .metricType(IndexParam.MetricType.COSINE)
                .searchParams(searchParams)
//                metadata  text   deepseek4j_test
                .outputFields(Collections.singletonList("metadata"))
                //anything中的默认配置为4
                .topK(5)
                .build();


        // 定义相似性阈值
        double threshold = 0.8;
        SearchResp searchResp = milvusClientV2.search(searchReq);

        List<String> resultList = new ArrayList<>();
        List<List<SearchResp.SearchResult>> searchResults = searchResp.getSearchResults();
        for (List<SearchResp.SearchResult> results : searchResults) {
            for (SearchResp.SearchResult result : results) {
                System.out.println(result.getEntity() + "相似度为:" + result.getScore());
                result.getScore();
                Gson gson = new Gson();
                JsonObject jsonObject = gson.fromJson(result.getEntity().get("metadata").toString(), JsonObject.class);
                resultList.add(result.getEntity().get("metadata").toString());
            }
        }


        ChatCompletionRequest request = ChatCompletionRequest.builder()
                // 根据渠道模型名称动态修改这个参数
                .model("deepseek-r1:32b")
                .addUserMessage(String.format("你要根据用户输入的问题:%s \n \n 参考如下内容: %s  \n\n 整理处理最终结果", prompt, resultList)).build();

        return deepSeekClient.chatFluxCompletion(request);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非ban必选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值