Document represents document content along with its metadata that can be embedded, indexed or retrieved. Each document can contain multiple parts (for example text and an image)

Hierarchy (View Summary)

Implements

Constructors

  • Parameters

    • data: {
          content: (
              | { media?: undefined; text: string }
              | { media: { contentType?: string; url: string }; text?: undefined }
          )[];
          metadata: { score: number } & { [k: string]: unknown };
      }

    Returns RankedDocument

Properties

content: (
    | { media?: undefined; text: string }
    | { media: { contentType?: string; url: string }; text?: undefined }
)[]
metadata: { score: number } & Record<string, any>

Accessors

  • get data(): string
  • Gets the first item in the document. Either text or media url.

    Returns string

  • get dataType(): undefined | string
  • Gets the contentType of the data that is returned by data()

    Returns undefined | string

  • get media(): { contentType?: string; url: string }[]
  • Media array getter.

    Returns { contentType?: string; url: string }[]

    the array of media parts.

  • get text(): string
  • Concatenates all text parts present in the document with no delimiter.

    Returns string

    A string of all concatenated text parts.

Methods

  • Embedders may return multiple embeddings for a single document. But storage still requires a 1:1 relationship. So we create an array of Documents from a single document - one per embedding.

    Parameters

    • embeddings: { embedding: number[]; metadata?: Record<string, unknown> }[]

      The embeddings to create the documents from.

    Returns Document[]

    an array of documents based on this document and the embeddings.

  • Returns the score of the document.

    Returns number

    The score of the document.

  • Returns {
        content: (
            | { media?: undefined; text: string }
            | { media: { contentType?: string; url: string }; text?: undefined }
        )[];
        metadata?: Record<string, any>;
    }

  • Parameters

    • data: string
    • OptionaldataType: string
    • Optionalmetadata: Record<string, unknown>

    Returns Document

  • Parameters

    • url: string
    • OptionalcontentType: string
    • Optionalmetadata: Record<string, unknown>

    Returns Document

  • Parameters

    • text: string
    • Optionalmetadata: Record<string, any>

    Returns Document