Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.DS_Store
*.local
*.local
.env
build/data/minio
build/data/postgres
build/data/weaviate
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
.PHONY: run-dev test test-servers test-client test-all \
test-api-gateway test-document-service test-eureka

run:
@echo "Starting Docker services..."
docker compose --env-file .env -f build/docker-compose.yml up --build


run-dev:
@echo "Starting all services in parallel..."
@parallel --line-buffer --colsep '\t' --tagstring '[{1}]' '{2}' ::: \
'docker docker compose -f docker-compose.dev.yaml up --build' \
'docker docker compose -f build/docker-compose.dev.yaml up --build' \
'client cd client && bun i && bun dev' \
'eureka cd server/eureka && watchexec -r -e java,yml,yaml ./gradlew bootRun' \
'api-gateway cd server/api-gateway && watchexec -r -e java,yml,yaml ./gradlew bootRun' \
Expand Down
21 changes: 21 additions & 0 deletions build/config/postgres/initdb.d/00_create_multiple_databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
-- Create databases for services that need persistent storage
CREATE DATABASE lecture_db;
CREATE DATABASE document_db;

-- Grant privileges to the default user
GRANT ALL PRIVILEGES ON DATABASE lecture_db TO $POSTGRES_USER;
GRANT ALL PRIVILEGES ON DATABASE document_db TO $POSTGRES_USER;

-- Optional: Create service-specific users (uncomment if needed)
-- CREATE USER lecture_user WITH PASSWORD 'lecture_pass';
-- CREATE USER document_user WITH PASSWORD 'document_pass';

-- GRANT ALL PRIVILEGES ON DATABASE lecture_db TO lecture_user;
-- GRANT ALL PRIVILEGES ON DATABASE document_db TO document_user;
EOSQL

echo "Multiple databases created successfully!"
Empty file added build/data/.gitkeep
Empty file.
20 changes: 4 additions & 16 deletions docker-compose.dev.yaml → build/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- CLUSTER_HOSTNAME=node1
- TRANSFORMERS_INFERENCE_API=http://transformers:8080
volumes:
- weaviate_data:/var/lib/weaviate
- ./data/weaviate:/var/lib/weaviate

minio:
image: minio/minio:RELEASE.2025-05-24T17-08-30Z
Expand All @@ -24,7 +24,7 @@ services:
- MINIO_ROOT_PASSWORD=minioadmin
command: server /data --console-address ":9001"
volumes:
- minio_data:/data
- ./data/minio:/data

postgres:
image: postgres:15-alpine
Expand All @@ -35,17 +35,5 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=document_db
volumes:
- postgres_data:/var/lib/postgresql/data

transformers:
image: semitechnologies/transformers-inference:cpu-2.4.0
environment:
- MODEL_NAME=sentence-transformers/all-MiniLM-L6-v2
- NUM_THREADS=4
networks:
- spring-cloud-network

volumes:
weaviate_data:
minio_data:
postgres_data:
- ./data/postgres:/var/lib/postgresql/data
- ./config/postgres/initdb.d:/docker-entrypoint-initdb.d:ro
28 changes: 12 additions & 16 deletions docker-compose.yaml → build/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
eureka:
build:
context: ./server/eureka
context: ../server/eureka
ports:
- "8761:8761"
environment:
Expand All @@ -14,7 +14,7 @@ services:

api-gateway:
build:
context: ./server/api-gateway
context: ../server/api-gateway
ports:
- "8080:8080"
environment:
Expand All @@ -29,7 +29,7 @@ services:

document-service:
build:
context: ./server/document-service
context: ../server/document-service
environment:
- SPRING_APPLICATION_NAME=document-service
- SERVER_PORT=8080
Expand All @@ -43,6 +43,7 @@ services:
- POSTGRES_DB=document_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- OPENAI_API_KEY=${OPENAI_API_KEY}
depends_on:
- eureka
- weaviate
Expand All @@ -53,7 +54,7 @@ services:

chat-service:
build:
context: ./server/chat-service
context: ../server/chat-service
environment:
- SPRING_APPLICATION_NAME=chat-service
- SERVER_PORT=8082
Expand All @@ -67,7 +68,7 @@ services:

lecture-service:
build:
context: ./server/lecture-service
context: ../server/lecture-service
environment:
- SPRING_APPLICATION_NAME=lecture-service
- SERVER_PORT=8083
Expand Down Expand Up @@ -96,7 +97,7 @@ services:
- OPENAI_APIKEY=${OPENAI_API_KEY}
- CLUSTER_HOSTNAME=node1
volumes:
- weaviate_data:/var/lib/weaviate
- ./data/weaviate:/var/lib/weaviate
networks:
- spring-cloud-network

