Files & Retrieval turns an upload into model context through upload checks, extraction, OCR, full-text injection, embedding, RAG, and compaction. This page shows the real order, the fallbacks, and the setting keys behind each stage.

Where to find it#

Admin console > Files & retrieval. The page groups settings as Upload limits, Content extraction, Full-text injection, Vector retrieval, Semantic enhancement, and RAG. Context compaction lives in Conversation > Context management.

How a file becomes context#

  1. Upload checks count, size, MIME type, and the user's storage quota.
  2. The file is stored and its type is detected.
  3. Text is extracted. Images use OCR, and PDFs can fall back to OCR.
  4. Each attachment is assigned a context mode:
    • A current or user-message image is sent as a direct image.
    • Otherwise the system chooses full-text injection or RAG.
  5. For RAG attachments, the query is embedded and chunks are retrieved, filtered by similarity, and bounded by the token budget.
  6. If retrieval returns nothing, fails, or times out, the attachment falls back to full text when it fits the limits, otherwise it is skipped.
  7. The assembled context is trimmed by token budget and compacted when it exceeds the turn or token trigger.

The full-text or RAG decision for Auto mode is:

  • Use RAG when the file cannot be injected in full, or when token-budget protection is on and the file text exceeds 40% of the model's effective input budget.
  • Use full text otherwise.

Full context mode never uses RAG. Vector retrieval mode always prefers RAG, but falls back to full text when a file is not retrievable. The user-side chat.file_mode setting is only a personal preference; the platform still applies its own limits.

Upload limits#

SettingKeyNotes
Attachment limitstorage.max_message_files1–50 files per message.
Default size limitstorage.max_upload_file_bytesDefault single-file limit. The UI uses MB.
User storage quotastorage.user_storage_quota_bytesTotal storage per user. The UI uses MB; 0 is unlimited.
Attachment MIME allowlistfile.allowed_mime_typesComma-separated. Only listed types can be uploaded.
Image size limitfile.image_max_bytesOverrides the default for images. Empty uses the default.
Document size limitfile.doc_max_bytesOverrides the default for documents. Empty uses the default.

The effective image or document limit is the smaller of the default limit and the override. If a MIME type is not on the allowlist, the upload is rejected before extraction runs.

Content extraction and OCR#

SettingKeyNotes
Extraction engineextract.enginebuiltin, tika, docling, or mineru.
Tika source / URL / key / timeoutextract.tika_source, extract.tika_base_url, extract.tika_auth_token, extract.tika_timeout_secondsSource is external or managed.
Docling URL / key / timeoutextract.docling_base_url, extract.docling_auth_token, extract.docling_timeout_secondsFor layout-heavy documents.
MinerU source / URL / types / key / timeoutextract.mineru_source, extract.mineru_base_url, extract.mineru_file_types, extract.mineru_auth_token, extract.mineru_timeout_secondsSource is cloud or self_hosted. Types are pdf, word, presentation, excel.
Image OCRextract.image_ocr_enabledSends image attachments through OCR. Off by default.
PDF OCR fallbackextract.pdf_ocr_fallback_enabledRuns OCR when native PDF text is missing or poor. Off by default.
OCR engineextract.ocr_enginerapidocr, tesseract, paddle, tencent, aliyun, mistral, or llm.

When the selected engine does not support a file, the platform falls back to the built-in extractor for document files. For PDFs with OCR fallback on, it first probes the native text layer and runs selective OCR only on weak pages, then falls back to full OCR if needed.

Each OCR engine needs its own connection fields, for example extract.rapidocr_base_url, extract.tesseract_ocr_base_url, extract.paddle_ocr_base_url, extract.tencent_ocr_secret_id, extract.aliyun_ocr_access_key_id, extract.mistral_ocr_base_url, and extract.llm_ocr_base_url. Image OCR uses the configured vision model for llm; Mistral needs a base URL, API key, and model.

