Welcome to this hands-on workshop, where you'll learn to implement sophisticated context-engineering patterns. Context Engineering is the practice of strategically designing, structuring, and optimizing the information provided to AI models (particularly LLMs) to achieve desired outputs. It goes beyond simple prompt engineering by considering the entire context window and how data is organized, presented, and sequenced to maximize model performance. In this workshop, you will learn how to implement this using Java, LangChain4J, and Redis.
LLMs have limited context windows and no inherent memory between conversations. Without proper context engineering:
- Models lose track of conversation history
- Responses lack relevant domain knowledge
- Token limits are exceeded, causing failures
- Repeated API calls increase costs
This workshop teaches you patterns to solve these challenges systematically.
By the end of this workshop, you'll have built a complete AI application featuring:
- LLM integration using OpenAI, Spring Boot, and LangChain4J
- Vector embeddings for semantic search with a chunking strategy
- RAG (Retrieval-Augmented Generation) with knowledge bases
- Dual-layer memory architecture (short-term and long-term memory)
- Query compression techniques for efficient context retrieval
- Content Reranking to optimize the relevance of retrieved information
- Few-shot learning pattern for improved generated responses
- Dynamic context window management based on token limits
- Semantic caching to optimize performance and reduce LLM costs
- Basic understanding of Java programming
- Basic knowledge of LLMs and AI concepts
- Familiarity with command-line interfaces
- Basic understanding of Docker and Git
- Familiarity with RESTful APIs
| Account | Description | Cost |
|---|---|---|
| OpenAI | LLM that will power the responses for the AI application | Free trial sufficient |
| Redis Cloud | Semantic caching service powered by Redis LangCache | Free tier sufficient |
💡 Note on OpenAI costs: While OpenAI occasionally offers free trial credits to new accounts, this workshop assumes pay-as-you-go pricing. The estimated cost of $1-3 covers all 9 labs. You can monitor your usage in the OpenAI dashboard to track costs in real-time.
This workshop has an estimated duration of 2 hours and is organized into 9 progressive labs, each building on the previous one. Each lab introduces a specific context engineering challenge, which is then addressed in the subsequent lab.
| Lab | Topic | Duration | Branch |
|---|---|---|---|
| 1 | Set up and deploy the AI application | 25 mins | lab-1-starter |
| 2 | Enabling short-term memory with chat memory | 10 mins | lab-2-starter |
| 3 | Knowledge base with embeddings, parsers, and splitters | 10 mins | lab-3-starter |
| 4 | Implementing basic RAG with knowledge base data | 15 mins | lab-4-starter |
| 5 | Enabling on-demand context management for memories | 10 mins | lab-5-starter |
| 6 | Implementing query compression and context reranking | 15 mins | lab-6-starter |
| 7 | Implementing a few-shot into the system prompt design | 05 mins | lab-7-starter |
| 8 | Enabling token management to handle token limits | 05 mins | lab-8-starter |
| 9 | Implementing semantic caching for conversations | 25 mins | lab-9-starter |
Each lab also contains a corresponding lab-X-solution branch with the completed code for reference. You can use this branch to compare your current implementation using git diff {lab-X-solution}. Alternatively, you can switch to the solution branch at any time during the lab if you are falling behind or to get unstuck.
git clone https://github.com/redis-developer/context-engineering-workshop-java.gitEnsure you have Java, Maven, Node.js, Docker, and Git installed. You can check their versions with:
java -version
mvn -version
npm --version
docker --version
git --versionNavigate to the cloned repository.
cd context-engineering-workshop-javaClick on the link for Lab 1: Set up and deploy the AI application to get started!
- Alexa Skill using Context Engineering
- LangChain4J Documentation
- Redis Agent Memory Server
- Redis LangCache Documentation
- OpenAI API Reference
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Ricardo Ferreira — @riferrei
This project is licensed under the MIT License.