feat: implement structured chunk data structures and development security config - #9
Conversation
- Implement StructuredChunk with embedding support and metadata - Add hierarchical navigation with breadcrumbs and level tracking - Create response objects for search results and content delivery - Include token counting for content length management
- Allow unrestricted access to API documentation endpoints - Enable MCP API access without authentication - Configure stateless session management for REST APIs - Prepare foundation for API key authentication on admin endpoints
- Configure PostgreSQL connection with optimized pool settings - Add Elasticsearch, Ollama, and MinIO service endpoints - Enable Flyway baseline migration for existing databases - Set appropriate logging levels for development debugging
There was a problem hiding this comment.
Pull Request Overview
This PR implements core data structures for a structured chunk-based search system and establishes development security configuration. The changes introduce a comprehensive DTO layer with validation, Swagger documentation, and configure the application for local development.
- Implements structured chunk DTOs with embedding support and hierarchical metadata for Elasticsearch integration
- Creates API response DTOs for search results and content retrieval with token management
- Establishes development security configuration allowing unrestricted API access and Swagger UI
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| application.yml | Updates database migration strategy and adds Flyway configuration |
| TokenInfo.java | Token counting and management DTO for LLM context control |
| StructuredChunk.java | Main Elasticsearch document structure with embeddings and metadata |
| SearchResultItem.java | Search API response format with relevance scoring |
| GetContentResponse.java | Content retrieval response with token information |
| ChunkMetadata.java | Hierarchical metadata structure for document navigation |
| SecurityConfig.java | Development security configuration with unrestricted API access |
|
|
||
| log.info("Security configuration completed successfully"); | ||
| return http.build(); | ||
| } |
There was a problem hiding this comment.
The commented-out API key authentication filter import and usage on line 11 and 73 indicates incomplete security implementation. Admin APIs at /api/v1/sources/** are currently allowing unrestricted access (line 66) which poses a security risk in production environments.
| } | |
| .requestMatchers("/api/v1/sources/**").authenticated() // Require authentication (API key) | |
| // All other requests require authentication | |
| .anyRequest().authenticated() | |
| ); | |
| // Add API Key authentication filter for Admin APIs | |
| http.addFilterBefore(apiKeyAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); | |
| log.info("Security configuration completed successfully"); | |
| return http.build(); | |
| } | |
| /** | |
| * Simple API Key Authentication Filter for Admin APIs. | |
| * Checks for X-API-KEY header and authenticates if valid. | |
| */ | |
| private class ApiKeyAuthenticationFilter extends OncePerRequestFilter { | |
| private final AntPathRequestMatcher adminApiMatcher = new AntPathRequestMatcher("/api/v1/sources/**"); | |
| @Override | |
| protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | |
| throws ServletException, IOException { | |
| if (adminApiMatcher.matches(request)) { | |
| String apiKey = request.getHeader(API_KEY_HEADER); | |
| if (ADMIN_API_KEY.equals(apiKey)) { | |
| Authentication auth = new PreAuthenticatedAuthenticationToken( | |
| "admin", apiKey, Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"))); | |
| SecurityContextHolder.getContext().setAuthentication(auth); | |
| } else { | |
| response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | |
| response.getWriter().write("Unauthorized: Invalid API Key"); | |
| return; | |
| } | |
| } | |
| filterChain.doFilter(request, response); | |
| } | |
| } |
| * Generated by Qwen3-Embedding-0.6B model via Ollama. | ||
| * Uses float[] for optimal performance with Elasticsearch dense_vector type. | ||
| */ | ||
| @Schema(description = "Embedding vector for semantic search (1024 dimensions)") |
There was a problem hiding this comment.
The embedding field lacks validation to ensure it contains exactly 1024 dimensions as described in the documentation comment. Consider adding a validation annotation like @Size(min = 1024, max = 1024) to enforce the documented constraint.
| @Schema(description = "Embedding vector for semantic search (1024 dimensions)") | |
| @Schema(description = "Embedding vector for semantic search (1024 dimensions)") | |
| @jakarta.validation.constraints.Size(min = 1024, max = 1024) |
| import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
| import org.springframework.security.config.http.SessionCreationPolicy; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
| import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
There was a problem hiding this comment.
The import for UsernamePasswordAuthenticationFilter is unused since the API key authentication filter is commented out. This unused import should be removed to maintain clean code.
| import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
Yoo-SH
left a comment
There was a problem hiding this comment.
All components have been verified to function as intended. This pull request is approved for merge.
Summary
Key Implementation Notes
Major Components
DTO Layer
Security Configuration
Application Configuration
Files Added
core/src/main/java/com/opencontext/dto/StructuredChunk.java- Main document structurecore/src/main/java/com/opencontext/dto/ChunkMetadata.java- Hierarchical metadatacore/src/main/java/com/opencontext/dto/SearchResultItem.java- Search response formatcore/src/main/java/com/opencontext/dto/GetContentResponse.java- Content retrieval responsecore/src/main/java/com/opencontext/dto/TokenInfo.java- Token management infocore/src/main/java/com/opencontext/config/SecurityConfig.java- Security configurationFiles Modified
core/src/main/resources/application.yml- Development environment settingsValidation Features
All DTOs include comprehensive validation:
Related Issues
Closes #7