Skip to content
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

feat : upgrade to spring boot 3.4.1 & polish #134

Merged
merged 2 commits into from
Dec 24, 2024
Merged

Conversation

rajadilipkolli
Copy link
Owner

No description provided.

@rajadilipkolli rajadilipkolli self-assigned this Dec 24, 2024
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Warning

Rate limit exceeded

@rajadilipkolli has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 26f9680 and 913f95a.

📒 Files selected for processing (1)
  • rag/rag-springai-openai-llm/src/main/java/com/learning/ai/llmragwithspringai/config/AppConfig.java (1 hunks)

Walkthrough

This pull request introduces modifications to a Spring AI-based RAG (Retrieval-Augmented Generation) application. The changes primarily focus on updating the AIChatService class to use a ChatClient.Builder for initialization, modifying the application properties for OpenAI embeddings and PgVector schema, and updating the PostgreSQL container version in the test configuration. These alterations reflect updates in the underlying library and configuration approach.

Changes

File Change Summary
rag/.../AIChatService.java - Constructor now accepts ChatClient.Builder instead of ChatClient
- Updated method for retrieving AI response content
- Modified method chaining for chat options
rag/.../application.properties - Added OpenAI embeddings property
- Added PgVector schema initialization
- Commented out response format configuration
rag/.../TestLlmRagWithSpringAiApplication.java - Updated PostgreSQL container Docker image from pg16 to pg17

Sequence Diagram

sequenceDiagram
    participant Client
    participant AIChatService
    participant ChatClientBuilder
    participant VectorStore
    participant OpenAI

    Client->>AIChatService: Initialize with ChatClient.Builder
    AIChatService->>ChatClientBuilder: Create aiClient
    ChatClientBuilder-->>AIChatService: Configured ChatClient
    Client->>AIChatService: Send prompt
    AIChatService->>VectorStore: Retrieve context
    AIChatService->>OpenAI: Call with prompt
    OpenAI-->>AIChatService: Return response
    AIChatService-->>Client: Return AI-generated content
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Code Refinement 🌟

Builders rise, old ways take flight,
ChatClient's dance now crisp and tight
PgVector schemas bloom with grace,
Embeddings spark in AI's embrace
Hop, hop, through lines of change so bright!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
rag/rag-springai-openai-llm/src/main/resources/application.properties (1)

Line range hint 5-5: Secure the OpenAI API key configuration

The OpenAI API key is currently set to 'demo'. In a production environment, this should be externalized and secured.

Consider:

  1. Using environment variables: ${OPENAI_API_KEY}
  2. Using a secure configuration service
  3. Adding this property to .gitignore and providing a template file

Example:

-spring.ai.openai.api-key=demo
+spring.ai.openai.api-key=${OPENAI_API_KEY}
🧹 Nitpick comments (2)
rag/rag-springai-openai-llm/src/main/resources/application.properties (2)

12-14: Consider documenting the embedding model choice

The configuration enables OpenAI embeddings with the text-embedding-3-small model, which is appropriate for RAG applications. However, consider adding a comment explaining why this model was chosen over alternatives (e.g., cost vs. performance trade-offs).

Add a comment like:

spring.ai.openai.embedding.enabled=true
+# text-embedding-3-small offers good balance between cost and performance for RAG
spring.ai.openai.embedding.options.model=text-embedding-3-small

Line range hint 17-19: Consider schema initialization strategy

The spring.ai.vectorstore.pgvector.initialize-schema=true setting will automatically initialize the PgVector schema. While this is convenient for development, consider these points:

  1. For production environments, schema initialization should be handled through proper database migration tools
  2. This setting could potentially affect existing data if the schema already exists

Consider using a database migration tool like Flyway or Liquibase for schema management in production environments. Would you like me to provide an example migration script?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c04d756 and 26f9680.

