Skip to content

Document Ingestion

MemoryLayer can ingest documents and email, extract their content, and automatically create memories from it. Supported document types are Markdown, plain text, code, HTML, PDF, DOCX, PPTX, and images (described with LLM vision).

Document ingestion is part of core MemoryLayer. Markdown, text, code, and HTML need no extras. For PDF and Office files, install the parsers: pip install "memorylayer-server[documents]", or [pdf] / [office] separately. The official Docker image includes them. ColPali visual page indexing uses the memorylayer-embed-server peer’s [colpali] extra (or [gpu] for the full bundle). MemoryLayer Enterprise adds a PostgreSQL-backed pipeline with background workers, layout-aware OCR, and data connectors that feed documents in automatically.


Upload a Document

Upload a document using multipart/form-data. The server automatically detects the file type, extracts text content, and creates memories — no configuration required.

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/documents" \
-H "Authorization: Bearer $API_KEY" \
-F "file=@report.pdf"

You can optionally specify a context and importance level:

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/documents" \
-H "Authorization: Bearer $API_KEY" \
-F "file=@report.pdf" \
-F "target_context_id=project-docs" \
-F "importance=0.7"
ParameterDefaultDescription
file(required)The document file (max 50 MB, MEMORYLAYER_DOCUMENT_MAX_FILE_SIZE)
document_typedetectedOverride the detected type
target_context_id_defaultMemory context for extracted memories
importance0.5Default importance for extracted memories (0.0–1.0)
chunk_size4096Maximum chunk size in characters
retain_originaltrueKeep the raw file content in storage

The response includes both the document record and the ingestion job:

{
"document": {
"id": "doc_abc123",
"workspace_id": "ws_001",
"filename": "report.pdf",
"document_type": "pdf",
"status": "pending",
"size_bytes": 204800,
"page_count": 0,
"chunk_count": 0,
"created_at": "2026-04-01T12:00:00Z"
},
"job": {
"id": "job_xyz789",
"status": "queued",
"progress_percent": 0,
"created_at": "2026-04-01T12:00:00Z"
}
}

Python SDK

from pathlib import Path
from memorylayer import MemoryLayerClient
async with MemoryLayerClient(base_url=MEMORYLAYER_URL, api_key=API_KEY) as client:
document, job = await client.upload_document(
Path("report.pdf").read_bytes(),
"report.pdf",
target_context_id="project-docs",
importance=0.7,
)
print(f"Document: {document.id}, Job: {job.id}")

The SDK also provides list_documents, get_document, delete_document, get_document_pages, search_document_pages, get_job, list_jobs, cancel_job, and reprocess_document.

The server automatically selects the best chunking strategy based on the document type (page-based for PDFs/PPTX, semantic for prose documents).

A document reaches completed as soon as its pages, transcripts, embeddings, and composite memories are durable, so it is searchable at that point. Fact decomposition and the enrichment that follows it keep running in the background after that.


Job Tracking

Check job status

Terminal window
curl "$MEMORYLAYER_URL/v1/documents/jobs/$JOB_ID" \
-H "Authorization: Bearer $API_KEY"

Response fields: status (queued, running, completed, failed, cancelled), progress_percent, documents_processed, total_memories_created, and errors.

List all jobs

Terminal window
curl "$MEMORYLAYER_URL/v1/documents/jobs?status=running&limit=20" \
-H "Authorization: Bearer $API_KEY"

Cancel a job

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/documents/jobs/$JOB_ID/cancel" \
-H "Authorization: Bearer $API_KEY"

Retrieve Extracted Memories

After processing completes, fetch the memories created from a document:

Terminal window
curl "$MEMORYLAYER_URL/v1/documents/$DOC_ID/memories" \
-H "Authorization: Bearer $API_KEY"

Each memory includes its id, content, type, importance, tags, and created_at.


Search Document Pages

Search ingested document pages using ColPali MaxSim (ColBERT-style late interaction) visual similarity:

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/documents/search" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "quarterly revenue chart",
"limit": 5,
"doc_ids": ["doc_abc123"]
}'
FieldTypeRequiredDescription
querystringyesNatural-language search query
limitintegerno (default 10, max 100)Maximum results to return
doc_idsstring[]noRestrict the search to a specific list of document IDs

Each result entry is a DocumentPageResponse with a relevance_score (sum of per-query-token max cosine similarities) on top of the usual page fields (id, document_id, page_no, transcript, metadata, etc.).

