Package com.redis.vl.test.vcr
Class VCRCassetteStore
java.lang.Object
com.redis.vl.test.vcr.VCRCassetteStore
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.JsonObjectcreateBatchEmbeddingCassette(float[][] embeddings, String testId, String model) Creates a cassette JSON object for batch embeddings.static com.google.gson.JsonObjectcreateEmbeddingCassette(float[] embedding, String testId, String model) Creates a cassette JSON object for an embedding.voidDeletes a cassette.booleanChecks if a cassette exists.static float[][]extractBatchEmbeddings(com.google.gson.JsonObject cassette) Extracts batch embeddings from a cassette JSON object.static float[]extractEmbedding(com.google.gson.JsonObject cassette) Extracts embedding from a cassette JSON object.static StringFormats a cassette key.static String[]Parses a cassette key into its components.com.google.gson.JsonObjectRetrieves a cassette from Redis.voidStores a cassette in Redis.
-
Constructor Details
-
VCRCassetteStore
Creates a new cassette store.- Parameters:
jedis- the Redis client
-
-
Method Details
-
formatKey
Formats a cassette key.- Parameters:
type- the cassette typetestId- the test identifiercallIndex- the call index (1-based)- Returns:
- the formatted key
-
parseKey
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 vectortestId- the test identifiermodel- 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 vectorstestId- the test identifiermodel- 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
Stores a cassette in Redis.- Parameters:
key- the cassette keycassette- the cassette data
-
retrieve
Retrieves a cassette from Redis.- Parameters:
key- the cassette key- Returns:
- the cassette data or null if not found
-
exists
Checks if a cassette exists.- Parameters:
key- the cassette key- Returns:
- true if the cassette exists
-
delete
Deletes a cassette.- Parameters:
key- the cassette key
-