{"id":25874792,"url":"https://github.com/tzolov/spring-ai-cli-chatbot","last_synced_at":"2025-09-01T18:42:54.592Z","repository":{"id":280252072,"uuid":"870688978","full_name":"tzolov/spring-ai-cli-chatbot","owner":"tzolov","description":"A command-line chatbot built with Spring AI that demonstrates Retrieval-Augmented Generation (RAG) and conversational memory capabilities.","archived":false,"fork":false,"pushed_at":"2024-10-11T16:39:42.000Z","size":2247,"stargazers_count":39,"open_issues_count":2,"forks_count":12,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T03:06:42.675Z","etag":null,"topics":["chatmemory","rag","spring-boot","springai"],"latest_commit_sha":null,"homepage":"https://docs.spring.io/spring-ai/reference/index.html","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tzolov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-10T13:44:52.000Z","updated_at":"2025-04-13T00:34:02.000Z","dependencies_parsed_at":"2025-03-02T09:34:27.654Z","dependency_job_id":"8cfc9a72-0b30-4cfc-a708-8d73da503f02","html_url":"https://github.com/tzolov/spring-ai-cli-chatbot","commit_stats":null,"previous_names":["tzolov/spring-ai-cli-chatbot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzolov%2Fspring-ai-cli-chatbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzolov%2Fspring-ai-cli-chatbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzolov%2Fspring-ai-cli-chatbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzolov%2Fspring-ai-cli-chatbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tzolov","download_url":"https://codeload.github.com/tzolov/spring-ai-cli-chatbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997085,"owners_count":21195799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatmemory","rag","spring-boot","springai"],"created_at":"2025-03-02T09:29:44.938Z","updated_at":"2025-04-15T03:06:48.534Z","avatar_url":"https://github.com/tzolov.png","language":"Java","readme":"# Spring AI Chat Bot CLI\n\nThis Spring Boot, CLI, application demonstrates how to create an AI-powered chatbot with domain-specific knowledge (in this case, about Hurricane Milton) using Spring AI, Retrieval-Augmented Generation RAG and Conversational Memory.\n\nApplication uses the [Hurricane_Milton](https://en.wikipedia.org/wiki/Hurricane_Milton) wikipage saved as `wikipedia-hurricane-milton-page.pdf`.\n\n## ChatBot Application\n\nquick build run the app.\n```\n./mvnw clean install\n./mvnw spring-boot:run\n```\n\n## Auto-configurations\n\n### AI Model\n\nBy default, this project uses OpenAI's Spring Boot starter (`spring-ai-openai-spring-boot-starter`). \nHowever, you can easily switch to any other supported AI model.\nThe `pom.xml` file prvidew few alternative AI model dependencies. (Note: Most models, except Ollama/Llama3.2, require an API key for access.)\nConfigure your API key and other model properties in the `application.properties` file.\nThe [Chat Model API](https://docs.spring.io/spring-ai/reference/api/chatmodel.html) lists all supported modesl.\n\n### Vector Store\n\nThe project is configured to use Chroma (`spring-ai-chroma-store-spring-boot-starter`) as a vector store, running locally:\nA `docker-compose.yaml` file is provided to start a local Chroma instance.\nThe project is configured with Spring Boot Docker Compose integration for easy setup. (e.g. you don't have to start the docker-compose manually).\nFind more about [Vector Stores](https://docs.spring.io/spring-ai/reference/api/vectordbs.html)\n\n### PDF Document Processing\n\nPDF document reading capability is enabled through the `spring-ai-pdf-document-reader` dependency.\nFind more about the Spring AI [document indexing support](https://docs.spring.io/spring-ai/reference/api/etl-pipeline.html)\n\n## CommandLineRunner\n\n`CommandLineRunner` created by the `cli` Bean, is a Spring Boot interface for running code after the application context is loaded.\nThis is the entry point of our chatbot the application.\n\n## Vector Store Loading\n\n```java\nvectorStore.add(new TokenTextSplitter().split(new PagePdfDocumentReader(hurricaneDocs).read()));\n```\n\nThis line reads a PDF document about Hurricane Milton, splits it into tokens, and adds it to a vector store. This is part of the RAG setup, allowing the chatbot to retrieve relevant information.\n\n## ChatClient Configuration\n\n```java\nvar chatClient = chatClientBuilder\n    .defaultSystem(\"You are useful assistant, expert in hurricanes.\")\n    .defaultAdvisors(new MessageChatMemoryAdvisor(new InMemoryChatMemory()))\n    .defaultAdvisors(new QuestionAnswerAdvisor(vectorStore))\n    .build();\n```\n\nHere, a `ChatClient` is built with the following configurations:\n- A system prompt defining the assistant's role\n- A `MessageChatMemoryAdvisor` for maintaining conversation history\n- A `QuestionAnswerAdvisor` that uses the vector store for RAG capabilities\n\n## Chat Loop\n\n```java\ntry (Scanner scanner = new Scanner(System.in)) {\n    while (true) {\n        System.out.print(\"\\nUSER: \");\n        System.out.println(\"\\nASSISTANT: \" + \n            chatClient.prompt(scanner.nextLine())\n                .call()\n                .content());\n    }\n}\n```\n\nThis creates an infinite loop that:\n1. Prompts the user for input\n2. Sends the user's input to the chatbot\n3. Prints the chatbot's response\n\nThe chatbot uses the configured `ChatClient`, which incorporates the conversation history and RAG capabilities to generate responses.\n\n## Key Features\n\n1. **RAG Implementation**: The application uses a vector store to implement RAG, allowing the chatbot to retrieve relevant information from the loaded document.\n2. **Conversation Memory**: The `MessageChatMemoryAdvisor` enables the chatbot to remember previous interactions within the conversation.\n3. **PDF Document Processing**: The application can read and process PDF documents, making the information available to the chatbot.\n4. **Interactive Console Interface**: The application provides a simple console-based interface for interacting with the chatbot.\n","funding_links":[],"categories":["Code \u0026 Examples"],"sub_categories":["CLI Applications","Code Examples"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftzolov%2Fspring-ai-cli-chatbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftzolov%2Fspring-ai-cli-chatbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftzolov%2Fspring-ai-cli-chatbot/lists"}