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

    Constructors
    Constructor
    Description
    VCREmbeddingModel(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 Type
    Method
    Description
    int
     
    dev.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>
    embed(String text)
     
    dev.langchain4j.model.output.Response<List<dev.langchain4j.data.embedding.Embedding>>
    embedAll(List<dev.langchain4j.data.segment.TextSegment> textSegments)
     
    long
    Gets the cache hit count.
    long
    Gets the cache miss count.
    dev.langchain4j.model.embedding.EmbeddingModel
    Gets the underlying delegate model.
    Gets the current VCR mode.
    int
    Gets the number of recorded cassettes.
    void
    preloadBatchCassette(String key, float[][] embeddings)
    Preloads a batch cassette into the in-memory cache (for testing).
    void
    preloadCassette(String key, float[] embedding)
    Preloads a cassette into the in-memory cache (for testing).
    void
    Resets the call counter (call at start of each test).
    void
    Resets statistics.
    void
    Sets the VCR mode.
    void
    setModelName(String modelName)
    Sets the model name for cassette metadata.
    void
    setTestId(String testId)
    Sets the current test identifier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 model
      cassetteStore - the cassette store
  • Method Details

    • setMode

      public void setMode(VCRMode mode)
      Sets the VCR mode.
      Parameters:
      mode - the mode
    • getMode

      public VCRMode getMode()
      Gets the current VCR mode.
      Returns:
      the mode
    • setTestId

      public void setTestId(String testId)
      Sets the current test identifier.
      Parameters:
      testId - the test ID
    • setModelName

      public void setModelName(String modelName)
      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:
      embed in interface dev.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:
      embed in interface dev.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:
      embedAll in interface dev.langchain4j.model.embedding.EmbeddingModel
    • dimension

      public int dimension()
      Specified by:
      dimension in interface dev.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

      public void preloadCassette(String key, float[] embedding)
      Preloads a cassette into the in-memory cache (for testing).
      Parameters:
      key - the cassette key
      embedding - the embedding to cache
    • preloadBatchCassette

      public void preloadBatchCassette(String key, float[][] embeddings)
      Preloads a batch cassette into the in-memory cache (for testing).
      Parameters:
      key - the cassette key
      embeddings - the embeddings to cache