クラス Document

java.lang.ObjectSE
org.springframework.ai.document.Document

public class Document extends ObjectSE
ドキュメントは、ドキュメントのコンテンツとメタデータを格納するコンテナーです。また、ドキュメント固有の ID も保持します。ドキュメントにはテキストコンテンツまたはメディアコンテンツのいずれか一方しか格納できません。ドキュメントは、spring-ai の ETL パイプラインの一部として外部ソースからデータを取得するために使用することを目的としています。

テキストドキュメントを作成する例:


 // Using constructor
 Document textDoc = new Document("Sample text content", Map.of("source", "user-input"));

 // Using builder
 Document textDoc = Document.builder()
     .text("Sample text content")
     .metadata("source", "user-input")
     .build();
 

メディアドキュメントの作成例:


 // Using constructor
 Media imageContent = new Media(MediaType.IMAGE_PNG, new byte[] {...});
 Document mediaDoc = new Document(imageContent, Map.of("filename", "sample.png"));

 // Using builder
 Document mediaDoc = Document.builder()
     .media(new Media(MediaType.IMAGE_PNG, new byte[] {...}))
     .metadata("filename", "sample.png")
     .build();
 

コンテンツ型を確認し、コンテンツにアクセスする例:


 if (document.isText()) {
     String textContent = document.getText();
     // Process text content
 } else {
     Media mediaContent = document.getMedia();
     // Process media content
 }
 
  • フィールドの詳細

    • DEFAULT_CONTENT_FORMATTER

      public static final ContentFormatter DEFAULT_CONTENT_FORMATTER
  • コンストラクターの詳細

  • メソッドの詳細

    • builder

      public static Document.Builder builder()
    • getId

      public StringSE getId()
      このドキュメントの一意の識別子を返します。

      この ID は、ドキュメントの作成時に明示的に提供されるか、構成された IdGenerator (デフォルトは RandomIdGenerator) を使用して生成されます。

      戻り値:
      このドキュメントの一意の識別子
      関連事項:
    • getText

      @Nullable public StringSE getText()
      ドキュメントのテキストコンテンツを返します (存在する場合)。
      戻り値:
      isText() が true の場合はテキストコンテンツ、そうでない場合は null
      関連事項:
    • isText

      public boolean isText()
      このドキュメントにテキストまたはメディアコンテンツが含まれているかどうかを決定します。
      戻り値:
      このドキュメントにテキストコンテンツ(getText() 経由でアクセス可能)が含まれている場合は true、メディアコンテンツが含まれている場合は false (getMedia() 経由でアクセス可能)
    • getMedia

      @Nullable public Media getMedia()
      ドキュメントのメディアコンテンツを返します (存在する場合)。
      戻り値:
      isText() が偽の場合はメディアコンテンツ、そうでない場合は null
      関連事項:
    • getFormattedContent

      public StringSE getFormattedContent()
    • getFormattedContent

      public StringSE getFormattedContent(MetadataMode metadataMode)
    • getFormattedContent

      public StringSE getFormattedContent(ContentFormatter formatter, MetadataMode metadataMode)
      外部の ContentFormatter を使用するヘルパーコンテンツ抽出プログラム。
    • getMetadata

      public MapSE<StringSE,ObjectSE> getMetadata()
      このドキュメントに関連付けられたメタデータを返します。

      メタデータ値は、ベクトルデータベースとの互換性のために、単純な型 (文字列、int、float、boolean) に制限されます。

      戻り値:
      メタデータマップ
    • getScore

      @Nullable public DoubleSE getScore()
    • getContentFormatter

      public ContentFormatter getContentFormatter()
      このドキュメントに関連付けられたコンテンツフォーマッタを返します。
      戻り値:
      ドキュメントコンテンツのフォーマットに使用される現在の ContentFormatter インスタンス。
    • setContentFormatter

      public void setContentFormatter(ContentFormatter contentFormatter)
      ドキュメントの ContentFormatter を置き換えます。
      パラメーター:
      contentFormatter - 使用する新しいフォーマッタ。
    • mutate

      public Document.Builder mutate()
    • equals

      public boolean equals(ObjectSE o)
      オーバーライド:
      クラス ObjectSEequalsSE 
    • hashCode

      public int hashCode()
      オーバーライド:
      クラス ObjectSEhashCode 
    • toString

      public StringSE toString()
      オーバーライド:
      クラス ObjectSEtoString