-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/rag/#37 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/rag/#37 #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,8 +242,12 @@ public ResponseEntity<CommonResponse<String>> deleteSourceDocument(@PathVariable | |
| } | ||
| } | ||
|
|
||
| @Value("${app.rag.service.url:http://open-context-rag:8001}") | ||
| private String ragServiceUrl; | ||
|
|
||
| /** | ||
| * Executes the document ingestion pipeline asynchronously. | ||
| * ๋ฌธ์ ์์ง ํ์ดํ๋ผ์ธ์ ๋น๋๊ธฐ์ ์ผ๋ก ์คํํฉ๋๋ค. | ||
| * RAG ์๋น์ค (FastAPI)๋ฅผ ํธ์ถํ์ฌ ์ฒ๋ฆฌํฉ๋๋ค. | ||
| */ | ||
| @Async | ||
| @Transactional | ||
|
|
@@ -253,41 +257,58 @@ public void processIngestionPipeline(UUID documentId) { | |
| try { | ||
| // 1. Update status to PARSING | ||
| fileStorageService.updateDocumentStatus(documentId, IngestionStatus.PARSING); | ||
|
|
||
| // 2. Parse document using Unstructured API | ||
| var parsedElements = documentParsingService.parseDocument(documentId); | ||
| log.info("Document parsing completed: id={}, elements={}", documentId, parsedElements.size()); | ||
|
|
||
| // 3. Update status to CHUNKING | ||
| fileStorageService.updateDocumentStatus(documentId, IngestionStatus.CHUNKING); | ||
|
|
||
| // 4. Split into chunks | ||
| var structuredChunks = chunkingService.createChunks(documentId, parsedElements); | ||
| log.info("Document chunking completed: id={}, chunks={}", documentId, structuredChunks.size()); | ||
| // 2. Get document info | ||
| SourceDocument document = sourceDocumentRepository.findById(documentId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.SOURCE_DOCUMENT_NOT_FOUND, | ||
| "Document not found: " + documentId)); | ||
|
|
||
| // 3. Generate presigned MinIO URL (valid for 1 hour) | ||
| String presignedUrl = fileStorageService.generatePresignedUrl(document.getFileStoragePath()); | ||
| log.debug("Generated presigned URL for document: id={}, filename={}", documentId, document.getOriginalFilename()); | ||
|
|
||
| // 4. Call RAG service | ||
| com.opencontext.dto.ProcessDocumentRequest request = com.opencontext.dto.ProcessDocumentRequest.builder() | ||
| .documentId(documentId.toString()) | ||
| .fileUrl(presignedUrl) | ||
| .filename(document.getOriginalFilename()) | ||
| .fileType(document.getFileType()) | ||
| .build(); | ||
|
|
||
| // 5. Update status to EMBEDDING | ||
| fileStorageService.updateDocumentStatus(documentId, IngestionStatus.EMBEDDING); | ||
|
|
||
| // 6. Generate embeddings | ||
| var embeddedChunks = embeddingService.generateEmbeddings(documentId, structuredChunks); | ||
| log.info("Embedding generation completed: id={}, embedded_chunks={}", documentId, embeddedChunks.size()); | ||
| String ragProcessUrl = ragServiceUrl + "/api/v1/process"; | ||
| log.info("Calling RAG service: url={}, documentId={}", ragProcessUrl, documentId); | ||
|
|
||
| // 7. Update status to INDEXING | ||
| fileStorageService.updateDocumentStatus(documentId, IngestionStatus.INDEXING); | ||
|
|
||
| // 8. Store in Elasticsearch and PostgreSQL | ||
| indexingService.indexChunks(documentId, embeddedChunks); | ||
| log.info("Document indexing completed: id={}", documentId); | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.setContentType(MediaType.APPLICATION_JSON); | ||
| HttpEntity<com.opencontext.dto.ProcessDocumentRequest> requestEntity = new HttpEntity<>(request, headers); | ||
|
|
||
| ResponseEntity<com.opencontext.dto.ProcessDocumentResponse> response = restTemplate.postForEntity( | ||
| ragProcessUrl, | ||
| requestEntity, | ||
| com.opencontext.dto.ProcessDocumentResponse.class | ||
| ); | ||
|
Comment on lines
+285
to
+289
|
||
|
|
||
| // 5. Check response | ||
| if (response.getBody() != null && response.getBody().isSuccess()) { | ||
| com.opencontext.dto.ProcessDocumentResponse ragResponse = response.getBody(); | ||
|
|
||
| // Update status to COMPLETED | ||
| fileStorageService.updateDocumentStatusToCompleted(documentId); | ||
|
|
||
| log.info("RAG processing completed: documentId={}, chunks={}, status={}", | ||
| documentId, ragResponse.getChunksProcessed(), ragResponse.getStatus()); | ||
| } else { | ||
| String errorMessage = response.getBody() != null ? response.getBody().getErrorMessage() : "Unknown error"; | ||
| throw new BusinessException(ErrorCode.INGESTION_PIPELINE_FAILED, | ||
| "RAG service processing failed: " + errorMessage); | ||
| } | ||
|
|
||
| // 9. Update status to COMPLETED | ||
| fileStorageService.updateDocumentStatusToCompleted(documentId); | ||
|
|
||
| log.info("Ingestion pipeline completed successfully: documentId={}", documentId); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Ingestion pipeline failed: documentId={}", documentId, e); | ||
| fileStorageService.updateDocumentStatusToError(documentId, e.getMessage()); | ||
| throw new BusinessException(ErrorCode.INGESTION_PIPELINE_FAILED, | ||
| throw new BusinessException(ErrorCode.INGESTION_PIPELINE_FAILED, | ||
| "Ingestion pipeline failed: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.opencontext.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Request DTO for RAG service document processing endpoint. | ||
| * Sent from core/ to rag/ FastAPI service. | ||
| */ | ||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class ProcessDocumentRequest { | ||
|
|
||
| /** | ||
| * Document UUID | ||
| */ | ||
| private String documentId; | ||
|
|
||
| /** | ||
| * Presigned MinIO URL for downloading the file | ||
| */ | ||
| private String fileUrl; | ||
|
|
||
| /** | ||
| * Original filename | ||
| */ | ||
| private String filename; | ||
|
|
||
| /** | ||
| * File type (PDF, MARKDOWN, TEXT) | ||
| */ | ||
| private String fileType; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.opencontext.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Response DTO from RAG service document processing endpoint. | ||
| * Received by core/ from rag/ FastAPI service. | ||
| */ | ||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class ProcessDocumentResponse { | ||
|
|
||
| /** | ||
| * Whether processing completed successfully | ||
| */ | ||
| private boolean success; | ||
|
|
||
| /** | ||
| * Document UUID | ||
| */ | ||
| private String documentId; | ||
|
|
||
| /** | ||
| * Number of chunks created and indexed | ||
| */ | ||
| private int chunksProcessed; | ||
|
|
||
| /** | ||
| * Processing status (COMPLETED or ERROR) | ||
| */ | ||
| private String status; | ||
|
|
||
| /** | ||
| * Error message if processing failed | ||
| */ | ||
| private String errorMessage; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,14 @@ spring: | |||||||||
| application: | ||||||||||
| name: open-context-core | ||||||||||
|
|
||||||||||
| # Database Configuration (Docker) | ||||||||||
| profiles: | ||||||||||
| active: dev | ||||||||||
|
|
||||||||||
| # Database Configuration (Development) | ||||||||||
|
||||||||||
| datasource: | ||||||||||
| url: jdbc:postgresql://postgres:5432/opencontext | ||||||||||
| username: user | ||||||||||
| password: password | ||||||||||
| url: jdbc:postgresql://localhost:5432/opencontext | ||||||||||
| username: postgres | ||||||||||
| password: 3482 | ||||||||||
|
Comment on lines
+11
to
+12
|
||||||||||
| username: postgres | |
| password: 3482 | |
| username: ${DB_USERNAME:postgres} | |
| password: ${DB_PASSWORD:} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security authentication has been disabled with a temporary comment. This is a critical security vulnerability that leaves the API completely unprotected. If this is genuinely needed for development, it should be controlled via a configuration property, not commented out in code. The comment states 'RE-ENABLE BEFORE PRODUCTION' but there's no guarantee this will happen - consider using a feature flag or environment-based configuration instead.