Skip to content

[DEV-390/BE] fix: LLM 응답이 일부만 오는 문제에 대응#637

Merged
kckc0608 merged 4 commits intodevfrom
DEV-390/feat/LLM-응답이-일부만-오는-문제에-대응
Feb 26, 2026

Hidden character warning

The head ref may contain hidden characters: "DEV-390/feat/LLM-\uc751\ub2f5\uc774-\uc77c\ubd80\ub9cc-\uc624\ub294-\ubb38\uc81c\uc5d0-\ub300\uc751"
Merged

[DEV-390/BE] fix: LLM 응답이 일부만 오는 문제에 대응#637
kckc0608 merged 4 commits intodevfrom
DEV-390/feat/LLM-응답이-일부만-오는-문제에-대응

Conversation

@kckc0608
Copy link
Collaborator

관련 이슈

close #636

작업한 내용

  • 클러스터 크기가 30을 넘어가면 30개 질문으로만 프롬프트를 생성하도록 수정
  • LLM 응답으로 누락된 id는 무시하고 qna set 외래키를 업데이트 하도록 수정

PR 리뷰시 참고할 사항

참고 자료 (링크, 사진, 예시 코드 등)

@kckc0608 kckc0608 self-assigned this Feb 26, 2026
@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
web-team4-refit Ignored Ignored Preview Feb 26, 2026 5:13am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kckc0608, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 LLM(Large Language Model) 응답이 불완전하게 오는 문제를 해결하기 위해 백엔드 로직을 개선합니다. 특히, 프롬프트 생성 시 질문의 수를 제한하고, LLM 응답 처리 과정에서 누락된 카테고리 정보에 대한 견고성을 높여 시스템의 안정성과 데이터 처리의 정확성을 향상시킵니다.

Highlights

  • LLM 프롬프트 생성 로직 개선: 클러스터 크기가 30을 초과할 경우, 프롬프트 생성 시 최대 30개의 질문만 사용하도록 제한하여 LLM 응답 누락 문제를 해결했습니다.
  • 누락된 ID 처리 로직 추가: LLM 응답에서 카테고리 ID 또는 이름이 누락된 경우, 해당 항목을 건너뛰고 경고 로그를 남기도록 QuestionCategoryBatchService에 예외 처리 로직을 추가했습니다.
Changelog
  • backend/src/main/java/com/shyashyashya/refit/batch/service/QuestionCategoryBatchService.java
    • createCategories 메서드에서 categoryId 또는 categoryNamenull인 경우 처리를 건너뛰고 경고 로그를 남기도록 수정되었습니다.
  • backend/src/main/java/com/shyashyashya/refit/global/util/PromptGenerateUtil.java
    • convertToRequest 메서드에서 프롬프트 생성을 위한 질문 목록을 구성할 때, questionIds의 크기가 30을 초과하면 처음 30개의 질문만 사용하도록 로직이 변경되었습니다.
Activity
  • kckc0608 님이 PR을 생성했습니다.
  • 관련 이슈 #636을 닫습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이 PR은 LLM 응답이 부분적으로 오는 문제에 대응하기 위한 두 가지 수정을 포함합니다. 첫째, 클러스터의 질문 수가 30개를 초과할 경우 30개로 제한하여 프롬프트를 생성하도록 변경했습니다. 둘째, LLM 응답에서 누락된 ID가 있을 경우 이를 무시하고 계속 진행하도록 예외 처리를 추가했습니다.
QuestionCategoryBatchService의 변경 사항은 견고성을 높이는 좋은 수정입니다. PromptGenerateUtil의 변경 사항은 기능적으로는 맞지만, 스트림 내에서 반복적으로 리스트를 생성하고 List.contains를 사용하여 성능이 저하될 수 있습니다. 이를 개선하기 위해 Set을 사용하고 리스트 생성을 스트림 외부로 옮기는 것을 제안합니다.

I am having trouble creating individual review comments. Click here to see my feedback.

backend/src/main/java/com/shyashyashya/refit/global/util/PromptGenerateUtil.java (81-90)

high

현재 구현에서는 questionVectors 스트림의 filter 내부에서 각 questionVector에 대해 subList를 반복적으로 생성하고 있습니다. 이는 비효율적입니다. 또한 List.contains는 O(n) 시간 복잡도를 가지므로 성능 저하를 유발할 수 있습니다.

filter를 적용하기 전에 subList를 한 번만 생성하고, 빠른 조회를 위해 HashSet을 사용하는 것이 좋습니다. 이렇게 하면 contains 연산의 시간 복잡도를 평균 O(1)로 줄일 수 있습니다.

                    List<Long> questionIds = category.getQuestionDocumentIds();
                    List<Long> idsForPrompt = questionIds.size() > 30 ? questionIds.subList(0, 30) : questionIds;
                    java.util.Set<Long> idSet = new java.util.HashSet<>(idsForPrompt);
                    List<String> questions = questionVectors.stream()
                            .filter(questionVector -> idSet.contains(questionVector.getId()))
                            .map(QuestionVectorDocument::getQuestion)
                            .toList();

@kckc0608 kckc0608 merged commit 36f0024 into dev Feb 26, 2026
3 checks passed
@HIHJH HIHJH deleted the DEV-390/feat/LLM-응답이-일부만-오는-문제에-대응 branch February 26, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DEV-390/BE] fix: LLM 응답이 일부만 오는 문제에 대응

1 participant