README.md

November 24, 2025 · View on GitHub

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 (For notebooks that based on Java)
  • 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

NotebookDescription
RAG/spring_ai_redis_rag.ipynbDemonstrates building a RAG-based beer recommendation chatbot using Spring AI and Redis as the vector store
semantic-routing/1_semantic_classification.ipynbDemonstrates how to perform text classification with vector search (RedisVL) instead of LLMs
semantic-routing/2_semantic_tool_calling.ipynbDemonstrates how to perform tool selection with vector search (RedisVL) instead of LLMs
semantic-routing/3_semantic_guardrails.ipynbDemonstrates how to implement guardrails with vector search (RedisVL)
semantic-caching/1_pre_generated_semantic_caching.ipynbDemonstrates how to perform pre generated semantic caching with RedisVL
semantic-caching/2_semantic_caching_with_langcache.ipynbDemonstrates how to perform pre generated semantic caching with LangCache

Project Structure

notebooks/
├── .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