[Feat] response_citations 저장 - ResponseCitationCommandService 구현 - #74
Conversation
citationOrder/citationLabel을 분리한 이유, quotedText/pageNo/relevanceScore가 각각 어떤 의미인지 필드별로 명시한다.
… (F-RAG-04) PromptBuilder가 라벨을 매긴 것과 동일한 candidates 순서를 citation_order/ citation_label 근거로 재사용해 response_citations에 저장한다. SearchResultCommandService.saveAll()과 동일하게 entityManager.getReference()로 불필요한 SELECT 없이 chunk FK를 연결한다. search_result_id는 이번 이슈에서 채우지 않는다(null) — SearchResultCommandService.saveAll()이 저장된 SearchResult를 반환하지 않아 이 시점에는 알 수 없고, Issue 5에서 채운다.
정상 케이스(순서/라벨/텍스트/페이지/점수 저장, searchResult null 확인)와 빈 후보 리스트 케이스를 검증한다.
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRAG 응답에 사용된 후보들을 Changes응답 인용 저장
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
docs/design/kangcheolung-#73-response-citation-save.md (1)
143-150: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win저장 실패 시 예외 전파 계약을 정확히 문서화해 주세요.
ResponseCitationCommandService는 예외를 별도로 처리하지 않으므로 리포지토리/JPA 저장 실패가 호출자에게 전파될 수 있습니다. “예외를 던지지 않는다” 대신 “예외를 변환하지 않으며 저장 실패는 전파된다”는 식으로 실제 동작을 명시해야 합니다.As per coding guidelines, 설계 문서는 에러 케이스를 문서화해야 합니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/design/kangcheolung-`#73-response-citation-save.md around lines 143 - 150, Update the “에러 케이스 정리” section for ResponseCitationCommandService to state that it does not transform or handle exceptions, and repository/JPA save failures are propagated to the caller. Keep the existing empty-candidates and multi-chunk behavior unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/com/opensource/docgrid/domain/rag/repository/ResponseCitationRepository.java`:
- Around line 7-8: Document the ResponseCitationRepository interface with a
class-level Javadoc describing its role, responsibilities, and scope boundary as
the persistence repository for ResponseCitation entities, while keeping the
existing JpaRepository inheritance unchanged.
In
`@src/test/java/com/opensource/docgrid/domain/rag/service/command/ResponseCitationCommandServiceTest.java`:
- Around line 53-68: Strengthen the saveAll test by configuring
entityManager.getReference for each candidate to return distinct DocumentChunk
mocks, then assert each captured ResponseCitation from
responseCitationCommandService.saveAll has the corresponding chunk association.
Keep the existing citation field assertions and verify the expected chunk IDs
are passed to getReference.
---
Nitpick comments:
In `@docs/design/kangcheolung-`#73-response-citation-save.md:
- Around line 143-150: Update the “에러 케이스 정리” section for
ResponseCitationCommandService to state that it does not transform or handle
exceptions, and repository/JPA save failures are propagated to the caller. Keep
the existing empty-candidates and multi-chunk behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 31f9c033-c2c3-40d0-af4e-1b6389f420e5
📒 Files selected for processing (5)
docs/design/kangcheolung-#73-response-citation-save.mdsrc/main/java/com/opensource/docgrid/domain/rag/entity/ResponseCitation.javasrc/main/java/com/opensource/docgrid/domain/rag/repository/ResponseCitationRepository.javasrc/main/java/com/opensource/docgrid/domain/rag/service/command/ResponseCitationCommandService.javasrc/test/java/com/opensource/docgrid/domain/rag/service/command/ResponseCitationCommandServiceTest.java
| public interface ResponseCitationRepository extends JpaRepository<ResponseCitation, Long> { | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
신규 저장소 인터페이스의 역할과 경계를 Javadoc으로 명시해 주세요.
As per coding guidelines, 새로 만든 인터페이스에는 역할·책임·경계를 설명하는 클래스 수준 주석이 필요합니다.
제안 변경
+/**
+ * ResponseCitation 엔티티의 영속화를 담당하는 저장소.
+ *
+ * 조회·저장 규칙은 Spring Data JPA에 위임하며 도메인 로직은 포함하지 않는다.
+ */
public interface ResponseCitationRepository extends JpaRepository<ResponseCitation, Long> {
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public interface ResponseCitationRepository extends JpaRepository<ResponseCitation, Long> { | |
| } | |
| /** | |
| * ResponseCitation 엔티티의 영속화를 담당하는 저장소. | |
| * | |
| * 조회·저장 규칙은 Spring Data JPA에 위임하며 도메인 로직은 포함하지 않는다. | |
| */ | |
| public interface ResponseCitationRepository extends JpaRepository<ResponseCitation, Long> { | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/main/java/com/opensource/docgrid/domain/rag/repository/ResponseCitationRepository.java`
around lines 7 - 8, Document the ResponseCitationRepository interface with a
class-level Javadoc describing its role, responsibilities, and scope boundary as
the persistence repository for ResponseCitation entities, while keeping the
existing JpaRepository inheritance unchanged.
Source: Coding guidelines
entityManager.getReference()가 항상 null을 반환하도록 mocking되어 있어 잘못된 chunkId가 전달돼도 테스트가 통과하던 문제를 수정한다. 후보별로 서로 다른 DocumentChunk mock을 반환하도록 하고, 저장된 citation의 chunk가 올바르게 매핑됐는지 검증을 추가한다.
🔍️ 작업 내용
✨ 상세 설명
RAG 블록 Issue 4 구현입니다. Issue 3(#71)에서 저장한 rag_responses가 실제로 어떤 chunk를 근거로 썼는지 response_citations에 구조화해서 저장합니다.
ResponseCitationRepository,ResponseCitationCommandService신규 구현PromptBuilder가 사용한 것과 동일한List<VectorSearchCandidate>순서를 그대로 재사용해 citation_order/citation_label 부여 (별도 라벨 재계산 없음)SearchResultCommandService.saveAll()과 동일하게entityManager.getReference()로 불필요한 SELECT 없이 chunk FK 연결search_result_id는 이번 이슈에서 채우지 않음(null) —SearchResultCommandService.saveAll()이 저장된 SearchResult를 반환하지 않아 이 시점에는 알 수 없음, Issue 5에서 채울 예정ResponseCitation엔티티 필드별 주석 보강상세 설계 배경은
docs/design/kangcheolung-#73-response-citation-save.md참고해주세요.🛠️ 추후 리팩토링 및 고도화 계획
SearchResultCommandService.saveAll()을List<SearchResult>반환으로 바꿔서search_result_id채우기RagFacade로SearchFacade/SearchController와 실제 연결📸 스크린샷 (선택)
N/A
💬 리뷰 요구사항
search_result_id를 Issue 5로 미룬 판단이 적절한지ResponseCitationCommandService로 바꾼 것에 이견 없는지Summary by CodeRabbit
새 기능
[1],[2]형식의 라벨을 자동으로 생성합니다.문서
테스트