An AI-powered study assistant built with Spring Boot, Spring AI, Ollama, PostgreSQL and PGVector.
The application allows users to upload study notes and PDF documents and ask questions about their content. It uses RAG (Retrieval-Augmented Generation) and AI Tool Calling to retrieve relevant information from the uploaded notes before generating an answer.
- Upload PDF study material
- Add text-based study notes
- Automatically split documents into smaller chunks
- Generate embeddings using Ollama
- Store document embeddings in PostgreSQL with PGVector
- Perform semantic similarity search
- Ask questions about uploaded notes
- AI Tool Calling using Spring AI
- Retrieve relevant notes automatically when answering questions
- REST APIs for adding, searching and asking questions
User
|
v
Spring Boot REST API
|
+------------+------------+
| |
v v
Upload PDF Ask Question
| |
v v
PDF Reader ChatClient
| |
v v
Text Splitting Ollama Qwen Model
| |
v |
Embeddings |
| |
v |
PostgreSQL + PGVector |
^ |
| |
+---- Semantic Search ----+
|
v
Relevant Note Chunks
When a PDF is uploaded, the application extracts its text using Spring AI PDF document readers.
The extracted document is divided into smaller chunks using TokenTextSplitter.
Each document chunk is converted into a numerical vector called an embedding.
The project uses the Ollama embedding model:
nomic-embed-text
The generated embeddings and document information are stored in PostgreSQL using PGVector.
PGVector allows the application to perform similarity searches on the stored document embeddings.
When a user asks a question, the question is sent to the AI model.
The AI model has access to a custom tool called searchNotes.
The model can call this tool when it needs information from the user's study notes.
The searchNotes tool performs a similarity search in PGVector.
It retrieves the most relevant document chunks related to the user's question.
The retrieved information is returned to the AI model.
The model then generates the final answer using the retrieved study material.
This is the RAG flow used in the project.
Question
|
v
AI Model
|
| Tool Call
v
searchNotes
|
v
Vector Similarity Search
|
v
PGVector
|
v
Relevant Document Chunks
|
v
AI Model
|
v
Final Answer
Spring AI Tool Calling is used to allow the AI model to interact with the application's search functionality.
The searchNotes method is exposed as a tool:
@Tool(description = "Search the user's study notes for relevant information")
public String searchNotes(String question)The AI model can decide when to call this tool to retrieve information from the user's notes.
This makes the application more agent-like because the model can choose to use the available tool instead of the application manually performing the search every time.
- Java 21
- Spring Boot
- Spring AI
- Ollama
- Qwen 2.5 3B
- Nomic Embed Text
- PostgreSQL
- PGVector
- Maven
- REST API
qwen2.5:3b
nomic-embed-text
Required Ollama commands:
ollama pull qwen2.5:3b
ollama pull nomic-embed-textPOST /addAdds study notes to the vector store.
Example request:
{
"title": "Computer Networks",
"content": "CRC stands for Cyclic Redundancy Check. It is an error detection technique."
}GET /search?question=What%20is%20CRC?This endpoint directly performs a semantic similarity search and returns relevant note content.
GET /ask?question=What%20is%20CRC?This endpoint sends the question to the AI model.
The AI model can use the searchNotes tool to retrieve relevant information from the stored notes.
POST /uploadThe PDF is processed, split into chunks and stored in the vector database.
Suppose a Java PDF is uploaded containing information about inheritance.
The user asks:
What is inheritance in Java?
The application performs the following steps:
- The AI receives the question.
- The AI decides whether it needs information from the study notes.
- The AI calls the
searchNotestool. searchNotesperforms a similarity search in PGVector.- Relevant chunks from the uploaded PDF are retrieved.
- The retrieved information is provided to the AI.
- The AI generates the final answer.
Example flow:
User Question
|
v
AI Model
|
v
searchNotes Tool
|
v
PGVector Similarity Search
|
v
Relevant PDF Content
|
v
AI Model
|
v
Final Answer
ai-notes-assistant
|
+-- src
| |
| +-- main
| | |
| | +-- java
| | | |
| | | +-- controller
| | | | |
| | | | +-- ChatController.java
| | | | +-- EmbeddingController.java
| | | | +-- NoteRequest.java
| | | | +-- VectorController.java
| | | |
| | | +-- service
| | | |
| | | +-- NoteService.java
| | |
| | +-- resources
| | |
| | +-- application.properties
| |
| +-- test
|
+-- pom.xml
+-- README.md
+-- mvnw
+-- mvnw.cmd
Before running the project, install:
- Java 21
- Maven
- PostgreSQL
- PGVector
- Ollama
Make sure PostgreSQL and Ollama are running.
Also make sure the required Ollama models are available:
ollama listRequired models:
qwen2.5:3b
nomic-embed-text
Clone the repository:
git clone https://github.com/devbbhatt/ai-notes-assistant.gitOpen the project:
cd ai-notes-assistantStart the application on Windows:
mvnw.cmd spring-boot:runOn Linux or macOS:
./mvnw spring-boot:runThe application will run on:
http://localhost:8080
This project was built as a practical learning project to understand:
- Spring AI
- RAG
- Vector databases
- Embeddings
- Semantic search
- Ollama integration
- AI Tool Calling
- PDF document processing
- Spring Boot REST APIs
- Integration of AI models with backend applications
- Web frontend for PDF upload and chat
- Multiple document management
- Conversation memory
- Page number source references
- User authentication
- User-specific document storage
- Streaming AI responses
- Support for additional document formats
Dev Bhatt
GitHub: