# AIDocumentLibraryChat

A demonstration project that uses Spring AI with Ollama or OpenAI to chat with documents stored in a library, embedding them into a PostgreSQL vector database to answer questions from their content.

AIDocumentLibraryChat is a sample project showing how to use Spring AI to chat with documents uploaded to a library. Uploaded documents are stored in both a normal and a vector-enabled PostgreSQL database, and an AI model creates embeddings from document chunks that are stored alongside them.

When a user asks a question, it is turned into an embedding and used to query the vector database; the document with the lowest distance is loaded and used to ask the AI model for an answer grounded in that document's content, with a link back to the source document to limit hallucination and support further research. The backend uses Spring Boot, Spring AI, PostgreSQL with its vector, hstore and uuid-ossp extensions, and Liquibase for migrations, and can call OpenAI or locally run Ollama models such as LLava for image description or sqlcoder for SQL generation. The frontend is built with Angular, Angular Material and TypeScript, and the project also includes an MCP client and server so an assistant can request book and movie information through Spring AI's MCP support.

It is licensed under Apache-2.0.

Website: https://github.com/Angular2Guy/AIDocumentLibraryChat
