Package dyntabs.ai.rag
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
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 Summary
ConstructorsConstructorDescriptionDocumentSource(String fileName, byte[] content) Creates an instance of aDocumentSourcerecord class. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.fileName()Returns the value of thefileNamerecord component.final inthashCode()Returns a hash code value for this object.static DocumentSourceCreates a DocumentSource from a file name and raw bytes.static DocumentSourceCreates a DocumentSource from plain text content.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
of
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
fileName
Returns the value of thefileNamerecord component.- Returns:
- the value of the
fileNamerecord component
-
content
public byte[] content()Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-