https://github.com/felipesalvadordev/spring-ai-samples
Use of Spring AI with ChatClient, Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) with Spring AI to build more accurate and contextually aware applications.
https://github.com/felipesalvadordev/spring-ai-samples
chatclient chatgpt4 llm openai rag springai
Last synced: about 1 month ago
JSON representation
Use of Spring AI with ChatClient, Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) with Spring AI to build more accurate and contextually aware applications.
- Host: GitHub
- URL: https://github.com/felipesalvadordev/spring-ai-samples
- Owner: felipesalvadordev
- Created: 2025-02-22T00:38:14.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-09T12:03:34.000Z (about 1 year ago)
- Last Synced: 2025-05-09T13:23:37.021Z (about 1 year ago)
- Topics: chatclient, chatgpt4, llm, openai, rag, springai
- Language: Java
- Homepage:
- Size: 1.16 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring AI Samples
A demonstration project showcasing Retrieval Augmented Generation (RAG) implementation using Spring AI and OpenAI's GPT models. This application enables intelligent document querying by combining the power of Large Language Models (LLMs) with local document context.
A demonstration of chat memory using MessageChatMemoryAdvisor.
And a demonstration of how to parse the AI's response into a structured Java object.
## Overview
This project demonstrates how to:
- Ingest PDF documents into a vector database
- Perform semantic searches using Spring AI
- Augment LLM responses with relevant document context
- Create an API endpoint for document-aware chat interactions
- Build a ChatClient with a MessageChatMemoryAdvisor that uses InMemoryChatMemory. This setup allows our chatbot to remember previous interactions.
- Build a book recommendation system using Spring AI and Spring Boot and parse the AI's response into a structured Java object.
- Build an image analyser with OpenAiChatModel
Query the API using curl or your preferred HTTP client:
```bash
curl http://localhost:8080/advisor-using-vector-store
```
The response will include context from your documents along with the LLM's analysis.
```bash
curl http://localhost:8080/chatbot?question="What was the first car with line production?"
```
The response will be a chatbot with memory capabilities. A chatID also can be sent as a parameter to remain in the same conversation context.
```bash
curl http://localhost:8080/advisor-with-memory?message="Whats my name?"
```
The chatbot remembers the user's name from the first interaction and can recall it in the second interaction
```bash
curl http://localhost:8080/book-recomendations
```
This code demonstrates how to automatically parse the AI's response into a structured Java object whitout JSON mapping.
```bash
curl http://localhost:8080/image-explained
```
Analyze images, answer questions about them, classify them, and generate summaries based on provided instructions.
## Architecture Anatomy of RAG and LLM process
- **Document Processing**: Uses Spring AI's PDF document reader to parse documents into manageable chunks
- **Vector Storage**: Utilizes PGVector for efficient similarity searches
- **Context Retrieval**: Automatically retrieves relevant document segments based on user queries
- **Response Generation**: Combines document context with GPT-4's capabilities for informed responses
## References
https://www.danvega.dev/blog/getting-started-with-spring-ai-rag
https://www.danvega.dev/blog/spring-ai-chat-memory
https://www.danvega.dev/blog/ai-java-developers
https://www.baeldung.com/spring-ai-anthropics-claude-models
https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html