Requirements:

  • A running memorylayer-embed-server peer with [colpali] (or [gpu]) installed — the core server calls /v1/embeddings/multi to embed the query as a multi-vector.
  • An ingestion path that populated the multivector column on document_pages. ColPali multivectors are produced for image-bearing documents (PDFs, image-only files) when the embed server is configured to do so.

MemoryLayer (core) vs MemoryLayer Enterprise: Both expose the same POST /v1/documents/search endpoint with the same request and response shape. The core SQLite backend loads candidate pages’ multivectors from disk and scores them in Python. That is correct and works well for workspaces with up to a few thousand multi-vector pages. The MemoryLayer Enterprise PostgreSQL backend pushes MaxSim scoring into the database through a pgvector lateral subquery, which holds up under much larger corpora and concurrent query load. Only the storage-backend implementation differs.


List and Inspect Documents

Terminal window
# List documents with optional filters
curl "$MEMORYLAYER_URL/v1/documents?status=completed&document_type=pdf&limit=50" \
-H "Authorization: Bearer $API_KEY"
# Get a single document
curl "$MEMORYLAYER_URL/v1/documents/$DOC_ID" \
-H "Authorization: Bearer $API_KEY"

Reprocess a Document

Re-extract memories from a document without re-uploading the file:

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/documents/$DOC_ID/reprocess" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"extraction_options": {"importance": 0.8, "chunking_strategy": "semantic"}}'

extraction_options overrides the stored extraction settings, such as chunking_strategy (page, semantic, or fixed), chunk_size, and importance.

This creates a new ingestion job and regenerates memories from the stored document.


Delete a Document

Terminal window
# Delete document only
curl -X DELETE "$MEMORYLAYER_URL/v1/documents/$DOC_ID" \
-H "Authorization: Bearer $API_KEY"
# Delete document and its extracted memories
curl -X DELETE "$MEMORYLAYER_URL/v1/documents/$DOC_ID?delete_memories=true" \
-H "Authorization: Bearer $API_KEY"

Document Statuses

StatusMeaning
pendingUploaded, waiting for processing
pending_fetchWaiting for its bytes to be fetched by a data connector
processingExtraction in progress
completedAll chunks processed and memories created
failedProcessing encountered an error
partialSome chunks succeeded, others failed

Writing and deleting documents requires documents READWRITE access on the workspace (since 0.2.0; previously MANAGE).


Email Ingestion

POST /v1/ingest/email stores an email as a memory. The email goes through the same pipeline as chat and documents: decomposition, enrichment, and entity accretion. The endpoint takes JSON. It does not parse raw .eml or MIME, so extract the fields first.

Terminal window
curl -X POST "$MEMORYLAYER_URL/v1/ingest/email" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sender": "alice@example.com",
"to": ["bob@example.com"],
"subject": "Q3 launch date",
"body": "We are moving the launch to October 14 to finish the security review.",
"timestamp": "2026-08-30T16:20:00Z",
"thread_id": "thr-8841",
"message_id": "<msg-123@example.com>"
}'
FieldRequiredDescription
senderyesBecomes the memory’s observer_id (see Perspective & User Memory)
bodyyesEmail body text
tonoRecipients. Stored in metadata and mapped to sent_to relations.
subjectnoAdded to the grounded content and to metadata
timestampnoSend time. Becomes the memory’s event_time, so temporal recall works.
thread_id / message_idnoConversation linkage (thread_id is preferred, message_id is the fallback)
importancenoDefault 0.5
workspace_id, context_idnoTarget workspace and context
metadata, relationsnoExtra source metadata and typed relations

The response is 201 with the created memory. The content is stored as a semantic memory, prefixed with the date and subject for grounding. Metadata records source: "email", the sender, recipients, subject, and message ID. No SDK wraps this endpoint in 0.2.0.

Connector Metadata

Documents and email can carry knowledge-work metadata from the system they came from, such as owner, assignee, author, reviewer, approver, project, or organization. The server normalizes a known set of these fields into a standard profile under metadata["knowledge_work"] and turns them into typed knowledge-work relations such as owned_by and reviewed_by. Normalization is deterministic and never overwrites a profile you supply yourself.

Raw Ingestion Without Enrichment

Some deployments only need raw memories and document pages, not derived facts or relationship graphs. Set MEMORYLAYER_POST_STORE_ENRICHMENT_ENABLED=false (default true) to skip fact decomposition, tier generation, contradiction checks, and association/type enrichment after each write. Raw content, embeddings, provenance, and cache invalidation still run. Queued auto_enrich tasks exit without calling models, and existing derived records are kept. Restart the server and any workers after changing it.