接口 DocumentSplitter


public interface DocumentSplitter
Defines the interface for splitting a document into text segments. This is necessary as LLMs have a limited context window, making it impossible to send the entire document at once. Therefore, the document should first be split into segments, and only the relevant segments should be sent to LLM.
DocumentSplitters.recursive() from a dev.langchain4j:langchain4j module is a good starting point.
  • 方法概要

    修饰符和类型
    方法
    说明
    split(Document document)
    Splits a single Document into a list of TextSegment objects.
    default List<TextSegment>
    splitAll(List<Document> documents)
    Splits a list of Documents into a list of TextSegment objects.
  • 方法详细资料

    • split

      List<TextSegment> split(Document document)
      Splits a single Document into a list of TextSegment objects. The metadata is typically copied from the document and enriched with segment-specific information, such as position in the document, page number, etc.
      参数:
      document - The Document to be split.
      返回:
      A list of TextSegment objects derived from the input Document.
    • splitAll

      default List<TextSegment> splitAll(List<Document> documents)
      Splits a list of Documents into a list of TextSegment objects. This is a convenience method that calls the split method for each Document in the list.
      参数:
      documents - The list of Documents to be split.
      返回:
      A list of TextSegment objects derived from the input Documents.