If image OCR is off, an image is stored without extracted text and can only be sent to a vision-capable model. If extraction fails on a document, the file stays previewable but has no searchable text.

Full-text injection#

Full-text injection puts the extracted text directly into the model context. It is exact and works well for small files, contracts, and short code, but it consumes context.

SettingKeyNotes
Full-text injection limitsfile.full_context_limit_enabledWhen off, the size, token, and page limits are ignored.
Full-text size limitfile.file_full_context_max_bytesExtracted text bytes. The UI uses MB; empty or 0 is unlimited.
Full-text token limitfile.full_context_max_tokensToken budget. Empty or 0 is unlimited.
Full-text page limitfile.full_context_pdf_max_pagesPDF pages. Empty or 0 is unlimited.

A video is never injected as full text. A file is injected only when it has non-empty text and stays within every enabled limit. Files that do not fit move to RAG when retrieval is available, otherwise they are skipped.

Vector retrieval and embedding#

Embedding must be enabled and configured before RAG or semantic recall can be turned on. Changing the model, dimensions, or endpoint marks existing vectors stale.

SettingKeyNotes
Enable Embeddingfile.embedding_enabledRequired for vectorization and retrieval.
Embedding service URL / auth keyfile.embedding_host, file.embedding_keyThe service must be OpenAI /embeddings compatible.
Embedding modelfile.rag_modelChanging it invalidates old vectors.
Embedding timeoutfile.embedding_timeout_secondsPer-request wait in seconds.
Vector dimensionsfile.embedding_output_dimensions64–4096. Must match the model output.
Dimensions request policyfile.embedding_dimensions_policysend includes dimensions; omit drops it but still validates the returned vector against the configured dimensions.
Normalize vectorsfile.embedding_normalizeL2-normalizes vectors before storage and retrieval.
Auto-vectorizefile.embed_trigger_on_uploadTriggers embedding after upload.
Batch sizefile.embed_batch_sizeText chunks per embedding request.
Chunk sizefile.embed_chunk_size_tokensToken-estimated chunk size.
Chunk overlapfile.embed_chunk_overlap_tokensToken overlap between chunks.
Retrieved chunksfile.rag_top_kFinal chunks returned and injected, 1–50.

Use omit for services that reject the dimensions parameter. The returned vector is still checked against file.embedding_output_dimensions, so a mismatch fails instead of storing a wrong-size vector.

Vector index status#

The status panel shows a model signature and counts per state. The signature is generated automatically after the first save.

StateMeaningAction
ReadyVectors match the current signature.Retrieval works.
StaleThe model, dimensions, or endpoint changed.Use Rebuild index.
PendingFiles are queued or processing.Wait before testing retrieval.
No textExtraction produced no text, so there is nothing to embed.Check extraction, or use Reindex including no-text files after fixing OCR.
FailedVectorization failed.Check extracted text, the embedding service, and chunk settings.

When no index exists yet, the panel shows that no data is available until the embedding service is configured. If any vectors are stale, a reindex warning appears. Rebuilding is a background task and takes longer as the file count grows.

RAG#

SettingKeyNotes
RAGchat.rag_enabledRequires a ready embedding service.
Similarity thresholdchat.rag_min_similarityMinimum score for an injected chunk.
Injected token budgetchat.rag_token_budgetContext budget for retrieved chunks.
Fetch multiplierchat.rag_fetch_multiplierFetches top_k × multiplier candidates before filtering.
Ready waitchat.rag_wait_ready_msMaximum wait for retrieval before sending.
Query history turnschat.rag_query_history_turnsRecent user turns added to the retrieval query.
Retrieval cache TTLchat.rag_retrieval_cache_ttl_secondsCaches retrieval results; 0 disables the cache.
Hybrid retrievalchat.rag_hybrid_enabledRuns vector and full-text search in parallel and merges with RRF.

The cache key includes the query, the embedding host and model, dimensions, retrieval settings, and each file's ID, chunk count, embed status, and updated time, so editing a file invalidates its cached results.

A high threshold can return nothing; a low threshold adds noise. When no chunk passes, the system does not inject unrelated content. It falls back to full text for those attachments when they fit, otherwise it skips them. If a knowledge base was explicitly selected, an unavailable knowledge base stops the send, while an empty result adds a notice that there is no knowledge-base evidence.

Semantic enhancement#

SettingKeyNotes
Message embeddingchat.message_embedding_enabledGenerates message vectors after each turn. Requires the embedding service.
Semantic context recallchat.semantic_context_enabledRecalls historically relevant snippets before sending. Requires message embedding.

Enabling semantic context recall while message embedding is off is rejected. Both features share the embedding service, so an embedding change also affects historical recall quality.

Context compaction#

Compaction is configured in Conversation > Context management. It summarizes older turns so long conversations stay inside the model budget.

SettingKeyNotes
Context compressionchat.context_compact_enabledMaster switch; users can still opt out in chat settings.
Token budget protectionchat.context_token_budget_enabledTrims history by the model's effective input budget.
Compression trigger turnschat.context_max_turnsTrigger when the conversation exceeds this turn count; 0 disables it.
Default context windowchat.context_window_fallback_tokensUsed when the model window cannot be identified.
Compression trigger ratiochat.context_compact_trigger_percentTrigger at this percentage of the effective input budget; 0 disables it.
Recent turns to preservechat.context_compact_preserve_recent_turnsRecent raw turns kept during compression.
Highlights per rolechat.context_compact_highlights_per_roleSummary highlights per user and assistant role.
Snippet character limitchat.context_compact_snippet_charsMaximum characters in one message snippet.
Evidence retention dayschat.context_artifact_retention_daysRetention for RAG, history, and tool evidence; 0 disables expiry.
Background compressionchat.compact_async_enabledRuns compression after the response.
LLM compressionchat.compact_llm_enabledUses a model for semantic summaries; off uses template summaries only.
Compression modelchat.compact_task_modelfollow uses the current model, falling back to the default chat model.
Circuit thresholdchat.compact_max_failuresAfter this many consecutive failures, falls back to template summaries.
Full / light summary promptchat.compact_system_prompt, chat.compact_light_promptCustom summary instructions.

Fallback rules#

ConditionBehavior
Upload check failsThe file is rejected.
Extraction failsThe file is previewable but has no searchable text.
OCR is off or failsImage or scanned text stays unavailable to non-vision models.
Full text exceeds a limitThe file moves to RAG, or is skipped if retrieval is unavailable.
Embedding is offRAG and semantic recall are unavailable.
Index is stale or failedRetrieval is incomplete; rebuild the index.
RAG returns nothingNo unrelated chunks are injected; full text is used when it fits.
Context is too longToken-budget trimming or compaction runs.

Verify the setup#

  1. Set upload count, size, MIME, image and document limits, and the storage quota.
  2. Configure an extraction engine and test PDF, Word, spreadsheet, and text files.
  3. Enable image OCR and PDF OCR fallback only where needed, then configure the matching engine.
  4. Turn on full-text injection limits for small documents.
  5. Configure the embedding service, model, dimensions, chunking, and auto-vectorization.
  6. Upload sample files and confirm the index state is Ready.
  7. Turn on RAG and tune similarity, top K, token budget, and hybrid retrieval.
  8. For long sessions, turn on message embedding, semantic recall, and compaction.

Troubleshooting#

SymptomCauseFix
Upload is rejectedMIME type, size, count, or quota.Check the allowlist and the size and quota limits.
The model cannot answer from a fileExtraction failed or the index is not ready.Check the extract status, preview text, and index state.
A PDF has no textIt is a scan and PDF OCR fallback is off.Turn on PDF OCR fallback and configure an OCR engine.
RAG returns nothingThe threshold is too high, the index is stale, or no chunks exist.Lower the threshold, rebuild the index, and check file.rag_top_k.
Retrieval is slowThe embedding service is slow or chat.rag_wait_ready_ms is high.Check the service latency and lower the wait.
Results ignore earlier turnsMessage embedding or semantic recall is off.Turn on message embedding, then semantic context recall.
Long chats lose early factsCompaction triggers too late or preserves too few turns.Lower the trigger percent and raise the preserved turns.

Reference: setting keys#

StageKeys
Upload limitsstorage.max_message_files, storage.max_upload_file_bytes, storage.user_storage_quota_bytes, file.allowed_mime_types, file.image_max_bytes, file.doc_max_bytes
Extraction enginesextract.engine, extract.tika_source, extract.tika_base_url, extract.tika_auth_token, extract.tika_timeout_seconds, extract.docling_base_url, extract.docling_auth_token, extract.docling_timeout_seconds, extract.mineru_source, extract.mineru_base_url, extract.mineru_file_types, extract.mineru_auth_token, extract.mineru_timeout_seconds
OCR switchesextract.image_ocr_enabled, extract.pdf_ocr_fallback_enabled, extract.ocr_engine
Local OCRextract.rapidocr_source, extract.rapidocr_base_url, extract.rapidocr_auth_token, extract.rapidocr_timeout_seconds, extract.tesseract_ocr_base_url, extract.tesseract_ocr_auth_token, extract.tesseract_ocr_timeout_seconds, extract.paddle_ocr_base_url, extract.paddle_ocr_auth_token, extract.paddle_ocr_timeout_seconds
Cloud and LLM OCRextract.tencent_ocr_secret_id, extract.tencent_ocr_secret_key, extract.tencent_ocr_region, extract.tencent_ocr_endpoint, extract.tencent_ocr_timeout_seconds, extract.aliyun_ocr_access_key_id, extract.aliyun_ocr_access_key_secret, extract.aliyun_ocr_region, extract.aliyun_ocr_endpoint, extract.aliyun_ocr_timeout_seconds, extract.mistral_ocr_base_url, extract.mistral_ocr_auth_token, extract.mistral_ocr_model, extract.mistral_ocr_timeout_seconds, extract.llm_ocr_base_url, extract.llm_ocr_auth_token, extract.llm_ocr_model, extract.llm_ocr_timeout_seconds, extract.llm_ocr_prompt
Full-text injectionfile.full_context_limit_enabled, file.file_full_context_max_bytes, file.full_context_max_tokens, file.full_context_pdf_max_pages
Embeddingfile.embedding_enabled, file.embedding_host, file.embedding_key, file.rag_model, file.embedding_timeout_seconds, file.embedding_output_dimensions, file.embedding_dimensions_policy, file.embedding_normalize, file.embed_trigger_on_upload, file.embed_batch_size, file.embed_chunk_size_tokens, file.embed_chunk_overlap_tokens
Semantic enhancementchat.message_embedding_enabled, chat.semantic_context_enabled
RAGchat.rag_enabled, file.rag_top_k, chat.rag_min_similarity, chat.rag_token_budget, chat.rag_fetch_multiplier, chat.rag_wait_ready_ms, chat.rag_query_history_turns, chat.rag_retrieval_cache_ttl_seconds, chat.rag_hybrid_enabled
Compactionchat.context_compact_enabled, chat.context_token_budget_enabled, chat.context_max_turns, chat.context_window_fallback_tokens, chat.context_compact_trigger_percent, chat.context_compact_preserve_recent_turns, chat.context_compact_highlights_per_role, chat.context_compact_snippet_chars, chat.context_artifact_retention_days, chat.compact_async_enabled, chat.compact_llm_enabled, chat.compact_task_model, chat.compact_max_failures, chat.compact_system_prompt, chat.compact_light_prompt