Package dev.langchain4j.data.document
Class Document
java.lang.Object
dev.langchain4j.data.document.Document
Represents an unstructured piece of text that usually corresponds to a content of a single file.
This text could originate from various sources such as a text file, PDF, DOCX, or a web page (HTML).
Each document may have associated metadata including its source, owner, creation date, etc.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Common metadata key for the absolute path of the directory from which the document was loaded.static final String
Common metadata key for the name of the file from which the document was loaded.static final String
Common metadata key for the URL from which the document was loaded. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Document
Creates a new Document from the given text.static Document
Creates a new Document from the given text.boolean
static Document
Creates a new Document from the given text.static Document
Creates a new Document from the given text.int
hashCode()
metadata()
Returns the metadata associated with this document.Deprecated, for removal: This API element is subject to removal in a future version.text()
Returns the text of this document.toString()
Builds a TextSegment from this document.
-
Field Details
-
FILE_NAME
Common metadata key for the name of the file from which the document was loaded.- See Also:
-
ABSOLUTE_DIRECTORY_PATH
Common metadata key for the absolute path of the directory from which the document was loaded.- See Also:
-
URL
Common metadata key for the URL from which the document was loaded.- See Also:
-
-
Constructor Details
-
Document
Creates a new Document from the given text.The created document will have empty metadata.
- Parameters:
text
- the text of the document.
-
Document
Creates a new Document from the given text.- Parameters:
text
- the text of the document.metadata
- the metadata of the document.
-
-
Method Details
-
text
Returns the text of this document.- Returns:
- the text.
-
metadata
Returns the metadata associated with this document.- Returns:
- the metadata.
-
metadata
Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usemetadata()
and thenMetadata.getString(String)
,Metadata.getInteger(String)
,Metadata.getLong(String)
,Metadata.getFloat(String)
,Metadata.getDouble(String)
instead.Looks up the metadata value for the given key.- Parameters:
key
- the key to look up.- Returns:
- the metadata value for the given key, or null if the key is not present.
-
toTextSegment
Builds a TextSegment from this document.- Returns:
- a TextSegment.
-
equals
-
hashCode
public int hashCode() -
toString
-
from
Creates a new Document from the given text.The created document will have empty metadata.
- Parameters:
text
- the text of the document.- Returns:
- a new Document.
-
from
Creates a new Document from the given text.- Parameters:
text
- the text of the document.metadata
- the metadata of the document.- Returns:
- a new Document.
-
document
Creates a new Document from the given text.The created document will have empty metadata.
- Parameters:
text
- the text of the document.- Returns:
- a new Document.
-
document
Creates a new Document from the given text.- Parameters:
text
- the text of the document.metadata
- the metadata of the document.- Returns:
- a new Document.
-
metadata()
and thenMetadata.getString(String)
,Metadata.getInteger(String)
,Metadata.getLong(String)
,Metadata.getFloat(String)
,Metadata.getDouble(String)
instead.