Feature/rag/#37#46
Conversation
- rag pipeline fastapi에서 처리 - langchain과 결합 - elasticsearch 데이터 저장 for(keyword, vector)
- 백엔드에서는 rag 검색만 진행 - 키워드(파일원본,제목,본문)검색+백터검색 3/7 - unstructed io 관련설정 제거
There was a problem hiding this comment.
Pull request overview
This PR implements a FastAPI-based RAG (Retrieval-Augmented Generation) service separation, migrating document processing from the Java Spring Boot core service to a dedicated Python microservice. The implementation includes hybrid search (BM25 + vector similarity), filename-based search enhancement, and improved local development setup.
Key Changes:
- Separates RAG pipeline into standalone FastAPI service with LangChain and Ollama integration
- Adds filename-based search field with 3x weighting for improved document retrieval
- Implements paragraph-based chunking and PyMuPDF document parsing
- Configures local development environment with HTTP-mode Elasticsearch
Reviewed changes
Copilot reviewed 37 out of 61 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| rag/requirements.txt | Python dependencies for FastAPI RAG service |
| rag/app/services/*.py | Core RAG services: parsing, chunking, embedding, indexing, and search |
| rag/app/api/v1/*.py | FastAPI endpoints for document processing, search, and content retrieval |
| rag/app/config/settings.py | Pydantic-based configuration management |
| rag/Dockerfile | Container definition for RAG service |
| docker-compose.yml | Replaces unstructured-api with FastAPI RAG service |
| core/src/main/java/com/opencontext/service/SearchService.java | Adds filename field to search query with 3x boost |
| core/src/main/java/com/opencontext/service/IndexingService.java | Stores originalFilename in metadata for search |
| core/src/main/java/com/opencontext/controller/SourceController.java | Integrates with RAG service via REST API |
| core/src/main/resources/application*.yml | Configuration updates for RAG service integration |
| core/src/main/java/com/opencontext/config/SecurityConfig.java | Temporarily disables API authentication |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["*"], # In production, restrict to specific origins | ||
| allow_credentials=True, | ||
| allow_methods=["*"], | ||
| allow_headers=["*"], | ||
| ) |
There was a problem hiding this comment.
The CORS middleware is configured to allow all origins with 'allow_origins=["*"]'. While the comment acknowledges this should be restricted in production, having permissive CORS in code increases the risk it will be deployed to production. Consider using environment-based configuration to enforce proper CORS settings.
|
|
||
| Pipeline: | ||
| 1. Download file from presigned URL | ||
| 2. Parse document (Unstructured.io) |
There was a problem hiding this comment.
The comment states 'Parse document (Unstructured.io)' but the code is actually using PyMuPDF for parsing. This is misleading and should be updated to reflect the actual implementation.
| 2. Parse document (Unstructured.io) | |
| 2. Parse document (PyMuPDF) |
| title: str = Field( | ||
| ..., | ||
| description="Section heading or title (from H1 header)" |
There was a problem hiding this comment.
The field description states 'Section heading or title (from H1 header)' but the actual implementation extracts the title from the first line or first 50 characters of a paragraph, not from H1 headers. This misleading documentation should be updated to match the actual behavior.
| elementType: str = Field( | ||
| default="TitleBasedChunk", | ||
| description="Type of chunk (TitleBasedChunk for H1-split chunks)" | ||
| ) |
There was a problem hiding this comment.
The field description states 'Type of chunk (TitleBasedChunk for H1-split chunks)' with a default value of 'TitleBasedChunk', but the actual implementation uses 'ParagraphChunk' as the element type (line 88 in chunking.py). This inconsistency between the model default and actual usage should be corrected.
| profiles: | ||
| active: dev | ||
|
|
||
| # Database Configuration (Development) |
There was a problem hiding this comment.
The comment incorrectly describes the configuration as 'Docker' when it's actually for local development based on the values (localhost URLs). The profile is also set to 'dev' on line 6. Update the comment to accurately reflect this is a development configuration.
| import logging | ||
|
|
||
| from app.config.settings import settings | ||
| from app.utils.exceptions import RagServiceException, rag_exception_handler |
There was a problem hiding this comment.
Import of 'rag_exception_handler' is not used.
| Internal API called by core/ service after file upload. | ||
| """ | ||
| import logging | ||
| from fastapi import APIRouter, HTTPException |
There was a problem hiding this comment.
Import of 'HTTPException' is not used.
| from fastapi import APIRouter, HTTPException | |
| from fastapi import APIRouter |
| from app.models.responses import ProcessResponse | ||
| from app.services.parsing import DocumentParsingService | ||
| from app.services.chunking import ChunkingService | ||
| from app.services.embedding import EmbeddingService |
There was a problem hiding this comment.
Import of 'EmbeddingService' is not used.
| from app.services.embedding import EmbeddingService |
| from app.services.parsing import DocumentParsingService | ||
| from app.services.chunking import ChunkingService | ||
| from app.services.embedding import EmbeddingService | ||
| from app.services.indexing import IndexingService |
There was a problem hiding this comment.
Import of 'IndexingService' is not used.
| from app.services.indexing import IndexingService |
| Provides accurate token counting for content retrieval with truncation support. | ||
| """ | ||
| import tiktoken | ||
| from typing import Optional |
There was a problem hiding this comment.
Import of 'Optional' is not used.
|
RAG 리팩토링, 검색 정확도 개선, 문서화까지 고생하셨습니다! |
📋 요약
RAG 시스템을 FastAPI로 분리하고, 로컬 개발 환경을 개선하며, 파일명 기반 검색 기능을 강화했습니다.
✨ 주요 변경사항
1. RAG 서비스 분리 및 리팩토링
2. 로컬 개발 환경 구축
3. MCP 서버 통합
4. 문서화 개선
5. 검색 기능 강화
6. 의존성 정리
🔧 기술 스택
📊 검색 개선 효과
Before:
After:
예시:
🧪 테스트
📝 관련 이슈
Closes [BACKEND] RAG서버를 SPIRNG에서 분리하기 #37
🚀 배포 후 작업
리뷰 포인트: