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-dev/moss 1.7.1+. Also available in Python as
create_index_from_files (moss 1.7.3+).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 throughonProgress) and resolves to a
MutationResult when the index is ready. Jobs time out after
30 minutes.
Files
Each entry is aParseFileInput:
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
pathon Node.js. In-memorydatais copied byte by byte across the native boundary, which is memory-hungry for large files.
Options
CreateIndexFromFilesOptions:
Parse options
All fields ofParseOptions are optional; omitted fields use the
server defaults.
Progress
onProgress receives a JobProgress roughly every 2 seconds
while the server is working (there is no per-byte upload progress):
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 parsed into retrieval-sized chunks with layout awareness. Repeating page headers, footers, and page numbers 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 withparseOptions: { 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:
Errors
Failures throw a plainError. Common messages:
Python
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.