MCPcopy Create free account
hub / github.com/LQF-dev/smart-hr / RAGService

Class RAGService

back/src/main/java/com/smarthr/service/rag/RAGService.java:20–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import java.util.stream.Collectors;
19
20@Slf4j
21@Service
22@RequiredArgsConstructor
23public class RAGService {
24
25 private final EmbeddingService embeddingService;
26 private final DocumentSplitter documentSplitter;
27 private final ModelRouter modelRouter;
28
29 // 可选依赖,使用 @Autowired(required = false) 或通过构造器处理
30 private final Optional<MilvusVectorStore> milvusVectorStore;
31
32 /**
33 * 索引简历文档到 Milvus
34 */
35 public void indexResume(String resumeId, String content, Map<String, Object> metadata) {
36 if (milvusVectorStore.isEmpty()) {
37 log.warn("Milvus is not available, skipping resume indexing");
38 return;
39 }
40
41 try {
42 // 分块
43 List<DocumentChunk> chunks = documentSplitter.split(resumeId, content, metadata);
44
45 // 向量化并存储
46 List<VectorDocument> documents = new ArrayList<>();
47 for (DocumentChunk chunk : chunks) {
48 float[] embedding = embeddingService.embed(chunk.getContent());
49
50 VectorDocument doc = VectorDocument.builder()
51 .id(chunk.getId())
52 .content(chunk.getContent())
53 .embedding(embedding)
54 .metadata(chunk.getMetadata())
55 .build();
56
57 documents.add(doc);
58 }
59
60 milvusVectorStore.get().addDocuments(documents);
61 log.info("Indexed resume {} with {} chunks to Milvus", resumeId, chunks.size());
62
63 } catch (Exception e) {
64 log.error("Failed to index resume: {}", e.getMessage(), e);
65 throw new RuntimeException("Failed to index resume", e);
66 }
67 }
68
69
70
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected