|
| 1 | +<div align="center"> |
| 2 | +<div><img src="../assets/redis-logo.svg" style="width: 130px"> </div> |
| 3 | +<h1>Redis AI Java Resources</h1> |
| 4 | +<div align="center"> |
| 5 | + |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +</div> |
| 11 | +<div> |
| 12 | + ✨ Java-based code examples, notebooks, and resources for using Redis in AI and ML applications. ✨ |
| 13 | +</div> |
| 14 | + |
| 15 | +<div></div> |
| 16 | +<br> |
| 17 | + |
| 18 | +[**Setup**](#setup) | [**Running the Project**](#running-the-project) | [**Notebooks**](#notebooks) | [**Project Structure**](#project-structure) | [**Implementation Details**](#implementation-details) |
| 19 | + |
| 20 | +</div> |
| 21 | +<br> |
| 22 | + |
| 23 | +## Setup |
| 24 | + |
| 25 | +This project uses Docker Compose to set up a complete environment for running Java-based AI applications with Redis. The environment includes: |
| 26 | + |
| 27 | +- A Jupyter Notebook server with Java kernel support |
| 28 | +- Redis Stack (includes Redis and RedisInsight) |
| 29 | +- Pre-installed dependencies for AI/ML workloads |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) |
| 34 | +- OpenAI API key (for notebooks that use OpenAI services) |
| 35 | + |
| 36 | +### Environment Configuration |
| 37 | + |
| 38 | +1. Create a `.env` file in the project root with your OpenAI API key: |
| 39 | + |
| 40 | +``` |
| 41 | +OPENAI_API_KEY=your_openai_api_key_here |
| 42 | +``` |
| 43 | + |
| 44 | +## Running the Project |
| 45 | + |
| 46 | +1. Clone the repository (if you haven't already): |
| 47 | + |
| 48 | +```bash |
| 49 | +git clone https://github.com/redis-developer/redis-ai-resources.git |
| 50 | +cd redis-ai-resources/java-resources |
| 51 | +``` |
| 52 | + |
| 53 | +2. Start the Docker containers: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker-compose up -d |
| 57 | +``` |
| 58 | + |
| 59 | +3. Access the Jupyter environment: |
| 60 | + - Open your browser and navigate to [http://localhost:8888](http://localhost:8888) |
| 61 | + - The token is usually shown in the docker-compose logs. You can view them with: |
| 62 | + |
| 63 | + ```bash |
| 64 | + docker-compose logs jupyter |
| 65 | + ``` |
| 66 | + |
| 67 | +4. Access RedisInsight: |
| 68 | + - Open your browser and navigate to [http://localhost:8001](http://localhost:8001) |
| 69 | + - Connect to Redis using the following details: |
| 70 | + - Host: redis-java |
| 71 | + - Port: 6379 |
| 72 | + - No password (unless configured) |
| 73 | + |
| 74 | +5. When finished, stop the containers: |
| 75 | + |
| 76 | +```bash |
| 77 | +docker-compose down |
| 78 | +``` |
| 79 | + |
| 80 | +## Notebooks |
| 81 | + |
| 82 | +| Notebook | Description | |
| 83 | +| --- | --- | |
| 84 | +| [RAG/spring_ai_redis_rag.ipynb](./RAG/spring_ai_redis_rag.ipynb) | Demonstrates building a RAG-based beer recommendation chatbot using Spring AI and Redis as the vector store | |
| 85 | + |
| 86 | +## Project Structure |
| 87 | + |
| 88 | +``` |
| 89 | +java-resources/ |
| 90 | +├── .env # Environment variables (create this) |
| 91 | +├── docker-compose.yml # Docker Compose configuration |
| 92 | +├── jupyter/ # Jupyter configuration files |
| 93 | +│ ├── Dockerfile # Dockerfile for Jupyter with Java kernel |
| 94 | +│ ├── environment.yml # Conda environment specification |
| 95 | +│ ├── install.py # JJava kernel installation script |
| 96 | +│ ├── kernel.json # Kernel specification |
| 97 | +│ └── java/ # Java dependencies and configuration |
| 98 | +│ └── pom.xml # Maven project file with dependencies |
| 99 | +└── resources/ # Data files for notebooks |
| 100 | + └── beers.json.gz # Compressed beer dataset |
| 101 | +``` |
| 102 | +
|
| 103 | +## Implementation Details |
| 104 | +
|
| 105 | +### Java Jupyter Kernel |
| 106 | +
|
| 107 | +The project uses [JJava](https://github.com/dflib/jjava), a Jupyter kernel for Java based on JShell. This allows for interactive Java development in Jupyter notebooks. |
| 108 | +
|
| 109 | +Key components: |
| 110 | +
|
| 111 | +- Java 21 for modern Java features |
| 112 | +- Maven for dependency management |
| 113 | +- JJava kernel for Jupyter integration |
| 114 | +
|
| 115 | +### Spring AI Integration |
| 116 | +
|
| 117 | +The Spring AI notebooks showcase how to use Spring's AI capabilities with Redis: |
| 118 | +
|
| 119 | +- **Spring AI**: Framework for building AI-powered applications |
| 120 | +- **Redis Vector Store**: Used for storing and querying vector embeddings |
| 121 | +- **Transformer Models**: For generating embeddings locally |
| 122 | +- **RAG Pattern**: Demonstrates the Retrieval Augmented Generation pattern |
| 123 | +
|
| 124 | +### Docker Configuration |
| 125 | +
|
| 126 | +The Docker setup includes: |
| 127 | +
|
| 128 | +1. **Jupyter Container**: |
| 129 | + - Based on minimal Jupyter notebook image |
| 130 | + - Adds Java 21, Maven, and the JJava kernel |
| 131 | + - Includes Python environment with PyTorch and other ML libraries |
| 132 | +
|
| 133 | +2. **Redis Container**: |
| 134 | + - Uses Redis Stack image with Vector Search capabilities |
| 135 | + - Persists data using Docker volumes |
| 136 | + - Exposes Redis on port 6379 and RedisInsight on port 8001 |
| 137 | +
|
| 138 | +## Example Applications |
| 139 | +
|
| 140 | +### Beer Recommendation Chatbot |
| 141 | +
|
| 142 | +The `spring-ai-rag.ipynb` notebook demonstrates: |
| 143 | +
|
| 144 | +- Loading and embedding beer data into Redis Vector Store |
| 145 | +- Using local transformer models for generating embeddings |
| 146 | +- Connecting to OpenAI for LLM capabilities |
| 147 | +- Building a RAG pipeline to answer beer-related queries |
| 148 | +- Semantic search over beer properties and descriptions |
0 commit comments