Record Class DocumentSource

java.lang.Object
java.lang.Record
dyntabs.ai.rag.DocumentSource
Record Components:
fileName - the file name with extension (e.g. "policy.pdf", "manual.docx"). The extension tells the parser how to interpret the bytes.
content - the raw document content as bytes

public record DocumentSource(String fileName, byte[] content) extends Record
Represents a document loaded into memory as raw bytes.

Use this when your documents come from a DMS, database, REST API, or any other source that provides content as byte[] rather than as a file on disk.

Use Case 1: Document from a DMS (Document Management System)


 byte[] pdfBytes = dmsClient.downloadDocument("DOC-12345");

 PolicyBot bot = EasyAI.assistant(PolicyBot.class)
     .withRAG(DocumentSource.of("policy.pdf", pdfBytes))
     .build();
 

Use Case 2: Document from a Database (BLOB)


 byte[] content = resultSet.getBytes("document_content");
 String fileName = resultSet.getString("file_name");

 PolicyBot bot = EasyAI.assistant(PolicyBot.class)
     .withRAG(DocumentSource.of(fileName, content))
     .build();
 

Use Case 3: Multiple Documents from Different Sources


 DocumentSource policy = DocumentSource.of("policy.pdf", dmsClient.download("policy"));
 DocumentSource faq = DocumentSource.of("faq.txt", restApi.getFaqContent());
 DocumentSource terms = DocumentSource.of("terms.docx", blobStorage.get("terms"));

 LegalBot bot = EasyAI.assistant(LegalBot.class)
     .withRAG(policy, faq, terms)
     .build();
 

Use Case 4: Plain Text Content (No File Needed)


 String textContent = "Company vacation policy: all employees get 25 days...";

 PolicyBot bot = EasyAI.assistant(PolicyBot.class)
     .withRAG(DocumentSource.ofText("policy", textContent))
     .build();
 
See Also:
  • Constructor Details

    • DocumentSource

      public DocumentSource(String fileName, byte[] content)
      Creates an instance of a DocumentSource record class.
      Parameters:
      fileName - the value for the fileName record component
      content - the value for the content record component
  • Method Details

    • of

      public static DocumentSource of(String fileName, byte[] content)
      Creates a DocumentSource from a file name and raw bytes.

      The file name extension is important - it tells the document parser how to interpret the bytes (e.g. ".pdf" for PDF parsing, ".docx" for Word).

      Parameters:
      fileName - file name with extension (e.g. "report.pdf", "manual.docx")
      content - the raw document bytes
      Returns:
      a new DocumentSource
    • ofText

      public static DocumentSource ofText(String name, String text)
      Creates a DocumentSource from plain text content.

      Use this when you already have the text and don't need PDF/DOCX parsing. The text is stored as UTF-8 bytes with a ".txt" extension.

      Parameters:
      name - a descriptive name for this content (e.g. "faq", "policy")
      text - the plain text content
      Returns:
      a new DocumentSource
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • fileName

      public String fileName()
      Returns the value of the fileName record component.
      Returns:
      the value of the fileName record component
    • content

      public byte[] content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component