A Spring Boot REST API that ingests a Java codebase and answers natural language questions about it using Spring AI and Gemini.
- Java 21
- Gradle
- A Gemini API key (free tier, Google AI Studio)
Set your Gemini API key as an environment variable before running:
export GEMINI_API_KEY=your_key_hereThe application.yml reads it via ${GEMINI_API_KEY}.
./gradlew bootRunThe app starts on http://localhost:8080.
Ingests a local codebase into the vector store. Point it at any directory containing Java source files.
curl -X POST "http://localhost:8080/ingest?repo=/path/to/your/project"Response:
{ "filesProcessed": 20, "chunksStored": 13 }The vector store is in-memory. Re-run /ingest after every restart.
Supported file types: .java, .kt, .xml, .yml, .yaml, .gradle, .properties, .md
RAG mode. Retrieves relevant chunks from the vector store and answers the question using that context. Streams the response as Server-Sent Events.
curl -N "http://localhost:8080/ask?q=What+does+IngestService+do"Use this for focused, factual questions about specific classes or behaviour.
Agentic mode. Gemini autonomously decides which tools to call and in what order until it can construct a precise answer. Streams the response as Server-Sent Events.
curl -N "http://localhost:8080/investigate?q=Trace+the+full+ingest+flow"Use this for open-ended questions that require reading across multiple files.
Available tools Gemini can call:
findFiles(keyword)- find files by name or pathreadFile(path)- read the full content of a filesemanticSearch(query)- search the vector store for relevant chunkslistMethods(path)- list method signatures in a Java file
gemini-2.0-flashis not available on the free tier in the EU. Usegemini-1.5-flash-latestinstead.- The embedding model (
all-MiniLM-L6-v2) downloads ~90MB on first boot and is cached after that. /askand/investigateboth stream tokens as they arrive. Usecurl -Nto see them live.