Skip to content

Use of Spring AI with ChatClient, Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) withSpring AI to build more accurate and contextually aware applications.

Notifications You must be signed in to change notification settings

felipesalvadordev/spring-ai-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Query the API using curl or your preferred HTTP client:

curl http://localhost:8080/advisor

The response will include context from your documents along with the LLM's analysis.

curl http://localhost:8080/chatbot?question="Wha 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.

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.

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

About

Use of Spring AI with ChatClient, Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) withSpring AI to build more accurate and contextually aware applications.

Topics

Resources

Stars

Watchers

Forks

Languages