Skip to content

[Hotfix] 하이브리드 검색 후속 이슈 보완#37

Merged
kimssirr merged 2 commits into
devfrom
hotfix/#31-review-followups
May 5, 2026
Merged

[Hotfix] 하이브리드 검색 후속 이슈 보완#37
kimssirr merged 2 commits into
devfrom
hotfix/#31-review-followups

Conversation

@kimssirr

@kimssirr kimssirr commented May 5, 2026

Copy link
Copy Markdown
Contributor

유형

  • Feat
  • Fix
  • Design
  • Docs
  • Chore
  • Hotfix

작업 내용

하이브리드 검색 인덱스 개선 이후 리뷰에서 지적된 후속 이슈를 보완합니다.

search_tsvector 생성 경로에서 불필요한 추가 UPDATE를 제거하고, 기존 데이터 backfill을 batch 단위로 나누어 처리하도록 수정했습니다. 또한 query expansion fallback에서 이미 생성한 embedding을 재사용해 중복 embedding API 호출을 방지했습니다.

변경 사항 (있다면)

  • chunk 생성 시 search_tsvector를 INSERT 시점에 함께 저장하도록 변경
  • chunk INSERT 후 별도 UPDATE ... FROM regulation_document로 검색 벡터를 갱신하던 흐름 제거
  • migration backfill을 전체 row 단일 UPDATE에서 batch 단위 UPDATE로 변경
  • keywords 검색 텍스트를 JSONB text cast 대신 keyword 원소 공백 결합 방식으로 변경
  • query expansion fallback에서 기존 query_embedding 재사용
  • 중복 embedding API 호출 방지 테스트 추가
  • search_tsvector 생성 방식 관련 repository 테스트 수정

리뷰 포인트

  • chunk 생성 시 search_tsvector를 INSERT 시점에 계산하는 방식이 적절한지
  • migration의 batch backfill 방식이 운영 DB 적용 관점에서 충분한지
  • 일반 CREATE INDEX 유지 판단이 현재 운영 방식에 적절한지
    • regulation_chunk 쓰기는 사용자 채팅 경로가 아니라 관리자성 규정 적재/수정 경로입니다.
    • RDS 반영 시점에는 규정 적재 작업을 수행하지 않을 예정입니다.
  • query expansion fallback에서 같은 query에 대해 embedding을 재사용하는 조건이 안전한지

테스트

  • 로컬 실행 확인
  • /docs 수동 확인
  • pytest 실행

스크린샷

image

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a search_tsvector column to the regulation_chunk table to support full-text search, updating the repository to populate this field during record creation and removing the previous post-creation refresh logic. Additionally, it optimizes the chat service by reusing query embeddings when the expanded query is identical to the retrieval query. A performance concern was identified in the database migration, where the batched backfill logic may cause sequential scans on each iteration; it is recommended to use ID-based range processing instead.

Comment on lines +32 to +38
WITH target_chunks AS (
SELECT regulation_chunk_id
FROM regulation_chunk
WHERE search_tsvector IS NULL
ORDER BY regulation_chunk_id
LIMIT :batch_size
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

search_tsvector IS NULL 조건을 사용하여 배치를 나누고 있는데, 현재 search_tsvector 컬럼에 인덱스가 없는 상태에서 매 배치마다 전체 테이블을 스캔(Sequential Scan)하게 됩니다. 데이터 양이 많을 경우 뒤로 갈수록 성능이 급격히 저하되는 O(N^2) 문제가 발생할 수 있습니다. regulation_chunk_id의 범위를 기반으로 업데이트하거나, 마지막으로 처리한 ID를 추적하여 다음 배치의 시작점으로 사용하는 방식을 권장합니다.

@kimssirr kimssirr force-pushed the hotfix/#31-review-followups branch 2 times, most recently from e813dd9 to 6c2bf2e Compare May 5, 2026 11:47
@kimssirr kimssirr force-pushed the hotfix/#31-review-followups branch from 6c2bf2e to 9dc4c0a Compare May 5, 2026 12:09
@kimssirr kimssirr merged commit 9008103 into dev May 5, 2026
1 check passed
@kimssirr kimssirr changed the title [Hotfix] [Hotfix] 하이브리드 검색 후속 이슈 보완 May 5, 2026
1024andrew added a commit that referenced this pull request May 7, 2026
* fix: update chat api contract for backend integration

* fix: fix/#37 오타/들여쓰기 수정 + 안쓰는 source_url= 삭제
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.

1 participant