Retrieval with LangChain4j and Ollama
This example shows a small local retrieval flow using Ollama embeddings and an in-memory embedding store.
Three short notes are ingested, the best match is retrieved for the question, and the retrieved note is the only external knowledge the model receives.
Requirements
- Java 21+
- Maven 3.9+
- Ollama installed locally
- A pulled chat model such as
llama3.2:1b - A pulled embedding model such as
nomic-embed-text
Steps for running this example in the shell
- Start Ollama and pull the models:
bash
ollama serve
ollama pull llama3.2:1b
ollama pull nomic-embed-text- Run the application:
bash
mvn compile exec:javaOutput
Use the self-service portal to reset your password, then sign in again.