import { Attributable } from "../common/base"; import { JSONObject } from "../common/jsonTypes"; import { BlobIdentifier } from "../common/storage"; import { DataSource } from "../ingestion/data-sources/dataSource"; export type RawDocumentChunk = { content: string; metadata: JSONObject; }; /** * The original document, as it was ingested from the data source. */ export interface RawDocument extends Attributable { uri: string; dataSource: DataSource; name: string; mimeType: string; hash?: string; blobId?: BlobIdentifier; documentId: string; collectionId?: string; /** * Fetch the document text from the data source. * TODO: saqadri - instead of fetching the entire document text (which could be large), we should * provide a way to fetch the text in chunks or stream the text. * Perhaps readable stream with async generators: https://nodejs.org/api/stream.html#creating-readable-streams-with-async-generators */ getContent(): Promise; /** * Fetch the document text and metadata in reasonable chunks (e.g. pages) from the data source. */ getChunkedContent(): Promise; } export type DocumentFragmentType = "text" | "image" | "table" | "list" | "paragraph" | "heading" | "code" | "quote"; /** * */ export interface DocumentFragment extends Attributable { fragmentId: string; hash?: string; blobId?: BlobIdentifier; fragmentType: DocumentFragmentType; documentId: string; previousFragment?: DocumentFragment; nextFragment?: DocumentFragment; children?: DocumentFragment[]; /** * Gets the content of the fragment. @see blobId */ getContent(): Promise; /** * Serializes the fragment and its relationship metadata as a JSON string. */ serialize(): Promise; } /** * A @see RawDocument after it has been parsed into a graph of @see DocumentFragments. */ export interface Document extends Attributable { documentId: string; collectionId?: string; fragments: DocumentFragment[]; /** * Serializes the document to disk, and returns the path to the serialized document. */ serialize(): Promise; } /** * A @see RawDocument after it has been parsed into a graph of @see DocumentFragments during * ingestion; RawDocument is accessible from the Document at ingestion time. */ export interface IngestedDocument extends Document { rawDocument: RawDocument; }