Class VCRCassetteStore

java.lang.Object
com.redis.vl.test.vcr.VCRCassetteStore

public class VCRCassetteStore extends Object
Stores and retrieves VCR cassettes (recorded API responses) in Redis.

Cassettes are stored as Redis JSON documents with the following key format:

vcr:{type}:{testId}:{callIndex}
Where:
  • {type} - The type of cassette (e.g., "embedding", "llm", "chat")
  • {testId} - The unique test identifier (e.g., "MyTest.testMethod")
  • {callIndex} - Zero-padded call index within the test (e.g., "0001")
  • Constructor Details

    • VCRCassetteStore

      public VCRCassetteStore(UnifiedJedis jedis)
      Creates a new cassette store.
      Parameters:
      jedis - the Redis client
  • Method Details

    • formatKey

      public static String formatKey(String type, String testId, int callIndex)
      Formats a cassette key.
      Parameters:
      type - the cassette type
      testId - the test identifier
      callIndex - the call index (1-based)
      Returns:
      the formatted key
    • parseKey

      public static String[] parseKey(String key)
      Parses a cassette key into its components.
      Parameters:
      key - the key to parse
      Returns:
      array of [prefix, type, testId, callIndex] or null if invalid
    • createEmbeddingCassette

      public static com.google.gson.JsonObject createEmbeddingCassette(float[] embedding, String testId, String model)
      Creates a cassette JSON object for an embedding.
      Parameters:
      embedding - the embedding vector
      testId - the test identifier
      model - the model name
      Returns:
      the cassette JSON object
    • createBatchEmbeddingCassette

      public static com.google.gson.JsonObject createBatchEmbeddingCassette(float[][] embeddings, String testId, String model)
      Creates a cassette JSON object for batch embeddings.
      Parameters:
      embeddings - the embedding vectors
      testId - the test identifier
      model - the model name
      Returns:
      the cassette JSON object
    • extractEmbedding

      public static float[] extractEmbedding(com.google.gson.JsonObject cassette)
      Extracts embedding from a cassette JSON object.
      Parameters:
      cassette - the cassette object
      Returns:
      the embedding vector or null if not present
    • extractBatchEmbeddings

      public static float[][] extractBatchEmbeddings(com.google.gson.JsonObject cassette)
      Extracts batch embeddings from a cassette JSON object.
      Parameters:
      cassette - the cassette object
      Returns:
      the embedding vectors or null if not present
    • store

      public void store(String key, com.google.gson.JsonObject cassette)
      Stores a cassette in Redis.
      Parameters:
      key - the cassette key
      cassette - the cassette data
    • retrieve

      public com.google.gson.JsonObject retrieve(String key)
      Retrieves a cassette from Redis.
      Parameters:
      key - the cassette key
      Returns:
      the cassette data or null if not found
    • exists

      public boolean exists(String key)
      Checks if a cassette exists.
      Parameters:
      key - the cassette key
      Returns:
      true if the cassette exists
    • delete

      public void delete(String key)
      Deletes a cassette.
      Parameters:
      key - the cassette key