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 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 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).
    • call

      public org.springframework.ai.embedding.EmbeddingResponse call(org.springframework.ai.embedding.EmbeddingRequest request)
      Specified by:
      call in interface org.springframework.ai.embedding.EmbeddingModel
      Specified by:
      call in interface org.springframework.ai.model.Model<org.springframework.ai.embedding.EmbeddingRequest,org.springframework.ai.embedding.EmbeddingResponse>
    • embed

      public float[] embed(String text)
      Specified by:
      embed in interface org.springframework.ai.embedding.EmbeddingModel
    • embed

      public float[] embed(org.springframework.ai.document.Document document)
      Specified by:
      embed in interface org.springframework.ai.embedding.EmbeddingModel
    • embed

      public List<float[]> embed(List<String> texts)
      Specified by:
      embed in interface org.springframework.ai.embedding.EmbeddingModel
    • embedForResponse

      public org.springframework.ai.embedding.EmbeddingResponse embedForResponse(List<String> texts)
      Specified by:
      embedForResponse in interface org.springframework.ai.embedding.EmbeddingModel
    • dimensions

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

      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