⛔ Files ignored due to path filters (1)
  • rag/rag-springai-openai-llm/pom.xml is excluded by !**/*.xml
📒 Files selected for processing (3)
  • rag/rag-springai-openai-llm/src/main/java/com/learning/ai/llmragwithspringai/service/AIChatService.java (2 hunks)
  • rag/rag-springai-openai-llm/src/main/resources/application.properties (1 hunks)
  • rag/rag-springai-openai-llm/src/test/java/com/learning/ai/llmragwithspringai/TestLlmRagWithSpringAiApplication.java (1 hunks)
🔇 Additional comments (7)
rag/rag-springai-openai-llm/src/main/java/com/learning/ai/llmragwithspringai/service/AIChatService.java (5)

6-6: Import usage is correct.

The newly added import statement for ChatClient is appropriate and aligns with the updated constructor signature.


41-42: Consider thread-safety of the cloned builder.

The builder pattern is a clean solution for creating aiClient. However, the clone() operation suggests multiple usages could occur. If you plan to share this chatClientBuilder among multiple components, verify that cloning does not introduce concurrency issues or shared mutable state that might affect subsequent builds. Otherwise, no immediate concerns are apparent.


50-50: Confirm the correctness of getText() usage.

Switching from Document::getContent to Document::getText is generally fine, assuming getText() is indeed the intended method for retrieving textual content. Validate that the returned value matches expectations, especially if you anticipate structured or formatted data.


57-57: Function-building approach is clear and concise.

Updating from the previous withFunction naming to function("currentDateFunction") is consistent with typical builder patterns and ensures clarity. This helps maintain a straightforward, fluent API style.


59-59: Improved read-flow with chained call.

Using aiClient.prompt(prompt).call().content() provides a clean, streamlined syntax. This makes the flow of prompt creation and response retrieval more readable. Ensure any exception handling or custom logic (e.g., fallback behavior) is still properly accounted for in this shortened chain.

rag/rag-springai-openai-llm/src/test/java/com/learning/ai/llmragwithspringai/TestLlmRagWithSpringAiApplication.java (1)

16-16: Verify compatibility with the updated Docker image version.

Upgrading to pgvector/pgvector:pg17 may introduce changes in the underlying PostgreSQL engine. Please confirm that there are no backward-incompatible differences and that any schema or data migration steps have been addressed.

✅ Verification successful

Docker image version mismatch detected between test and runtime environments

The verification reveals that while the test is using pgvector/pgvector:pg17, the actual runtime environment in docker-compose.yml is still using pgvector/pgvector:pg16. This version mismatch could lead to inconsistencies between test and production environments.

  • docker/docker-compose.yml: Update the image version from pg16 to pg17 to maintain consistency
  • Update the version references in both README files to reflect the new version

Let's verify if there are any version-specific configurations or schema changes:


Coordinated version upgrade detected across the codebase

The verification reveals that the upgrade to pgvector/pgvector:pg17 is part of a coordinated update across the codebase. Multiple components are already using or being updated to use pg17:

  • embeddingstores/pgvector-springai/docker/docker-compose.yml: Using pg17
  • embeddingstores/pgvector-langchain4j/docker/docker-compose.yml: Using pg17
  • rag/rag-langchain4j-AllMiniLmL6V2-llm/docker/docker-compose.yml: Using pg17
  • chatbot/chatbot-ollama-springai/docker/docker-compose.yml: Using pg17
  • Test configurations in multiple modules are already using pg17

Only one file still references pg16:

  • rag/rag-springai-openai-llm/docker/docker-compose.yml: Still using pg16

Let's verify if there are any version-specific schema changes:


Safe to upgrade - no version-specific schema dependencies found

The verification shows that the upgrade from pg16 to pg17 is safe for the following reasons:

  1. No version-specific SQL scripts or schema definitions were found in the codebase
  2. The pgvector schema initialization is handled automatically through Spring Boot properties (initialize-schema=true)
  3. Most of the codebase is already using pg17 in both test and runtime environments
  4. The configuration properties are version-agnostic and focus on generic features like dimensions and initialization

Action needed:

  • Update rag/rag-springai-openai-llm/docker/docker-compose.yml to use pgvector/pgvector:pg17 for consistency with the rest of the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify whether there are any migration steps needed for pg16 -> pg17

# 1) Search for references to the old Docker image or version-specific features
rg "pgvector/pgvector:pg16" 

# 2) Check for sql scripts or migration scripts that reference version-based functionality
rg -A 5 "CREATE EXTENSION IF NOT EXISTS vector" 

# 3) Inspect relevant test or config files that might rely on version 16
ast-grep --pattern $'class $_ {\n $$$\n}' 

Length of output: 433


Script:

#!/bin/bash
# Check for any PostgreSQL or pgvector specific configurations
rg -l "postgresql" .

# Look for SQL files or database initialization scripts
fd -e sql

# Search for vector-related configurations
rg "vector" -A 5 -g "!*.md"

Length of output: 45526


Script:

#!/bin/bash
# Check for any SQL migration scripts or schema definitions
fd -e sql -e ddl

# Look for any pgvector extension or schema initialization code
rg -p "CREATE EXTENSION|CREATE TABLE.*vector" --type-add 'props:*.properties'

# Check for any version-specific configuration properties
rg "pgvector" --type-add 'props:*.properties' -g "*.properties"

Length of output: 1053

rag/rag-springai-openai-llm/src/main/resources/application.properties (1)

10-10: Verify the impact of removing responseFormat configuration

The removal of responseFormat=json_object configuration might affect how responses are handled. Please ensure this change is compatible with your response handling logic.

Run this script to check for JSON response handling in the codebase:

@rajadilipkolli rajadilipkolli merged commit b037b5c into main Dec 24, 2024
2 of 3 checks passed
@rajadilipkolli rajadilipkolli deleted the rag-openapi branch December 24, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant