Document training lets you add source files to a Kommander knowledge base. Kommander extracts text from each uploaded file, stores the original or prepared source, indexes the extracted content for retrieval, and makes the source available when the assistant answers related questions.

Use document training for longer source material such as policies, manuals, product sheets, onboarding guides, terms, and support procedures. Use FAQ training when the assistant needs a short approved answer, and use URL training when the source is a public web page.

Supported Formats

The current document extraction code supports these general-purpose document formats:

FormatMIME typeExtraction pathNotes
PDFapplication/pdfpdf-parse, with a pdftotext fallback in the smart file readerWorks best when the PDF has selectable embedded text. Scanned PDFs may need OCR before they produce useful text.
DOCXapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentmammoth.extractRawTextExtracts raw document text. Complex styling, comments, and layout are not preserved for retrieval.
TXTtext/plainUTF-8 buffer readBest for predictable ingestion when you already have clean plain text.

The GridFS upload action also accepts text/csv for structured CSV ingestion, and the training UI may show additional extensions for adjacent workflows. For document training, PDF, DOCX, and TXT are the reliable formats to prepare when you expect natural-language retrieval from uploaded source material.

Files uploaded through the GridFS action are limited to 5 MB. Larger source material should be split into smaller files with clear filenames and topic boundaries.

Processing Flow

Diagram description: the user uploads a supported document, Kommander stores the source, starts a background ingestion job, extracts text, handles OCR-required documents, chunks and embeds the extracted text, and later retrieves matching chunks during chat.

Text Extraction And OCR

Kommander first tries to extract selectable text from the uploaded file.

For PDFs, the in-repo extractors use pdf-parse in the training upload summary path. The smart file reader also tries pdftotext first when available, then falls back to pdf-parse, alternate parse options, and finally basic PDF metadata. If no meaningful text is found, the PDF is treated as a scanned or image-only document.

For DOCX files, Kommander uses Mammoth to read raw text from the document body. For TXT files, Kommander reads the UTF-8 text directly from the file buffer.

OCR is relevant only when a file contains images of text rather than embedded text. In that case, the practical pipeline is:

  1. Detect that normal text extraction returned empty, very short, or metadata-only content.
  2. Convert the scanned page images to text with OCR before indexing.
  3. Normalize the OCR text into plain text.
  4. Continue with the same chunking and indexing path used for normal extracted text.

The current repository does not expose OCR configuration or OCR accuracy controls in the product UI. When a scanned PDF does not produce usable text, prepare an OCRed PDF or upload the extracted text as a TXT file for the most predictable result.

Storage

Document sources are stored separately from the vector index.

The active training upload path stores the uploaded object in the assistant knowledge-base storage bucket and sends a rag/ingest_file background event. The ingestion worker indexes the file asynchronously, so the upload response confirms that ingestion has started, not that retrieval is already live.

The GridFS document action stores raw uploaded files in MongoDB GridFS using the file_uploads bucket. It also writes metadata to raw_files_meta with the filename, MIME type, file length, upload time, owner or organization scope, and the gridFsFileId. Generated summaries are stored in file_summaries and linked back to the GridFS file ID.

GridFS keeps the original file bytes available for later retrieval, summarization, and smart file context. Qdrant stores the searchable chunks used by retrieval, not the original binary file.

Chunking Strategy

The ingestion worker treats the extracted document text as the source of truth for retrieval. It cleans the extracted text, splits it into smaller chunks, embeds each chunk, and stores the chunk vectors with source metadata such as the filename. Smaller chunks make retrieval more precise because the assistant can match the specific section that answers the user’s question instead of pulling an entire long document into context.

Operationally, prepare documents so chunk boundaries are useful:

  • Keep one topic or policy family per file when possible.
  • Use headings and short sections so chunk text has enough local context.
  • Avoid mixing obsolete and current policy versions in the same file.
  • Split very long manuals into focused files if users normally ask about one section at a time.

During chat, Kommander retrieves the most relevant indexed chunks and builds grounded context for the answer. Separately, the GridFS smart file reader may load recent or relevant stored files, extract their text on demand, and truncate each selected file to 8,000 characters before adding it to prompt context. That prompt-time truncation is not the vector indexing chunk size; it is a guardrail for chat context size.

Indexing Latency

Document indexing is asynchronous.

After upload, the UI can show progress for the upload request and then returns once the file has been accepted and the background ingest job has started. Indexing normally completes shortly after the background worker extracts, chunks, embeds, and writes the content to the vector index. Small TXT and DOCX files are usually available sooner than large PDFs because extraction is simpler.

Expect a short delay before a newly uploaded document affects answers. In normal conditions, plan for seconds to a few minutes. Larger files, scanned PDFs that require OCR preparation, unavailable PDF extraction tools, or a busy ingestion queue can extend that window.

If a document does not appear in answers after indexing should have finished:

  • Confirm the file is PDF, DOCX, or TXT.
  • Confirm the file has extractable text.
  • Try a focused question that uses terms from the document heading or body.
  • Re-upload as TXT if PDF extraction produced little or no text.
  • Delete or refresh older conflicting sources if answers cite outdated material.

Retrieval And Source Management

Document chunks live in the same retrieval system used by other knowledge-base sources. When a user asks a question, the RAG layer searches the assistant’s indexed content and returns the most relevant matches as answer context.

Source metadata matters. Use descriptive filenames such as returns-policy-2026.pdf or installation-guide-router-x.docx, because filenames can be used for display, filtering, deletion, and operational debugging.

Deleting a document source removes indexed vectors for that source where the deletion path is available. It does not rewrite past conversations that already cited the document, and it does not remove separate FAQ or web-source entries that contain similar text.

Knowledge Audiences

One assistant can serve several knowledge bases, for example one for licenza-personale customers and one for licenza-movolab customers. In Training, open Audience on a document, web page or FAQ and list the audiences it is reserved to, separated by commas. Keys are saved as lowercase slugs (Licenza Movolab becomes licenza-movolab). Content without an audience is Shared.

On the website, pass the visitor’s audience to the widget:

window.initKommanderChatbot({ organizationId: 'YOUR_ID', audience: 'licenza-movolab' });

Answers then use the shared content plus the content tagged with that audience. Visitors without an audience, and WhatsApp and Instagram conversations, only get shared content. Re-uploading a document or re-scraping a page keeps its audiences, and so does editing a FAQ.

The audience selects content: it is sent by the visitor’s browser, so it is not access control. Never rely on it to hide confidential documents.

Best Practices

  • Prefer clean TXT or DOCX when you control the source format.
  • Use PDFs with selectable text, not screenshots of text.
  • OCR scanned files before upload, then spot-check the text.
  • Keep files focused and current.
  • Use headings that match customer language.
  • Remove old policy versions before uploading replacements.
  • Test important documents with real customer questions after indexing completes.