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: 4 additions & 2 deletions mflix/server/java-spring/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Replace with your MongoDB Atlas connection string or local MongoDB URI
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/sample_mflix?retryWrites=true&w=majority

# Voyage AI Configuration
# Optional: Voyage AI Configuration
# API key for Voyage AI embedding model (required for Vector Search)
VOYAGE_API_KEY=your_voyage_api_key
# Get your API key from https://www.voyageai.com/
# Uncomment the following line to enable vector search
# VOYAGE_API_KEY=your-api-key

# Server Configuration
# Port on which the Spring Boot application will run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,10 @@ public List<VectorSearchResult> vectorSearchMovies(String query, Integer limit)
}

// Check if Voyage API key is configured
if (voyageApiKey == null || voyageApiKey.trim().isEmpty()) {
if (voyageApiKey == null || voyageApiKey.trim().isEmpty() ||
voyageApiKey.equals("your_voyage_api_key")) {
throw new ValidationException(
"Vector search unavailable: VOYAGE_API_KEY not configured. Please add your API key to the application.properties file"
"Vector search unavailable: VOYAGE_API_KEY not configured. Please add your Voyage AI API key to the .env file"
);
}

Expand Down Expand Up @@ -978,6 +979,10 @@ private List<Double> generateVoyageEmbedding(String text, String apiKey) throws

// Check for successful response
if (response.statusCode() != 200) {
// Handle authentication errors specifically
if (response.statusCode() == 401) {
throw new IOException("Invalid Voyage AI API key. Please check your VOYAGE_API_KEY in the .env file");
}
throw new IOException("Voyage AI API returned status code " + response.statusCode() + ": " + response.body());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ void testVectorSearchMovies_MissingApiKey() {
assertThrows(ValidationException.class, () -> movieService.vectorSearchMovies("test query", 10));
}

@Test
@DisplayName("Should throw ValidationException when API key is placeholder value in vector search")
void testVectorSearchMovies_PlaceholderApiKey() {
// Arrange
ReflectionTestUtils.setField(movieService, "voyageApiKey", "your_voyage_api_key");

// Act & Assert
assertThrows(ValidationException.class, () -> movieService.vectorSearchMovies("test query", 10));
}

@Test
@DisplayName("Should enforce limit constraints in vector search")
void testVectorSearchMovies_LimitConstraints() {
Expand Down