Expand All @@ -110,7 +111,7 @@ services:
- MINIO_ROOT_PASSWORD=minioadmin
command: server /data --console-address ":9001"
volumes:
- minio_data:/data
- ./data/minio:/data
networks:
- spring-cloud-network

Expand All @@ -123,14 +124,14 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
volumes:
- postgres_data:/var/lib/postgresql/data
- ./scripts/create-multiple-databases.sh:/docker-entrypoint-initdb.d/create-multiple-databases.sh
- ./data/postgres:/var/lib/postgresql/data
- ./config/postgres/initdb.d:/docker-entrypoint-initdb.d:ro
networks:
- spring-cloud-network

client:
build:
context: ./client
context: ../client
ports:
- "3000:80"
depends_on:
Expand All @@ -143,9 +144,4 @@ networks:
driver: bridge

spring-cloud-network:
driver: bridge

volumes:
weaviate_data:
minio_data:
postgres_data:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public Mono<ResponseEntity<String>> getServiceApiDocs(@PathVariable String servi
.map(body -> ResponseEntity.ok()
.header("Content-Type", "application/json")
.body(body))
.onErrorReturn(ResponseEntity.notFound().build());
.onErrorResume(err -> webClient.get()
.uri(serviceUrl + "/openapi.json")
.retrieve()
.bodyToMono(String.class)
.map(body -> ResponseEntity.ok()
.header("Content-Type", "application/json")
.body(body))
.onErrorReturn(ResponseEntity.notFound().build())
);
}
}
12 changes: 9 additions & 3 deletions server/api-gateway/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ springdoc:
- url: /api/document/v3/api-docs
name: "Document Service"
primaryName: "Document Service"
- url: /api/hello/v3/api-docs
name: "Hello Service"
primaryName: "Hello Service"
- url: /api/lecture/v3/api-docs
name: "Lecture Service"
primaryName: "Lecture Service"
- url: /api/quiz/v3/api-docs
name: "Quiz Service"
primaryName: "Quiz Service"
- url: /api/chat/v3/api-docs
name: "Chat Service"
primaryName: "Chat Service"
api-docs:
enabled: true
path: /v3/api-docs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.tum.team_sigma.document_service.dto.DocumentResponse;
import de.tum.team_sigma.document_service.dto.DocumentUploadRequest;
import de.tum.team_sigma.document_service.dto.SimilarChunkResponse;
import de.tum.team_sigma.document_service.service.DocumentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand Down Expand Up @@ -231,18 +232,18 @@ public ResponseEntity<List<DocumentResponse>> searchDocuments(
@Operation(summary = "Search similar documents", description = "Find similar documents using vector similarity search")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Similar documents found",
content = @Content(schema = @Schema(implementation = DocumentResponse.class))),
content = @Content(schema = @Schema(implementation = SimilarChunkResponse.class))),
@ApiResponse(responseCode = "500", description = "Internal server error")
})
public ResponseEntity<List<DocumentResponse>> searchSimilarDocuments(
public ResponseEntity<List<SimilarChunkResponse>> searchSimilarDocuments(
@Parameter(description = "Search query for similarity", required = true)
@RequestParam("q") String query,
@Parameter(description = "Maximum number of results")
@RequestParam(value = "limit", defaultValue = "10") int limit) {

try {
List<DocumentResponse> documents = documentService.searchSimilarDocuments(query, limit);
return ResponseEntity.ok(documents);
List<SimilarChunkResponse> chunks = documentService.searchSimilarDocuments(query, limit);
return ResponseEntity.ok(chunks);
} catch (Exception e) {
logger.error("Failed to search similar documents with query: {}", query, e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.tum.team_sigma.document_service.dto;

public class SimilarChunkResponse {
private Long documentId;
private Integer chunkIndex;
private String text;

public SimilarChunkResponse() {}

public SimilarChunkResponse(Long documentId, Integer chunkIndex, String text) {
this.documentId = documentId;
this.chunkIndex = chunkIndex;
this.text = text;
}

public Long getDocumentId() {
return documentId;
}

public void setDocumentId(Long documentId) {
this.documentId = documentId;
}

public Integer getChunkIndex() {
return chunkIndex;
}

public void setChunkIndex(Integer chunkIndex) {
this.chunkIndex = chunkIndex;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}
Loading
Loading