Package com.redis.vl.test.vcr
Class VCREmbeddingModel
java.lang.Object
com.redis.vl.test.vcr.VCREmbeddingModel
- All Implemented Interfaces:
dev.langchain4j.model.embedding.EmbeddingModel
public class VCREmbeddingModel
extends Object
implements dev.langchain4j.model.embedding.EmbeddingModel
VCR-enabled wrapper around a LangChain4J EmbeddingModel.
This wrapper intercepts embedding calls and routes them through the VCR system for recording and playback.
Usage:
// In your test
EmbeddingModel realModel = new AllMiniLmL6V2EmbeddingModel();
VCREmbeddingModel vcrModel = new VCREmbeddingModel(realModel);
vcrModel.setMode(VCRMode.PLAYBACK_OR_RECORD);
vcrModel.setTestId("MyTest.testMethod");
// Use vcrModel instead of realModel
Response<Embedding> response = vcrModel.embed("text");
-
Constructor Summary
ConstructorsConstructorDescriptionVCREmbeddingModel(dev.langchain4j.model.embedding.EmbeddingModel delegate) Creates a VCR-enabled embedding model wrapper.VCREmbeddingModel(dev.langchain4j.model.embedding.EmbeddingModel delegate, VCRCassetteStore cassetteStore) Creates a VCR-enabled embedding model wrapper with Redis storage. -
Method Summary
Modifier and TypeMethodDescriptionintdev.langchain4j.model.output.Response<dev.langchain4j.data.embedding.Embedding> embed(dev.langchain4j.data.segment.TextSegment textSegment) dev.langchain4j.model.output.Response<dev.langchain4j.data.embedding.Embedding> dev.langchain4j.model.output.Response<List<dev.langchain4j.data.embedding.Embedding>> longGets the cache hit count.longGets the cache miss count.dev.langchain4j.model.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.
-
Constructor Details
-
VCREmbeddingModel
public VCREmbeddingModel(dev.langchain4j.model.embedding.EmbeddingModel delegate) Creates a VCR-enabled embedding model wrapper.- Parameters:
delegate- the real embedding model
-
VCREmbeddingModel
public VCREmbeddingModel(dev.langchain4j.model.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). -
embed
public dev.langchain4j.model.output.Response<dev.langchain4j.data.embedding.Embedding> embed(String text) - Specified by:
embedin interfacedev.langchain4j.model.embedding.EmbeddingModel
-
embed
public dev.langchain4j.model.output.Response<dev.langchain4j.data.embedding.Embedding> embed(dev.langchain4j.data.segment.TextSegment textSegment) - Specified by:
embedin interfacedev.langchain4j.model.embedding.EmbeddingModel
-
embedAll
public dev.langchain4j.model.output.Response<List<dev.langchain4j.data.embedding.Embedding>> embedAll(List<dev.langchain4j.data.segment.TextSegment> textSegments) - Specified by:
embedAllin interfacedev.langchain4j.model.embedding.EmbeddingModel
-
dimension
public int dimension()- Specified by:
dimensionin interfacedev.langchain4j.model.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 dev.langchain4j.model.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
-