Skip to content

[Feat] RAG 프롬프트 조립 PromptBuilder + Ollama 로컬 세팅 - #66

Merged
kangcheolung merged 6 commits into
developfrom
feature/65
Jul 27, 2026
Merged

[Feat] RAG 프롬프트 조립 PromptBuilder + Ollama 로컬 세팅#66
kangcheolung merged 6 commits into
developfrom
feature/65

Conversation

@kangcheolung

@kangcheolung kangcheolung commented Jul 27, 2026

Copy link
Copy Markdown
Member

🔍️작업 내용

✨ 상세 설명

RAG 블록 Issue 1(F-RAG-01) 구현입니다.

  • Ollama를 docker-compose에 등록하고 qwen2.5:3b 모델 로컬 세팅
  • 검색 후보(VectorSearchCandidate) 목록을 출처 라벨([1], [2]...) 포함 프롬프트로 조립하는 PromptBuilder 구현
  • search_results/document_chunks 재조회 없이 SearchFacade가 만든 후보 리스트를 그대로 재사용
  • README에 embedding-server/ollama 로컬 실행 방법 추가

설계 배경과 로컬 검증 로그는 docs/design/kangcheolung-#65-rag-prompt-builder.md 참고해주세요.

🛠️추후 리팩토링 및 고도화 계획

  • Issue 2(OllamaClient 연동)에서 실제 프롬프트로 호출 테스트 후, 언어 섞임 현상이 재현되면 PromptBuilder 지시문에 "한국어로 답변하세요" 추가 검토
  • PromptBuilder는 아직 어디에도 연결되지 않은 독립 컴포넌트 — Issue 5(RagFacade)에서 실제로 연결됨

📸 스크린샷 (선택)

image

💬 리뷰 요구사항

  • 인용 라벨을 후보 리스트 인덱스 순서로 그대로 재사용하는 설계(별도 매핑 구조체 없음)가 괜찮은지
  • "검색 결과 0건(NO_CONTEXT)이면 LLM 호출 생략" 판단을 PromptBuilder가 아니라 이후 RagFacade(Issue 5)에 위임한 책임 분리가 적절한지

Summary by CodeRabbit

  • 새 기능

    • 로컬 Ollama RAG LLM 서버를 Docker Compose로 실행할 수 있습니다.
    • 검색 결과 문서와 질문을 기반으로 출처가 포함된 RAG 프롬프트를 생성합니다.
    • 문서 페이지 정보가 있을 경우 프롬프트에 페이지 번호를 함께 표시합니다.
  • 문서 및 설정

    • 임베딩 서버와 Ollama의 설치, 실행, 모델 준비 절차를 README에 추가했습니다.
    • 기본 서버 주소와 필요 시 주소를 변경하는 환경변수 안내를 제공했습니다.
  • 테스트

    • 문서 출처 표시, 페이지 번호 생략, 검색 결과가 없는 경우의 프롬프트 생성을 검증합니다.

RAG 답변 생성에 쓸 로컬 LLM(qwen2.5:3b)을 Ollama로 구동하기 위해
docker-compose에 서비스를 등록하고 application.yml에 접속 주소 기본값을 추가한다.
검색 후보(VectorSearchCandidate) 목록과 질문 텍스트를 받아, 출처 라벨([1], [2]...)과
환각 방지 지시문이 포함된 LLM 프롬프트 문자열을 조립한다.
search_results/document_chunks 재조회 없이 SearchFacade가 이미 만든 후보 목록을 그대로 재사용한다.
정상 케이스(라벨 순서/문서정보 포함), 페이지 번호 없는 경우, 지시문/질문 항상 포함
3개 케이스를 검증한다.
로컬 DB 실행 방법만 있던 README에 embedding-server, ollama 서비스의
build/run 순서와 헬스체크 확인법을 추가한다.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kangcheolung, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 34e17935-2ed2-4ffc-803d-eff92a3ffd39

📥 Commits

Reviewing files that changed from the base of the PR and between 09b035d and 954ab01.

📒 Files selected for processing (2)
  • docker-compose.yml
  • docs/design/kangcheolung-#65-rag-prompt-builder.md
📝 Walkthrough

Walkthrough

로컬 Ollama 서비스와 접속 설정이 추가되고, 검색 후보를 출처 라벨이 포함된 RAG 프롬프트로 변환하는 PromptBuilder 및 단위 테스트가 구현되었습니다. 실행 절차와 설계 범위도 문서화되었습니다.

Changes

RAG 로컬 실행과 프롬프트 조립

