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_test01SearchReq 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);}