Skip to main content
createIndexFromFiles builds a new index directly from raw documents. You upload PDF and DOCX files; the server parses them, splits them into chunks, generates embeddings, and builds the index. The call resolves when the index is ready to query.
Requires @moss-js/moss 1.8.0+. Also available in Python as create_index_from_files (moss 1.7.3+). chunkSize and chunkOverlap need 1.18.0+ (Python 1.17.0+).

How it works

The call handles the full flow: it registers the files, uploads each one, and triggers parsing, embedding, and the index build server-side. It polls the job every ~2 seconds (reporting through onProgress) and resolves to a MutationResult when the index is ready. Jobs time out after 30 minutes.

Files

Each entry is a ParseFileInput: Limits:
  • 1 to 20 files per call. Each call creates a new index, and files cannot be appended to an existing index afterwards, so an index is built from at most 20 files.
  • 50 MB per file, enforced server-side. The SDK does not pre-check size; an oversized file fails during the job.
  • Prefer path on Node.js. In-memory data is copied byte by byte across the native boundary, which is memory-hungry for large files.

Options

CreateIndexFromFilesOptions:

Parse options

All fields of ParseOptions are optional; omitted fields use the server defaults. The extraction options shape the text the parser extracts; chunking then runs over it as one stream per file.

Progress

onProgress receives a JobProgress roughly every 2 seconds while the server is working (there is no per-byte upload progress):
File-parse jobs move through the phases queued, parsing, waiting_for_parser, parsing_complete, generating_embeddings, and building_index. Guard phase checks with if (p.currentPhase) - it can be unset on some events. Progress is advisory; the awaited promise is the authoritative signal.

What gets indexed

Documents are split into chunks of up to chunkSize characters overlapping by up to chunkOverlap, each prefixed with a title (the document’s title or first heading, else the file name) that is part of the hit text returned by query. Repeating page headers, footers, page numbers, and images are excluded from the indexed text. A scanned or image-only document produces no readable text unless OCR runs - if a file fails with “No readable text was found”, retry with parseOptions: { ocrMode: 'full_ocr' }.

Querying a parse-built index

Query the index without loading it - client.query(name, text) runs server-side when the index is not loaded locally:
Local text queries are not yet supported for parse-built indexes: after loadIndex(), a plain text query() throws. Either query without loading the index, or pass your own query embedding via QueryOptions.embedding.

Errors

Failures throw a MossError; message is fixed text, detail starts with:

Python

Same behavior and limits; there is no progress callback in Python. See the Python guide.

Browser

@moss-dev/moss-web also exposes createIndexFromFiles, with a reduced surface: files must supply data as a Uint8Array (no path), and parseOptions and progress reporting are not available. See Browser vs Node.