Package com.redis.vl.test.vcr
Class VCRSpringAIEmbeddingModel
java.lang.Object
com.redis.vl.test.vcr.VCRSpringAIEmbeddingModel
- All Implemented Interfaces:
org.springframework.ai.embedding.EmbeddingModel,org.springframework.ai.model.Model<org.springframework.ai.embedding.EmbeddingRequest,org.springframework.ai.embedding.EmbeddingResponse>
public class VCRSpringAIEmbeddingModel
extends Object
implements org.springframework.ai.embedding.EmbeddingModel
VCR-enabled wrapper around a Spring AI EmbeddingModel.
This wrapper intercepts embedding calls and routes them through the VCR system for recording and playback.
Usage:
// In your test
EmbeddingModel realModel = new OpenAiEmbeddingModel(...);
VCRSpringAIEmbeddingModel vcrModel = new VCRSpringAIEmbeddingModel(realModel);
vcrModel.setMode(VCRMode.PLAYBACK_OR_RECORD);
vcrModel.setTestId("MyTest.testMethod");
// Use vcrModel instead of realModel
float[] embedding = vcrModel.embed("text");
-
Constructor Summary
ConstructorsConstructorDescriptionVCRSpringAIEmbeddingModel(org.springframework.ai.embedding.EmbeddingModel delegate) Creates a VCR-enabled embedding model wrapper.VCRSpringAIEmbeddingModel(org.springframework.ai.embedding.EmbeddingModel delegate, VCRCassetteStore cassetteStore) Creates a VCR-enabled embedding model wrapper with Redis storage. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.ai.embedding.EmbeddingResponsecall(org.springframework.ai.embedding.EmbeddingRequest request) intfloat[]List<float[]> float[]embed(org.springframework.ai.document.Document document) org.springframework.ai.embedding.EmbeddingResponseembedForResponse(List<String> texts) longGets the cache hit count.longGets the cache miss count.org.springframework.ai.embedding.EmbeddingModelGets the underlying delegate model.getMode()Gets the current VCR mode.intGets the number of recorded cassettes.voidpreloadBatchCassette(String key, float[][] embeddings) Preloads a batch cassette into the in-memory cache (for testing).voidpreloadCassette(String key, float[] embedding) Preloads a cassette into the in-memory cache (for testing).voidResets the call counter (call at start of each test).voidResets statistics.voidSets the VCR mode.voidsetModelName(String modelName) Sets the model name for cassette metadata.voidSets the current test identifier.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.embedding.EmbeddingModel
embed
-
Constructor Details
-
VCRSpringAIEmbeddingModel
public VCRSpringAIEmbeddingModel(org.springframework.ai.embedding.EmbeddingModel delegate) Creates a VCR-enabled embedding model wrapper.- Parameters:
delegate- the real embedding model
-
VCRSpringAIEmbeddingModel
public VCRSpringAIEmbeddingModel(org.springframework.ai.embedding.EmbeddingModel delegate, VCRCassetteStore cassetteStore) Creates a VCR-enabled embedding model wrapper with Redis storage.- Parameters:
delegate- the real embedding modelcassetteStore- the cassette store
-
-
Method Details
-
setMode
Sets the VCR mode.- Parameters:
mode- the mode
-
getMode
Gets the current VCR mode.- Returns:
- the mode
-
setTestId
Sets the current test identifier.- Parameters:
testId- the test ID
-
setModelName
Sets the model name for cassette metadata.- Parameters:
modelName- the model name
-
resetCallCounter
public void resetCallCounter()Resets the call counter (call at start of each test). -
call
public org.springframework.ai.embedding.EmbeddingResponse call(org.springframework.ai.embedding.EmbeddingRequest request) - Specified by:
callin interfaceorg.springframework.ai.embedding.EmbeddingModel- Specified by:
callin interfaceorg.springframework.ai.model.Model<org.springframework.ai.embedding.EmbeddingRequest,org.springframework.ai.embedding.EmbeddingResponse>
-
embed
- Specified by:
embedin interfaceorg.springframework.ai.embedding.EmbeddingModel
-
embed
public float[] embed(org.springframework.ai.document.Document document) - Specified by:
embedin interfaceorg.springframework.ai.embedding.EmbeddingModel
-
embed
- Specified by:
embedin interfaceorg.springframework.ai.embedding.EmbeddingModel
-
embedForResponse
- Specified by:
embedForResponsein interfaceorg.springframework.ai.embedding.EmbeddingModel
-
dimensions
public int dimensions()- Specified by:
dimensionsin interfaceorg.springframework.ai.embedding.EmbeddingModel
-
getCacheHits
public long getCacheHits()Gets the cache hit count.- Returns:
- number of cache hits
-
getCacheMisses
public long getCacheMisses()Gets the cache miss count.- Returns:
- number of cache misses
-
resetStatistics
public void resetStatistics()Resets statistics. -
getRecordedCount
public int getRecordedCount()Gets the number of recorded cassettes.- Returns:
- the count
-
getDelegate
public org.springframework.ai.embedding.EmbeddingModel getDelegate()Gets the underlying delegate model.- Returns:
- the delegate
-
preloadCassette
Preloads a cassette into the in-memory cache (for testing).- Parameters:
key- the cassette keyembedding- the embedding to cache
-
preloadBatchCassette
Preloads a batch cassette into the in-memory cache (for testing).- Parameters:
key- the cassette keyembeddings- the embeddings to cache
-