Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.moorcheh.ai/llms.txt

Use this file to discover all available pages before exploring further.

documents.upload_file

Uploads a file to a text namespace. The SDK automatically requests a pre-signed upload URL, uploads the file bytes, and the backend processes and embeds the content asynchronously.

Parameters

namespace_name
str
required
The name of the target text namespace.
file_path
str | Path | BinaryIO
required
Path to a local file (str or Path) or a file-like object (BinaryIO).
Returns: Dict[str, Any] - A dictionary confirming the file upload request. Common response fields include success, message, namespace, file_name, and file_size. Raises: NamespaceNotFound, InvalidInputError, AuthenticationError, APIError, MoorchehError.

Example

Upload File Example
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    status = client.documents.upload_file(
        namespace_name="my-faq-documents",
        file_path="C:/path/to/document.pdf"
    )
    print(status)

Input Options

You can pass either a file path or a file-like object.
File Path Or File-Like Object
from pathlib import Path
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    # Option 1: Path
    result_a = client.documents.upload_file(
        namespace_name="my-faq-documents",
        file_path=Path("C:/path/to/guide.md")
    )

    # Option 2: File-like object
    with open("C:/path/to/data.csv", "rb") as f:
        result_b = client.documents.upload_file(
            namespace_name="my-faq-documents",
            file_path=f
        )

    print(result_a)
    print(result_b)

Complete Example

Complete File Upload Workflow
from moorcheh_sdk import MoorchehClient
import time

with MoorchehClient() as client:
    # 1. Create a namespace (once)
    client.namespaces.create("my-data", type="text")

    # 2. Upload a file
    upload_result = client.documents.upload_file(
        namespace_name="my-data",
        file_path="C:/path/to/product-faq.pdf"
    )
    print(f"Upload response: {upload_result}")

    # 3. Wait for processing before querying/searching
    print("Waiting for file processing...")
    time.sleep(5)

Important Notes

SDK handles pre-signed upload internally: You do not need to call the upload URL endpoint manually when using documents.upload_file.
Asynchronous Processing: Uploaded files are processed asynchronously. Allow some time after upload before searching.
Supported file types only: .pdf, .docx, .xlsx, .json, .txt, .csv, .md.
File size limit: Maximum upload size is 5GB.

Best Practices

  • Use clear, stable file names so ingestion and auditing are easier
  • Keep source files clean and well-structured for better extraction quality
  • Use markdown or plain text when possible for predictable parsing
  • Upload large datasets in multiple files rather than one huge file
  • Wait briefly before running search queries after upload
  • Handle upload exceptions and retry transient failures

File Limits

  • File Size: Max 5GB
  • Supported Types: .pdf, .docx, .xlsx, .json, .txt, .csv, .md
  • Upload URL Expiry: Internally handled by SDK (short-lived pre-signed URL)
  • Fetch Text Data - List ingested text and summary chunks
  • Search - Query uploaded and processed content
  • Delete Data - Remove documents or entries from a namespace