Class DocumentBySentenceSplitter
- All Implemented Interfaces:
dev.langchain4j.data.document.DocumentSplitter
Document into sentences and attempts to fit as many sentences as possible
into a single TextSegment, adhering to the limit set by maxSegmentSize.
The maxSegmentSize can be defined in terms of characters (default) or tokens.
For token-based limit, a Tokenizer must be provided.
Sentence boundaries are detected using the Apache OpenNLP library with the English sentence model.
If multiple sentences fit within maxSegmentSize, they are joined together using a space (" ").
If a single sentence is too long and exceeds maxSegmentSize,
the subSplitter (DocumentByWordSplitter by default) is used to split it into smaller parts and
place them into multiple segments.
Such segments contain only the parts of the split long sentence.
Each TextSegment inherits all metadata from the Document and includes an "index" metadata key
representing its position within the document (starting from 0).
-
Field Summary
Fields inherited from class dev.langchain4j.data.document.splitter.HierarchicalDocumentSplitter
maxOverlapSize, maxSegmentSize, subSplitter, tokenizer -
Constructor Summary
ConstructorsConstructorDescriptionDocumentBySentenceSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars) DocumentBySentenceSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars, dev.langchain4j.data.document.DocumentSplitter subSplitter) DocumentBySentenceSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, dev.langchain4j.model.Tokenizer tokenizer) DocumentBySentenceSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, dev.langchain4j.model.Tokenizer tokenizer, dev.langchain4j.data.document.DocumentSplitter subSplitter) -
Method Summary
Modifier and TypeMethodDescriptionprotected dev.langchain4j.data.document.DocumentSplitterThe default sub-splitter to use when a single segment is too long.Delimiter string to use to re-join the parts.String[]Splits the provided text into parts.Methods inherited from class dev.langchain4j.data.document.splitter.HierarchicalDocumentSplitter
splitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.langchain4j.data.document.DocumentSplitter
splitAll
-
Constructor Details
-
DocumentBySentenceSplitter
public DocumentBySentenceSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars) -
DocumentBySentenceSplitter
public DocumentBySentenceSplitter(int maxSegmentSizeInChars, int maxOverlapSizeInChars, dev.langchain4j.data.document.DocumentSplitter subSplitter) -
DocumentBySentenceSplitter
public DocumentBySentenceSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, dev.langchain4j.model.Tokenizer tokenizer) -
DocumentBySentenceSplitter
public DocumentBySentenceSplitter(int maxSegmentSizeInTokens, int maxOverlapSizeInTokens, dev.langchain4j.model.Tokenizer tokenizer, dev.langchain4j.data.document.DocumentSplitter subSplitter)
-
-
Method Details
-
split
Description copied from class:HierarchicalDocumentSplitterSplits the provided text into parts. Implementation API.- Specified by:
splitin classHierarchicalDocumentSplitter- Parameters:
text- The text to be split.- Returns:
- An array of parts.
-
joinDelimiter
Description copied from class:HierarchicalDocumentSplitterDelimiter string to use to re-join the parts.- Specified by:
joinDelimiterin classHierarchicalDocumentSplitter- Returns:
- The delimiter.
-
defaultSubSplitter
protected dev.langchain4j.data.document.DocumentSplitter defaultSubSplitter()Description copied from class:HierarchicalDocumentSplitterThe default sub-splitter to use when a single segment is too long.- Specified by:
defaultSubSplitterin classHierarchicalDocumentSplitter- Returns:
- The default sub-splitter.
-