Layer / File(s) Summary
Ollama 실행 환경 설정
docker-compose.yml, src/main/resources/application.yml, .env.example, README.md, docs/design/...
Ollama 컨테이너, ollama-data 볼륨, 헬스체크, OLLAMA_SERVER_URL 오버라이드와 로컬 모델 실행 절차가 추가되었습니다.
후보 기반 프롬프트 조립
src/main/java/.../PromptBuilder.java, src/test/java/.../PromptBuilderTest.java, docs/design/...
후보를 [1], [2] 형식의 출처 라인으로 조립하고 pageNo가 null인 경우 페이지 표기를 생략하며, 빈 후보 처리와 질문 포함 동작을 테스트합니다.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested labels: ✨ Feature

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 PromptBuilder 구현과 Ollama 로컬 세팅이라는 핵심 변경을 간결하게 요약합니다.
Description check ✅ Passed 필수 섹션들이 모두 포함되어 있고 작업 내용, 상세 설명, 계획, 리뷰 요구사항이 충분히 작성되었습니다.
Linked Issues check ✅ Passed #65의 Ollama 등록, base-url 설정, PromptBuilder 구현, 라벨 부여, 문서화 요구사항이 모두 반영되었습니다.
Out of Scope Changes check ✅ Passed 변경 범위는 설정, 문서, PromptBuilder, 테스트로 한정되어 보이며 링크된 목표와 무관한 변경은 보이지 않습니다.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/65

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/main/java/com/opensource/docgrid/domain/rag/service/PromptBuilder.java (1)

24-31: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

순차 처리 단계에 번호 주석을 보강하세요.

이 메서드는 지시문 초기화 → 후보 인용 조립 → 질문 추가의 순차 흐름이므로 각 단계에 간결한 1., 2., 3. 주석을 추가해 구현 의도를 유지하세요.

As per path instructions, Java 순차 실행 흐름에는 관련 단계 번호 주석을 추가해야 합니다.

🤖 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/service/PromptBuilder.java`
around lines 24 - 31, In PromptBuilder.build, add concise sequential comments
marking the three execution stages: 1. instruction initialization, 2. candidate
citation assembly, and 3. query appending. Keep the existing logic and ordering
unchanged.

Source: Path instructions

🤖 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 `@docker-compose.yml`:
- Around line 67-68: Update the Ollama port mapping in the compose configuration
to bind host port 11434 exclusively to the loopback interface, using the
existing ports entry. Preserve container port 11434 while changing the host
binding to 127.0.0.1; do not expose it on all host interfaces.

In `@docs/design/kangcheolung-`#65-rag-prompt-builder.md:
- Line 34: 문서의 두 fenced code block에 언어 식별자가 없어 MD040 경고가 발생합니다. 해당 Markdown 코드
블록을 모두 언어 식별자 text를 사용하는 fenced block으로 변경해 문서 lint를 통과시키세요.
- Around line 245-249: Revise the “원인 분석” and “판단 및 대응 방향” sections to avoid
concluding from a single greeting that the behavior is an inherent qwen2.5:3b
characteristic. Explicitly state the uncertainty and possible causes, including
language instructions, generation settings, and model behavior, then defer the
conclusion until reproduction with an actual Korean RAG prompt; retain the
existing milestone assessment without asserting an unverified root cause.

---

Nitpick comments:
In `@src/main/java/com/opensource/docgrid/domain/rag/service/PromptBuilder.java`:
- Around line 24-31: In PromptBuilder.build, add concise sequential comments
marking the three execution stages: 1. instruction initialization, 2. candidate
citation assembly, and 3. query appending. Keep the existing logic and ordering
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: ebb204f4-bd53-49b3-8dec-ab21bb054b07

📥 Commits

Reviewing files that changed from the base of the PR and between cc8a4ff and 09b035d.

📒 Files selected for processing (7)
  • .env.example
  • README.md
  • docker-compose.yml
  • docs/design/kangcheolung-#65-rag-prompt-builder.md
  • src/main/java/com/opensource/docgrid/domain/rag/service/PromptBuilder.java
  • src/main/resources/application.yml
  • src/test/java/com/opensource/docgrid/domain/rag/service/PromptBuilderTest.java

Comment thread docker-compose.yml Outdated
Comment thread docs/design/kangcheolung-#65-rag-prompt-builder.md Outdated
Comment thread docs/design/kangcheolung-#65-rag-prompt-builder.md Outdated
- Ollama HTTP API가 인증 없는 로컬 개발용 엔드포인트라 127.0.0.1로만 바인딩하도록 수정
- 설계 문서 흐름도 코드 블록에 언어 식별자(text) 추가 (MD040 lint 대응)
- 언어 섞임 현상 원인 분석 문구를 단정적 결론에서 미확정/재검증 필요로 수정
@kangcheolung
kangcheolung merged commit 9ad3c34 into develop Jul 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Ollama 세팅 + PromptBuilder 구현

1 participant