Class RedisVLDocumentStore

java.lang.Object
com.redis.vl.langchain4j.RedisVLDocumentStore

public class RedisVLDocumentStore extends Object
RedisVL Document Store for storing raw binary content (images, PDFs, etc.) for multimodal RAG.

This store enables persistent storage of raw documents with metadata, separate from vector embeddings. Useful for multimodal RAG where text summaries are embedded for search, but raw images/content is needed for vision LLM generation.

Documents are stored as Redis Hashes with:

  • content: Base64-encoded binary content
  • metadata_*: Individual metadata fields

Example usage:


 // Create document store
 UnifiedJedis jedis = RedisClient.create("localhost", 6379);
 RedisVLDocumentStore store = new RedisVLDocumentStore(jedis, "docs:");

 // Store a document
 byte[] imageBytes = Files.readAllBytes(Path.of("image.jpg"));
 Map<String, String> metadata = Map.of("type", "image", "source", "page1.pdf");
 store.store("doc_id_1", imageBytes, metadata);

 // Retrieve document
 Optional<Document> doc = store.retrieve("doc_id_1");
 if (doc.isPresent()) {
   byte[] content = doc.get().content();
   Map<String, String> meta = doc.get().metadata();
   // Use with vision LLM
 }

 // Builder pattern
 RedisVLDocumentStore store = RedisVLDocumentStore.builder()
     .jedis(jedis)
     .keyPrefix("docs:")
     .build();
 
  • Constructor Details

    • RedisVLDocumentStore

      public RedisVLDocumentStore(UnifiedJedis jedis)
      Creates a new RedisVLDocumentStore with default prefix.
      Parameters:
      jedis - The Redis client
    • RedisVLDocumentStore

      public RedisVLDocumentStore(UnifiedJedis jedis, String keyPrefix)
      Creates a new RedisVLDocumentStore with custom prefix.
      Parameters:
      jedis - The Redis client
      keyPrefix - The key prefix for Redis keys
  • Method Details

    • store

      public void store(String id, byte[] content, Map<String,String> metadata)
      Stores a document with metadata.
      Parameters:
      id - Unique document identifier
      content - Binary content
      metadata - Optional metadata (can be null)
      Throws:
      IllegalArgumentException - if id or content is null
    • retrieve

      Retrieves a document by ID.
      Parameters:
      id - Document identifier
      Returns:
      Optional containing the document if found
    • delete

      public boolean delete(String id)
      Deletes a document by ID.
      Parameters:
      id - Document identifier
      Returns:
      true if document was deleted, false if it didn't exist
    • listDocumentIds

      public List<String> listDocumentIds()
      Lists all document IDs in this store.
      Returns:
      List of document IDs
    • getJedis

      public UnifiedJedis getJedis()
      Gets the underlying Jedis client.
      Returns:
      The Redis client
    • getKeyPrefix

      public String getKeyPrefix()
      Gets the key prefix.
      Returns:
      The key prefix
    • builder

      public static RedisVLDocumentStore.Builder builder()
      Creates a builder for RedisVLDocumentStore.
      Returns:
      A new builder instance