Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions memorylayer-sdk-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ print(trace["chain"])
```python
# Perform multiple operations in one request
results = await client.batch_memories([
{"type": "create", "data": {"content": "Memory 1", "importance": 0.7}},
{"type": "create", "data": {"content": "Memory 2", "importance": 0.8}},
{"type": "delete", "data": {"memory_id": "mem_old", "hard": False}}
{"op": "create", "content": "Memory 1", "importance": 0.7},
{"op": "create", "content": "Memory 2", "importance": 0.8},
{"op": "update", "memory_id": "mem_123", "tags": ["reviewed"]},
{"op": "delete", "memory_id": "mem_old", "hard": False},
])
print(f"Successful: {results['successful']}, Failed: {results['failed']}")
```
Expand Down
2 changes: 1 addition & 1 deletion memorylayer-sdk-python/src/memorylayer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"ChatThread",
"ChatThreadWithMessages",
"DecompositionResult",
# Document models (Enterprise)
# Document models
"DocumentInfo",
"DocumentPage",
"JobInfo",
Expand Down
39 changes: 27 additions & 12 deletions memorylayer-sdk-python/src/memorylayer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,22 +1976,32 @@ async def batch_memories(
"""
Perform multiple memory operations in a single request.

Supported operation types:
- create: {"type": "create", "data": {"content": "...", ...}}
- update: {"type": "update", "data": {"memory_id": "...", "content": "..."}}
- delete: {"type": "delete", "data": {"memory_id": "...", "hard": False}}
Each operation is a flat object discriminated by ``op``:
- create: {"op": "create", "content": "...", "type": ..., "subtype": ...,
"importance": 0.5, "tags": [...], "metadata": {...},
"observer_id": ..., "subject_id": ...}
- update: {"op": "update", "memory_id": "...", "content": ..., "type": ...,
"subtype": ..., "importance": ..., "tags": [...], "metadata": {...},
"pinned": ...}
- delete: {"op": "delete", "memory_id": "...", "hard": False}

Only ``op`` and ``content`` (create) or ``memory_id`` (update/delete) are
required. An operation without an ``op`` field fails request validation.

Args:
operations: List of operations to perform

Returns:
Results for each operation with success/error status
Dict with ``total_operations``, ``successful``, ``failed`` and a
per-operation ``results`` list (``index``, ``type``, ``status``,
``memory_id``, ``error``).

Example:
results = await client.batch_memories([
{"type": "create", "data": {"content": "Memory 1"}},
{"type": "create", "data": {"content": "Memory 2"}},
{"type": "delete", "data": {"memory_id": "mem_old"}}
{"op": "create", "content": "Memory 1"},
{"op": "create", "content": "Memory 2", "importance": 0.8},
{"op": "update", "memory_id": "mem_123", "tags": ["reviewed"]},
{"op": "delete", "memory_id": "mem_old"},
])
"""
payload = {"operations": operations}
Expand Down Expand Up @@ -2820,7 +2830,7 @@ async def decompose_thread(
return DecompositionResult(**data)

# ------------------------------------------------------------------ #
# Document operations (Enterprise)
# Document operations
# ------------------------------------------------------------------ #

async def upload_document(
Expand All @@ -2838,8 +2848,10 @@ async def upload_document(
"""
Upload a document for ingestion.

Requires MemoryLayer Enterprise. On OSS servers this raises
``EnterpriseRequiredError``.
Supported by the core server. Ingestion runs as a background job; poll
``get_job(job.id)`` or ``get_document(document.id)`` for progress.
``chunking_strategy`` and ``chunk_overlap`` are sent for servers that
support them; the core server ignores them.

Args:
file_data: Raw file bytes.
Expand Down Expand Up @@ -2951,7 +2963,10 @@ async def search_document_pages(
"""
Search document pages using ColPali MaxSim visual similarity.

Requires MemoryLayer Enterprise.
Requires an embed-server peer that serves ColPali multi-vector
embeddings and a storage backend that supports page search. When the
backend does not support it the server returns 501, raised here as
``EnterpriseRequiredError``.

Args:
query: Natural language search query.
Expand Down
10 changes: 5 additions & 5 deletions memorylayer-sdk-python/src/memorylayer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ class DecompositionResult(BaseModel):


# ------------------------------------------------------------------ #
# Document models (Enterprise)
# Document models
# ------------------------------------------------------------------ #


class DocumentPage(BaseModel):
"""A page from an ingested document (Enterprise)."""
"""A page from an ingested document."""

id: str
document_id: str
Expand All @@ -428,7 +428,7 @@ class DocumentPage(BaseModel):


class DocumentInfo(BaseModel):
"""Document metadata returned from the API (Enterprise)."""
"""Document metadata returned from the API."""

id: str
workspace_id: str
Expand All @@ -451,7 +451,7 @@ class DocumentInfo(BaseModel):


class JobInfo(BaseModel):
"""Ingestion job status (Enterprise)."""
"""Ingestion job status."""

id: str
workspace_id: str
Expand All @@ -467,7 +467,7 @@ class JobInfo(BaseModel):


class PageSearchResult(BaseModel):
"""Result from a document page search (Enterprise)."""
"""Result from a document page search."""

pages: list[DocumentPage]
total_count: int
Expand Down
32 changes: 21 additions & 11 deletions memorylayer-sdk-python/src/memorylayer/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,22 +1150,32 @@ def batch_memories(
"""
Perform multiple memory operations in a single request.

Supported operation types:
- create: {"type": "create", "data": {"content": "...", ...}}
- update: {"type": "update", "data": {"memory_id": "...", "content": "..."}}
- delete: {"type": "delete", "data": {"memory_id": "...", "hard": False}}
Each operation is a flat object discriminated by ``op``:
- create: {"op": "create", "content": "...", "type": ..., "subtype": ...,
"importance": 0.5, "tags": [...], "metadata": {...},
"observer_id": ..., "subject_id": ...}
- update: {"op": "update", "memory_id": "...", "content": ..., "type": ...,
"subtype": ..., "importance": ..., "tags": [...], "metadata": {...},
"pinned": ...}
- delete: {"op": "delete", "memory_id": "...", "hard": False}

Only ``op`` and ``content`` (create) or ``memory_id`` (update/delete) are
required. An operation without an ``op`` field fails request validation.

Args:
operations: List of operations to perform

Returns:
Results for each operation with success/error status
Dict with ``total_operations``, ``successful``, ``failed`` and a
per-operation ``results`` list (``index``, ``type``, ``status``,
``memory_id``, ``error``).

Example:
results = client.batch_memories([
{"type": "create", "data": {"content": "Memory 1"}},
{"type": "create", "data": {"content": "Memory 2"}},
{"type": "delete", "data": {"memory_id": "mem_old"}}
{"op": "create", "content": "Memory 1"},
{"op": "create", "content": "Memory 2", "importance": 0.8},
{"op": "update", "memory_id": "mem_123", "tags": ["reviewed"]},
{"op": "delete", "memory_id": "mem_old"},
])
"""
payload = {"operations": operations}
Expand Down Expand Up @@ -2125,7 +2135,7 @@ def decompose_thread(
return DecompositionResult(**data)

# ------------------------------------------------------------------ #
# Document operations (Enterprise)
# Document operations
# ------------------------------------------------------------------ #

def upload_document(
Expand All @@ -2140,7 +2150,7 @@ def upload_document(
importance: float = 0.5,
retain_original: bool = True,
) -> tuple[DocumentInfo, JobInfo]:
"""Upload a document for ingestion (Enterprise)."""
"""Upload a document for background ingestion (supported by the core server)."""
client = self._ensure_client()

try:
Expand Down Expand Up @@ -2225,7 +2235,7 @@ def search_document_pages(
limit: int = 10,
doc_ids: list[str] | None = None,
) -> PageSearchResult:
"""Search document pages using ColPali MaxSim (Enterprise)."""
"""Search document pages using ColPali MaxSim (needs a ColPali embed-server peer)."""
payload: dict[str, Any] = {"query": query, "limit": limit}
if doc_ids:
payload["doc_ids"] = doc_ids
Expand Down
Loading