Skip to content

Files

Latest commit

 

History

History
148 lines (105 loc) · 4.77 KB

README.md

File metadata and controls

148 lines (105 loc) · 4.77 KB

Redis AI Java Resources

License: MIT Java Spring AI

✨ Java-based code examples, notebooks, and resources for using Redis in AI and ML applications. ✨

Setup | Running the Project | Notebooks | Project Structure | Implementation Details


Setup

This project uses Docker Compose to set up a complete environment for running Java-based AI applications with Redis. The environment includes:

  • A Jupyter Notebook server with Java kernel support
  • Redis Stack (includes Redis and RedisInsight)
  • Pre-installed dependencies for AI/ML workloads

Prerequisites

Environment Configuration

  1. Create a .env file in the project root with your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here

Running the Project

  1. Clone the repository (if you haven't already):

    git clone https://github.com/redis-developer/redis-ai-resources.git
    cd redis-ai-resources/java-resources
  2. Start the Docker containers:

    docker-compose up -d
  3. Access the Jupyter environment:

    • Open your browser and navigate to http://localhost:8888

    • The token is usually shown in the docker-compose logs. You can view them with:

      docker-compose logs jupyter
  4. Access RedisInsight:

    • Open your browser and navigate to http://localhost:8001
    • Connect to Redis using the following details:
      • Host: redis-java
      • Port: 6379
      • No password (unless configured)
  5. When finished, stop the containers:

    docker-compose down

Notebooks

Notebook Description
RAG/spring_ai_redis_rag.ipynb Demonstrates building a RAG-based beer recommendation chatbot using Spring AI and Redis as the vector store

Project Structure

java-recipes/
├── .env                         # Environment variables (create this)
├── docker-compose.yml           # Docker Compose configuration
├── jupyter/                     # Jupyter configuration files
│   ├── Dockerfile               # Dockerfile for Jupyter with Java kernel
│   ├── environment.yml          # Conda environment specification
│   ├── install.py               # JJava kernel installation script
│   ├── kernel.json              # Kernel specification
│   └── java/                    # Java dependencies and configuration
│       └── pom.xml              # Maven project file with dependencies
└── resources/                   # Data files for notebooks
    └── beers.json.gz            # Compressed beer dataset

Implementation Details

Java Jupyter Kernel

The project uses JJava, a Jupyter kernel for Java based on JShell. This allows for interactive Java development in Jupyter notebooks.

Key components:

  • Java 21 for modern Java features
  • Maven for dependency management
  • JJava kernel for Jupyter integration

Spring AI Integration

The Spring AI notebooks showcase how to use Spring's AI capabilities with Redis:

  • Spring AI: Framework for building AI-powered applications
  • Redis Vector Store: Used for storing and querying vector embeddings
  • Transformer Models: For generating embeddings locally
  • RAG Pattern: Demonstrates the Retrieval Augmented Generation pattern

Docker Configuration

The Docker setup includes:

  1. Jupyter Container:

    • Based on minimal Jupyter notebook image
    • Adds Java 21, Maven, and the JJava kernel
    • Includes Python environment with PyTorch and other ML libraries
  2. Redis Container:

    • Uses Redis Stack image with Vector Search capabilities
    • Persists data using Docker volumes
    • Exposes Redis on port 6379 and RedisInsight on port 8001

Example Applications

Beer Recommendation Chatbot

The spring-ai-rag.ipynb notebook demonstrates:

  • Loading and embedding beer data into Redis Vector Store
  • Using local transformer models for generating embeddings
  • Connecting to OpenAI for LLM capabilities
  • Building a RAG pipeline to answer beer-related queries
  • Semantic search over beer properties and descriptions