Skip to content

Module 3: Context Retriever


What you're building

So far your agent can search static documents. But real questions like "Do I have any upcoming appointments?" need live data that changes constantly.

Context Retriever lets you describe your data once, then auto-generates tools your agent can call at runtime.

Vector Search Context Retriever
Data Static documents Live business data
Query "What's the cancellation policy?" "Do I have any upcoming appointments?"
How Searches by meaning Queries patients, appointments, providers directly

Cloud setup

1. Create a Context Retriever service

  1. Go to Context Retriever in the Redis Cloud console.
  2. Click Create custom service.
  3. Fill in the general settings:

    • Service name: healthcare
    • Database: select your workshop database

2. Define your first entity

  1. Click Entities, then Add Entity.
  2. Fill in:

    • Entity name: Patient
    • Key Template: healthcare_patient:{id}

    The key template tells Context Retriever the pattern behind your Redis keys. From this one pattern, it can find any patient record instantly.

  3. Click Fields, then Auto-Detect Fields.

    Auto-detect fields

    It just scanned your database and figured out the schema automatically. Field names, types, and which fields link to other entities.

    Define entities

  4. Click Create.

3. Save your Surface ID

After creating the service, look at the URL in your browser:

cloud.redis.io/#/context-retriever/<your-surface-id>

Copy everything after /context-retriever/ and paste it in your .env file:

CTX_SURFACE_ID=<your-surface-id>

4. Save your Admin Key

  1. Click back to Context Retriever Surfaces.

    Back to services

  2. Click the Admin Keys tab and create a new key.

    Admin keys list

  3. Copy the key and save it in your .env file:

CTX_ADMIN_KEY=<your-admin-key>

5. Complete the surface and load data

You defined one entity. The app needs all 7 (Location, Provider, Patient, Appointment, Referral, Waitlist, HealthDoc). Run this to add the rest automatically:

make setup-context
.\workshop.ps1 setup-context

What you just built

Go back to your Context Retriever service in the Redis Cloud console and scroll down.

7 entities mapped to your Redis keys with full field definitions and relationships:

Entities view

Expand any entity. Appointment.patient_idPatient. Appointment.provider_idProvider. These relationships let your agent follow the data trail across entities, just like a human care coordinator would.

Auto-generated MCP tools your agent can now call:

Generated MCP tools

Redis automatically figured out the best way for your agent to access your business data and created these tools as pathways your agent can call at runtime. filter_appointment_by_patient_id, filter_referral_by_urgency, search_patient_by_text, and more.


Verify

Stop the running server (Ctrl+C) and restart:

make dev
.\workshop.ps1 dev

Open localhost:3040.

The mode toggle now shows Real-time Context.

  1. Switch to Real-time Context mode
  2. Ask: "Do I have any upcoming appointments?"
  3. Watch the activity panel on the right as the agent chains tool calls to pull your appointments, providers, and locations
  4. Try: "What's the status of my referrals?"
  5. Switch back to Simple RAG and ask the same question to see the difference