diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b7ab6b5..3b93d2a 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.33.1" + ".": "3.34.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index b978975..2b69c4b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 26 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-3d1ed08ae874eafef0c275748f38e21c1e6a245ecad05db24dee27f4166f18db.yml -openapi_spec_hash: fa7ccfe7d4574c280f3189d020401032 -config_hash: f3eb5ca71172780678106f6d46f15dda +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-f09b91ede978d3fd05810d3750fcc837f8baa6430fa1be9208ba3088ecaef7f4.yml +openapi_spec_hash: 957d1e254f2f5933d0c22f3b310122e9 +config_hash: cde97ef3188581c5f4924c633ec33ddb diff --git a/CHANGELOG.md b/CHANGELOG.md index e64a56d..3e2658f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 3.34.0 (2026-04-18) + +Full Changelog: [v3.33.1...v3.34.0](https://github.com/supermemoryai/python-sdk/compare/v3.33.1...v3.34.0) + +### Features + +* **api:** api update ([5b92603](https://github.com/supermemoryai/python-sdk/commit/5b9260335ff2514491b0c41f6544872ee58485fb)) +* **api:** api update ([ab60a76](https://github.com/supermemoryai/python-sdk/commit/ab60a7657699fc974c8648adcb74a0dba9a4fe5b)) +* **api:** api update ([0950bae](https://github.com/supermemoryai/python-sdk/commit/0950bae08a126b09a2844839db673e99cfc13f75)) + + +### Performance Improvements + +* **client:** optimize file structure copying in multipart requests ([421e80e](https://github.com/supermemoryai/python-sdk/commit/421e80e55548a1ea7b348683e841060c350b56e7)) + ## 3.33.1 (2026-04-11) Full Changelog: [v3.33.0...v3.33.1](https://github.com/supermemoryai/python-sdk/compare/v3.33.0...v3.33.1) diff --git a/pyproject.toml b/pyproject.toml index 5959589..8e5b006 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "supermemory" -version = "3.33.1" +version = "3.34.0" description = "The official Python library for the supermemory API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/supermemory/_client.py b/src/supermemory/_client.py index 67a574c..2e7309e 100644 --- a/src/supermemory/_client.py +++ b/src/supermemory/_client.py @@ -4,7 +4,7 @@ import os from typing import TYPE_CHECKING, Any, Dict, Union, Mapping -from typing_extensions import Self, override +from typing_extensions import Self, Literal, override import httpx @@ -245,7 +245,9 @@ def add( container_tags: SequenceNotStr[str] | Omit = omit, custom_id: str | Omit = omit, entity_context: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -269,8 +271,14 @@ def add( entity_context: Optional entity context for this container tag. Max 1500 characters. Used during document processing to guide memory extraction. + filepath: Optional file path for the document. Used by supermemoryfs to store the full + path of the file. + metadata: Optional metadata for the document. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -288,7 +296,9 @@ def add( "container_tags": container_tags, "custom_id": custom_id, "entity_context": entity_context, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, client_add_params.ClientAddParams, ), @@ -561,7 +571,9 @@ async def add( container_tags: SequenceNotStr[str] | Omit = omit, custom_id: str | Omit = omit, entity_context: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -585,8 +597,14 @@ async def add( entity_context: Optional entity context for this container tag. Max 1500 characters. Used during document processing to guide memory extraction. + filepath: Optional file path for the document. Used by supermemoryfs to store the full + path of the file. + metadata: Optional metadata for the document. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -604,7 +622,9 @@ async def add( "container_tags": container_tags, "custom_id": custom_id, "entity_context": entity_context, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, client_add_params.ClientAddParams, ), diff --git a/src/supermemory/_files.py b/src/supermemory/_files.py index ae7c465..2378358 100644 --- a/src/supermemory/_files.py +++ b/src/supermemory/_files.py @@ -3,8 +3,8 @@ import io import os import pathlib -from typing import overload -from typing_extensions import TypeGuard +from typing import Sequence, cast, overload +from typing_extensions import TypeVar, TypeGuard import anyio @@ -17,7 +17,9 @@ HttpxFileContent, HttpxRequestFiles, ) -from ._utils import is_tuple_t, is_mapping_t, is_sequence_t +from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t + +_T = TypeVar("_T") def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]: @@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent: return await anyio.Path(file).read_bytes() return file + + +def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T: + """Copy only the containers along the given paths. + + Used to guard against mutation by extract_files without copying the entire structure. + Only dicts and lists that lie on a path are copied; everything else + is returned by reference. + + For example, given paths=[["foo", "files", "file"]] and the structure: + { + "foo": { + "bar": {"baz": {}}, + "files": {"file": } + } + } + The root dict, "foo", and "files" are copied (they lie on the path). + "bar" and "baz" are returned by reference (off the path). + """ + return _deepcopy_with_paths(item, paths, 0) + + +def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T: + if not paths: + return item + if is_mapping(item): + key_to_paths: dict[str, list[Sequence[str]]] = {} + for path in paths: + if index < len(path): + key_to_paths.setdefault(path[index], []).append(path) + + # if no path continues through this mapping, it won't be mutated and copying it is redundant + if not key_to_paths: + return item + + result = dict(item) + for key, subpaths in key_to_paths.items(): + if key in result: + result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1) + return cast(_T, result) + if is_list(item): + array_paths = [path for path in paths if index < len(path) and path[index] == ""] + + # if no path expects a list here, nothing will be mutated inside it - return by reference + if not array_paths: + return cast(_T, item) + return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item]) + return item diff --git a/src/supermemory/_utils/__init__.py b/src/supermemory/_utils/__init__.py index 10cb66d..1c090e5 100644 --- a/src/supermemory/_utils/__init__.py +++ b/src/supermemory/_utils/__init__.py @@ -24,7 +24,6 @@ coerce_integer as coerce_integer, file_from_path as file_from_path, strip_not_given as strip_not_given, - deepcopy_minimal as deepcopy_minimal, get_async_library as get_async_library, maybe_coerce_float as maybe_coerce_float, get_required_header as get_required_header, diff --git a/src/supermemory/_utils/_utils.py b/src/supermemory/_utils/_utils.py index 63b8cd6..771859f 100644 --- a/src/supermemory/_utils/_utils.py +++ b/src/supermemory/_utils/_utils.py @@ -177,21 +177,6 @@ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]: return isinstance(obj, Iterable) -def deepcopy_minimal(item: _T) -> _T: - """Minimal reimplementation of copy.deepcopy() that will only copy certain object types: - - - mappings, e.g. `dict` - - list - - This is done for performance reasons. - """ - if is_mapping(item): - return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()}) - if is_list(item): - return cast(_T, [deepcopy_minimal(entry) for entry in item]) - return item - - # copied from https://github.com/Rapptz/RoboDanny def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str: size = len(seq) diff --git a/src/supermemory/_version.py b/src/supermemory/_version.py index d364648..b36d0d7 100644 --- a/src/supermemory/_version.py +++ b/src/supermemory/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "supermemory" -__version__ = "3.33.1" # x-release-please-version +__version__ = "3.34.0" # x-release-please-version diff --git a/src/supermemory/resources/connections.py b/src/supermemory/resources/connections.py index 6ebc71a..56e25c8 100644 --- a/src/supermemory/resources/connections.py +++ b/src/supermemory/resources/connections.py @@ -417,6 +417,7 @@ def resources( connection_id: str, *, page: float | Omit = omit, + parent_id: str | Omit = omit, per_page: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -449,6 +450,7 @@ def resources( query=maybe_transform( { "page": page, + "parent_id": parent_id, "per_page": per_page, }, connection_resources_params.ConnectionResourcesParams, @@ -839,6 +841,7 @@ async def resources( connection_id: str, *, page: float | Omit = omit, + parent_id: str | Omit = omit, per_page: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -871,6 +874,7 @@ async def resources( query=await async_maybe_transform( { "page": page, + "parent_id": parent_id, "per_page": per_page, }, connection_resources_params.ConnectionResourcesParams, diff --git a/src/supermemory/resources/documents.py b/src/supermemory/resources/documents.py index 44688ff..c193aaf 100644 --- a/src/supermemory/resources/documents.py +++ b/src/supermemory/resources/documents.py @@ -15,8 +15,9 @@ document_delete_bulk_params, document_upload_file_params, ) +from .._files import deepcopy_with_paths from .._types import Body, Omit, Query, Headers, NoneType, NotGiven, FileTypes, SequenceNotStr, omit, not_given -from .._utils import extract_files, path_template, maybe_transform, deepcopy_minimal, async_maybe_transform +from .._utils import extract_files, path_template, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -66,7 +67,9 @@ def update( container_tags: SequenceNotStr[str] | Omit = omit, content: str | Omit = omit, custom_id: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -98,12 +101,18 @@ def update( custom_id: Optional custom ID of the document. This could be an ID from your database that will uniquely identify this document. + filepath: Optional file path for the document (e.g., '/documents/reports/file.pdf'). Used + by supermemoryfs to map documents to filesystem paths. + metadata: Optional metadata for the document. This is used to store additional information about the document. You can use this to store any additional information you need about the document. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -122,7 +131,9 @@ def update( "container_tags": container_tags, "content": content, "custom_id": custom_id, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_update_params.DocumentUpdateParams, ), @@ -136,6 +147,7 @@ def list( self, *, container_tags: SequenceNotStr[str] | Omit = omit, + filepath: str | Omit = omit, filters: document_list_params.Filters | Omit = omit, include_content: bool | Omit = omit, limit: Union[str, float] | Omit = omit, @@ -157,6 +169,9 @@ def list( your user, a project ID, or any other identifier you wish to use to group documents. + filepath: Filter documents by filepath. Exact match for full paths, prefix match if ending + with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_content: Whether to include the content field in the response. Warning: This can make @@ -183,6 +198,7 @@ def list( body=maybe_transform( { "container_tags": container_tags, + "filepath": filepath, "filters": filters, "include_content": include_content, "limit": limit, @@ -240,7 +256,9 @@ def add( container_tags: SequenceNotStr[str] | Omit = omit, custom_id: str | Omit = omit, entity_context: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -264,8 +282,14 @@ def add( entity_context: Optional entity context for this container tag. Max 1500 characters. Used during document processing to guide memory extraction. + filepath: Optional file path for the document. Used by supermemoryfs to store the full + path of the file. + metadata: Optional metadata for the document. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -283,7 +307,9 @@ def add( "container_tags": container_tags, "custom_id": custom_id, "entity_context": entity_context, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_add_params.DocumentAddParams, ), @@ -300,7 +326,9 @@ def batch_add( container_tag: str | Omit = omit, container_tags: SequenceNotStr[str] | Omit = omit, content: None | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -322,12 +350,18 @@ def batch_add( containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to group documents. + filepath: Optional file path for the document (e.g., '/documents/reports/file.pdf'). Used + by supermemoryfs to map documents to filesystem paths. + metadata: Optional metadata for the document. This is used to store additional information about the document. You can use this to store any additional information you need about the document. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -344,7 +378,9 @@ def batch_add( "container_tag": container_tag, "container_tags": container_tags, "content": content, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_batch_add_params.DocumentBatchAddParams, ), @@ -358,6 +394,7 @@ def delete_bulk( self, *, container_tags: SequenceNotStr[str] | Omit = omit, + filepath: str | Omit = omit, ids: SequenceNotStr[str] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -372,6 +409,9 @@ def delete_bulk( Args: container_tags: Array of container tags - all documents in these containers will be deleted + filepath: Delete documents matching this filepath. Exact match for full paths, prefix + match if ending with / + ids: Array of document IDs to delete (max 100 at once) extra_headers: Send extra headers @@ -387,6 +427,7 @@ def delete_bulk( body=maybe_transform( { "container_tags": container_tags, + "filepath": filepath, "ids": ids, }, document_delete_bulk_params.DocumentDeleteBulkParams, @@ -455,9 +496,11 @@ def upload_file( file: FileTypes, container_tag: str | Omit = omit, container_tags: str | Omit = omit, + filepath: str | Omit = omit, file_type: str | Omit = omit, metadata: str | Omit = omit, mime_type: str | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, use_advanced_processing: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -478,6 +521,9 @@ def upload_file( '["user_123", "project_123"]') or a single string (e.g., 'user_123'). Single strings will be automatically converted to an array. + filepath: Optional file path for the uploaded file (e.g., '/documents/reports/file.pdf'). + Used by supermemoryfs to map documents to filesystem paths. + file_type: Optional file type override to force specific processing behavior. Valid values: text, pdf, tweet, google_doc, google_slide, google_sheet, image, video, @@ -490,6 +536,9 @@ def upload_file( mime_type: Required when fileType is 'image' or 'video'. Specifies the exact MIME type to use (e.g., 'image/png', 'image/jpeg', 'video/mp4', 'video/webm') + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + use_advanced_processing: DEPRECATED: This field is no longer used. Advanced PDF processing is now automatic with our hybrid Mistral OCR + Gemini pipeline. This parameter will be accepted but ignored for backwards compatibility. @@ -502,16 +551,19 @@ def upload_file( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( + body = deepcopy_with_paths( { "file": file, "container_tag": container_tag, "container_tags": container_tags, + "filepath": filepath, "file_type": file_type, "metadata": metadata, "mime_type": mime_type, + "task_type": task_type, "use_advanced_processing": use_advanced_processing, - } + }, + [["file"]], ) files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) # It should be noted that the actual Content-Type header that will be @@ -557,7 +609,9 @@ async def update( container_tags: SequenceNotStr[str] | Omit = omit, content: str | Omit = omit, custom_id: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -589,12 +643,18 @@ async def update( custom_id: Optional custom ID of the document. This could be an ID from your database that will uniquely identify this document. + filepath: Optional file path for the document (e.g., '/documents/reports/file.pdf'). Used + by supermemoryfs to map documents to filesystem paths. + metadata: Optional metadata for the document. This is used to store additional information about the document. You can use this to store any additional information you need about the document. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -613,7 +673,9 @@ async def update( "container_tags": container_tags, "content": content, "custom_id": custom_id, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_update_params.DocumentUpdateParams, ), @@ -627,6 +689,7 @@ async def list( self, *, container_tags: SequenceNotStr[str] | Omit = omit, + filepath: str | Omit = omit, filters: document_list_params.Filters | Omit = omit, include_content: bool | Omit = omit, limit: Union[str, float] | Omit = omit, @@ -648,6 +711,9 @@ async def list( your user, a project ID, or any other identifier you wish to use to group documents. + filepath: Filter documents by filepath. Exact match for full paths, prefix match if ending + with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_content: Whether to include the content field in the response. Warning: This can make @@ -674,6 +740,7 @@ async def list( body=await async_maybe_transform( { "container_tags": container_tags, + "filepath": filepath, "filters": filters, "include_content": include_content, "limit": limit, @@ -731,7 +798,9 @@ async def add( container_tags: SequenceNotStr[str] | Omit = omit, custom_id: str | Omit = omit, entity_context: str | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -755,8 +824,14 @@ async def add( entity_context: Optional entity context for this container tag. Max 1500 characters. Used during document processing to guide memory extraction. + filepath: Optional file path for the document. Used by supermemoryfs to store the full + path of the file. + metadata: Optional metadata for the document. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -774,7 +849,9 @@ async def add( "container_tags": container_tags, "custom_id": custom_id, "entity_context": entity_context, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_add_params.DocumentAddParams, ), @@ -791,7 +868,9 @@ async def batch_add( container_tag: str | Omit = omit, container_tags: SequenceNotStr[str] | Omit = omit, content: None | Omit = omit, + filepath: str | Omit = omit, metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, @@ -813,12 +892,18 @@ async def batch_add( containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to group documents. + filepath: Optional file path for the document (e.g., '/documents/reports/file.pdf'). Used + by supermemoryfs to map documents to filesystem paths. + metadata: Optional metadata for the document. This is used to store additional information about the document. You can use this to store any additional information you need about the document. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -835,7 +920,9 @@ async def batch_add( "container_tag": container_tag, "container_tags": container_tags, "content": content, + "filepath": filepath, "metadata": metadata, + "task_type": task_type, }, document_batch_add_params.DocumentBatchAddParams, ), @@ -849,6 +936,7 @@ async def delete_bulk( self, *, container_tags: SequenceNotStr[str] | Omit = omit, + filepath: str | Omit = omit, ids: SequenceNotStr[str] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -863,6 +951,9 @@ async def delete_bulk( Args: container_tags: Array of container tags - all documents in these containers will be deleted + filepath: Delete documents matching this filepath. Exact match for full paths, prefix + match if ending with / + ids: Array of document IDs to delete (max 100 at once) extra_headers: Send extra headers @@ -878,6 +969,7 @@ async def delete_bulk( body=await async_maybe_transform( { "container_tags": container_tags, + "filepath": filepath, "ids": ids, }, document_delete_bulk_params.DocumentDeleteBulkParams, @@ -946,9 +1038,11 @@ async def upload_file( file: FileTypes, container_tag: str | Omit = omit, container_tags: str | Omit = omit, + filepath: str | Omit = omit, file_type: str | Omit = omit, metadata: str | Omit = omit, mime_type: str | Omit = omit, + task_type: Literal["memory", "superrag"] | Omit = omit, use_advanced_processing: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -969,6 +1063,9 @@ async def upload_file( '["user_123", "project_123"]') or a single string (e.g., 'user_123'). Single strings will be automatically converted to an array. + filepath: Optional file path for the uploaded file (e.g., '/documents/reports/file.pdf'). + Used by supermemoryfs to map documents to filesystem paths. + file_type: Optional file type override to force specific processing behavior. Valid values: text, pdf, tweet, google_doc, google_slide, google_sheet, image, video, @@ -981,6 +1078,9 @@ async def upload_file( mime_type: Required when fileType is 'image' or 'video'. Specifies the exact MIME type to use (e.g., 'image/png', 'image/jpeg', 'video/mp4', 'video/webm') + task_type: Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + use_advanced_processing: DEPRECATED: This field is no longer used. Advanced PDF processing is now automatic with our hybrid Mistral OCR + Gemini pipeline. This parameter will be accepted but ignored for backwards compatibility. @@ -993,16 +1093,19 @@ async def upload_file( timeout: Override the client-level default timeout for this request, in seconds """ - body = deepcopy_minimal( + body = deepcopy_with_paths( { "file": file, "container_tag": container_tag, "container_tags": container_tags, + "filepath": filepath, "file_type": file_type, "metadata": metadata, "mime_type": mime_type, + "task_type": task_type, "use_advanced_processing": use_advanced_processing, - } + }, + [["file"]], ) files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) # It should be noted that the actual Content-Type header that will be diff --git a/src/supermemory/resources/search.py b/src/supermemory/resources/search.py index 821725e..c02d83c 100644 --- a/src/supermemory/resources/search.py +++ b/src/supermemory/resources/search.py @@ -55,6 +55,7 @@ def documents( container_tags: SequenceNotStr[str] | Omit = omit, doc_id: str | Omit = omit, document_threshold: float | Omit = omit, + filepath: str | Omit = omit, filters: search_documents_params.Filters | Omit = omit, include_full_docs: bool | Omit = omit, include_summary: bool | Omit = omit, @@ -92,6 +93,9 @@ def documents( document_threshold: DEPRECATED: This field is no longer used in v3 search. The search now uses chunkThreshold only. This parameter will be ignored. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_full_docs: If true, include full document in the response. This is helpful if you want a @@ -131,6 +135,7 @@ def documents( "container_tags": container_tags, "doc_id": doc_id, "document_threshold": document_threshold, + "filepath": filepath, "filters": filters, "include_full_docs": include_full_docs, "include_summary": include_summary, @@ -157,6 +162,7 @@ def execute( container_tags: SequenceNotStr[str] | Omit = omit, doc_id: str | Omit = omit, document_threshold: float | Omit = omit, + filepath: str | Omit = omit, filters: search_execute_params.Filters | Omit = omit, include_full_docs: bool | Omit = omit, include_summary: bool | Omit = omit, @@ -194,6 +200,9 @@ def execute( document_threshold: DEPRECATED: This field is no longer used in v3 search. The search now uses chunkThreshold only. This parameter will be ignored. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_full_docs: If true, include full document in the response. This is helpful if you want a @@ -233,6 +242,7 @@ def execute( "container_tags": container_tags, "doc_id": doc_id, "document_threshold": document_threshold, + "filepath": filepath, "filters": filters, "include_full_docs": include_full_docs, "include_summary": include_summary, @@ -255,6 +265,7 @@ def memories( q: str, aggregate: bool | Omit = omit, container_tag: str | Omit = omit, + filepath: str | Omit = omit, filters: search_memories_params.Filters | Omit = omit, include: search_memories_params.Include | Omit = omit, limit: int | Omit = omit, @@ -282,6 +293,9 @@ def memories( container_tag: Optional tag this search should be containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to filter memories. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. limit: Maximum number of results to return @@ -315,6 +329,7 @@ def memories( "q": q, "aggregate": aggregate, "container_tag": container_tag, + "filepath": filepath, "filters": filters, "include": include, "limit": limit, @@ -362,6 +377,7 @@ async def documents( container_tags: SequenceNotStr[str] | Omit = omit, doc_id: str | Omit = omit, document_threshold: float | Omit = omit, + filepath: str | Omit = omit, filters: search_documents_params.Filters | Omit = omit, include_full_docs: bool | Omit = omit, include_summary: bool | Omit = omit, @@ -399,6 +415,9 @@ async def documents( document_threshold: DEPRECATED: This field is no longer used in v3 search. The search now uses chunkThreshold only. This parameter will be ignored. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_full_docs: If true, include full document in the response. This is helpful if you want a @@ -438,6 +457,7 @@ async def documents( "container_tags": container_tags, "doc_id": doc_id, "document_threshold": document_threshold, + "filepath": filepath, "filters": filters, "include_full_docs": include_full_docs, "include_summary": include_summary, @@ -464,6 +484,7 @@ async def execute( container_tags: SequenceNotStr[str] | Omit = omit, doc_id: str | Omit = omit, document_threshold: float | Omit = omit, + filepath: str | Omit = omit, filters: search_execute_params.Filters | Omit = omit, include_full_docs: bool | Omit = omit, include_summary: bool | Omit = omit, @@ -501,6 +522,9 @@ async def execute( document_threshold: DEPRECATED: This field is no longer used in v3 search. The search now uses chunkThreshold only. This parameter will be ignored. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. include_full_docs: If true, include full document in the response. This is helpful if you want a @@ -540,6 +564,7 @@ async def execute( "container_tags": container_tags, "doc_id": doc_id, "document_threshold": document_threshold, + "filepath": filepath, "filters": filters, "include_full_docs": include_full_docs, "include_summary": include_summary, @@ -562,6 +587,7 @@ async def memories( q: str, aggregate: bool | Omit = omit, container_tag: str | Omit = omit, + filepath: str | Omit = omit, filters: search_memories_params.Filters | Omit = omit, include: search_memories_params.Include | Omit = omit, limit: int | Omit = omit, @@ -589,6 +615,9 @@ async def memories( container_tag: Optional tag this search should be containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to filter memories. + filepath: Filter search results by filepath. Exact match for full paths, prefix match if + ending with / + filters: Optional filters to apply to the search. Can be a JSON string or Query object. limit: Maximum number of results to return @@ -622,6 +651,7 @@ async def memories( "q": q, "aggregate": aggregate, "container_tag": container_tag, + "filepath": filepath, "filters": filters, "include": include, "limit": limit, diff --git a/src/supermemory/types/client_add_params.py b/src/supermemory/types/client_add_params.py index 77b21d6..2b7aaed 100644 --- a/src/supermemory/types/client_add_params.py +++ b/src/supermemory/types/client_add_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Dict, Union -from typing_extensions import Required, Annotated, TypedDict +from typing_extensions import Literal, Required, Annotated, TypedDict from .._types import SequenceNotStr from .._utils import PropertyInfo @@ -38,5 +38,17 @@ class ClientAddParams(TypedDict, total=False): Max 1500 characters. Used during document processing to guide memory extraction. """ + filepath: str + """Optional file path for the document. + + Used by supermemoryfs to store the full path of the file. + """ + metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] """Optional metadata for the document.""" + + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ diff --git a/src/supermemory/types/connection_resources_params.py b/src/supermemory/types/connection_resources_params.py index 97ba168..ff39796 100644 --- a/src/supermemory/types/connection_resources_params.py +++ b/src/supermemory/types/connection_resources_params.py @@ -10,4 +10,6 @@ class ConnectionResourcesParams(TypedDict, total=False): page: float + parent_id: str + per_page: float diff --git a/src/supermemory/types/document_add_params.py b/src/supermemory/types/document_add_params.py index 71d9fbd..07ea075 100644 --- a/src/supermemory/types/document_add_params.py +++ b/src/supermemory/types/document_add_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Dict, Union -from typing_extensions import Required, Annotated, TypedDict +from typing_extensions import Literal, Required, Annotated, TypedDict from .._types import SequenceNotStr from .._utils import PropertyInfo @@ -38,5 +38,17 @@ class DocumentAddParams(TypedDict, total=False): Max 1500 characters. Used during document processing to guide memory extraction. """ + filepath: str + """Optional file path for the document. + + Used by supermemoryfs to store the full path of the file. + """ + metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] """Optional metadata for the document.""" + + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ diff --git a/src/supermemory/types/document_batch_add_params.py b/src/supermemory/types/document_batch_add_params.py index 4a35fe8..8c5daf9 100644 --- a/src/supermemory/types/document_batch_add_params.py +++ b/src/supermemory/types/document_batch_add_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Dict, Union, Iterable -from typing_extensions import Required, Annotated, TypedDict +from typing_extensions import Literal, Required, Annotated, TypedDict from .._types import SequenceNotStr from .._utils import PropertyInfo @@ -30,6 +30,12 @@ class DocumentBatchAddParams(TypedDict, total=False): content: None + filepath: str + """Optional file path for the document (e.g., '/documents/reports/file.pdf'). + + Used by supermemoryfs to map documents to filesystem paths. + """ + metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] """Optional metadata for the document. @@ -39,6 +45,12 @@ class DocumentBatchAddParams(TypedDict, total=False): be strings, numbers, or booleans. You cannot nest objects. """ + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ + class DocumentsUnionMember0(TypedDict, total=False): content: Required[str] @@ -74,6 +86,12 @@ class DocumentsUnionMember0(TypedDict, total=False): document. """ + filepath: str + """Optional file path for the document (e.g., '/documents/reports/file.pdf'). + + Used by supermemoryfs to map documents to filesystem paths. + """ + metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] """Optional metadata for the document. @@ -82,3 +100,9 @@ class DocumentsUnionMember0(TypedDict, total=False): can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. """ + + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ diff --git a/src/supermemory/types/document_delete_bulk_params.py b/src/supermemory/types/document_delete_bulk_params.py index 047f7d6..3dd221a 100644 --- a/src/supermemory/types/document_delete_bulk_params.py +++ b/src/supermemory/types/document_delete_bulk_params.py @@ -14,5 +14,11 @@ class DocumentDeleteBulkParams(TypedDict, total=False): container_tags: Annotated[SequenceNotStr[str], PropertyInfo(alias="containerTags")] """Array of container tags - all documents in these containers will be deleted""" + filepath: str + """Delete documents matching this filepath. + + Exact match for full paths, prefix match if ending with / + """ + ids: SequenceNotStr[str] """Array of document IDs to delete (max 100 at once)""" diff --git a/src/supermemory/types/document_get_response.py b/src/supermemory/types/document_get_response.py index 5bba549..411f179 100644 --- a/src/supermemory/types/document_get_response.py +++ b/src/supermemory/types/document_get_response.py @@ -44,6 +44,8 @@ class DocumentGetResponse(BaseModel): document. """ + filepath: Optional[str] = None + metadata: Union[str, float, bool, Dict[str, object], List[object], None] = None """Optional metadata for the document. @@ -69,6 +71,12 @@ class DocumentGetResponse(BaseModel): summary: Optional[str] = None """Summary of the document content""" + task_type: Literal["memory", "superrag"] = FieldInfo(alias="taskType") + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ + title: Optional[str] = None """Title of the document""" diff --git a/src/supermemory/types/document_list_params.py b/src/supermemory/types/document_list_params.py index d37a0e3..11bd957 100644 --- a/src/supermemory/types/document_list_params.py +++ b/src/supermemory/types/document_list_params.py @@ -336,6 +336,12 @@ class DocumentListParams(TypedDict, total=False): to use to group documents. """ + filepath: str + """Filter documents by filepath. + + Exact match for full paths, prefix match if ending with / + """ + filters: Filters """Optional filters to apply to the search. Can be a JSON string or Query object.""" diff --git a/src/supermemory/types/document_list_response.py b/src/supermemory/types/document_list_response.py index c5cb1b1..d667965 100644 --- a/src/supermemory/types/document_list_response.py +++ b/src/supermemory/types/document_list_response.py @@ -30,6 +30,8 @@ class Memory(BaseModel): document. """ + filepath: Optional[str] = None + metadata: Union[str, float, bool, Dict[str, object], List[object], None] = None """Optional metadata for the document. diff --git a/src/supermemory/types/document_update_params.py b/src/supermemory/types/document_update_params.py index 1727666..3164b5b 100644 --- a/src/supermemory/types/document_update_params.py +++ b/src/supermemory/types/document_update_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Dict, Union -from typing_extensions import Annotated, TypedDict +from typing_extensions import Literal, Annotated, TypedDict from .._types import SequenceNotStr from .._utils import PropertyInfo @@ -45,6 +45,12 @@ class DocumentUpdateParams(TypedDict, total=False): document. """ + filepath: str + """Optional file path for the document (e.g., '/documents/reports/file.pdf'). + + Used by supermemoryfs to map documents to filesystem paths. + """ + metadata: Dict[str, Union[str, float, bool, SequenceNotStr[str]]] """Optional metadata for the document. @@ -53,3 +59,9 @@ class DocumentUpdateParams(TypedDict, total=False): can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects. """ + + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ diff --git a/src/supermemory/types/document_upload_file_params.py b/src/supermemory/types/document_upload_file_params.py index f7c9526..507fc87 100644 --- a/src/supermemory/types/document_upload_file_params.py +++ b/src/supermemory/types/document_upload_file_params.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing_extensions import Required, Annotated, TypedDict +from typing_extensions import Literal, Required, Annotated, TypedDict from .._types import FileTypes from .._utils import PropertyInfo @@ -25,6 +25,12 @@ class DocumentUploadFileParams(TypedDict, total=False): converted to an array. """ + filepath: str + """Optional file path for the uploaded file (e.g., '/documents/reports/file.pdf'). + + Used by supermemoryfs to map documents to filesystem paths. + """ + file_type: Annotated[str, PropertyInfo(alias="fileType")] """Optional file type override to force specific processing behavior. @@ -46,6 +52,12 @@ class DocumentUploadFileParams(TypedDict, total=False): 'video/mp4', 'video/webm') """ + task_type: Annotated[Literal["memory", "superrag"], PropertyInfo(alias="taskType")] + """ + Task type: "memory" (default) for full context layer with SuperRAG built in, + "superrag" for managed RAG as a service. + """ + use_advanced_processing: Annotated[str, PropertyInfo(alias="useAdvancedProcessing")] """DEPRECATED: This field is no longer used. diff --git a/src/supermemory/types/search_documents_params.py b/src/supermemory/types/search_documents_params.py index 8f77d22..2f68805 100644 --- a/src/supermemory/types/search_documents_params.py +++ b/src/supermemory/types/search_documents_params.py @@ -364,6 +364,12 @@ class SearchDocumentsParams(TypedDict, total=False): The search now uses chunkThreshold only. This parameter will be ignored. """ + filepath: str + """Filter search results by filepath. + + Exact match for full paths, prefix match if ending with / + """ + filters: Filters """Optional filters to apply to the search. Can be a JSON string or Query object.""" diff --git a/src/supermemory/types/search_execute_params.py b/src/supermemory/types/search_execute_params.py index 2102f87..9660a3f 100644 --- a/src/supermemory/types/search_execute_params.py +++ b/src/supermemory/types/search_execute_params.py @@ -364,6 +364,12 @@ class SearchExecuteParams(TypedDict, total=False): The search now uses chunkThreshold only. This parameter will be ignored. """ + filepath: str + """Filter search results by filepath. + + Exact match for full paths, prefix match if ending with / + """ + filters: Filters """Optional filters to apply to the search. Can be a JSON string or Query object.""" diff --git a/src/supermemory/types/search_memories_params.py b/src/supermemory/types/search_memories_params.py index a6d3aed..12aa665 100644 --- a/src/supermemory/types/search_memories_params.py +++ b/src/supermemory/types/search_memories_params.py @@ -346,6 +346,12 @@ class SearchMemoriesParams(TypedDict, total=False): to use to filter memories. """ + filepath: str + """Filter search results by filepath. + + Exact match for full paths, prefix match if ending with / + """ + filters: Filters """Optional filters to apply to the search. Can be a JSON string or Query object.""" diff --git a/src/supermemory/types/search_memories_response.py b/src/supermemory/types/search_memories_response.py index 16d6ad4..3395f88 100644 --- a/src/supermemory/types/search_memories_response.py +++ b/src/supermemory/types/search_memories_response.py @@ -128,6 +128,9 @@ class Result(BaseModel): documents: Optional[List[ResultDocument]] = None """Associated documents for this memory entry""" + filepath: Optional[str] = None + """Filepath of the source document this memory or chunk came from""" + is_aggregated: Optional[bool] = FieldInfo(alias="isAggregated", default=None) """Indicates if this memory was created by aggregating multiple source memories""" diff --git a/tests/api_resources/test_client.py b/tests/api_resources/test_client.py index 9d5c3a6..ca8cfa4 100644 --- a/tests/api_resources/test_client.py +++ b/tests/api_resources/test_client.py @@ -34,7 +34,9 @@ def test_method_add_with_all_params(self, client: Supermemory) -> None: container_tags=["string"], custom_id="customId", entity_context="entityContext", + filepath="filepath", metadata={"foo": "string"}, + task_type="memory", ) assert_matches_type(AddResponse, client_, path=["response"]) @@ -143,7 +145,9 @@ async def test_method_add_with_all_params(self, async_client: AsyncSupermemory) container_tags=["string"], custom_id="customId", entity_context="entityContext", + filepath="filepath", metadata={"foo": "string"}, + task_type="memory", ) assert_matches_type(AddResponse, client, path=["response"]) diff --git a/tests/api_resources/test_connections.py b/tests/api_resources/test_connections.py index 8a1ba03..3eb33fc 100644 --- a/tests/api_resources/test_connections.py +++ b/tests/api_resources/test_connections.py @@ -423,6 +423,7 @@ def test_method_resources_with_all_params(self, client: Supermemory) -> None: connection = client.connections.resources( connection_id="connectionId", page=0, + parent_id="parent_id", per_page=0, ) assert_matches_type(ConnectionResourcesResponse, connection, path=["response"]) @@ -863,6 +864,7 @@ async def test_method_resources_with_all_params(self, async_client: AsyncSuperme connection = await async_client.connections.resources( connection_id="connectionId", page=0, + parent_id="parent_id", per_page=0, ) assert_matches_type(ConnectionResourcesResponse, connection, path=["response"]) diff --git a/tests/api_resources/test_documents.py b/tests/api_resources/test_documents.py index 75b82b8..684058a 100644 --- a/tests/api_resources/test_documents.py +++ b/tests/api_resources/test_documents.py @@ -43,6 +43,7 @@ def test_method_update_with_all_params(self, client: Supermemory) -> None: container_tags=["user_123", "project_123"], content="This is a detailed article about machine learning concepts...", custom_id="mem_abc123", + filepath="/documents/reports/file.pdf", metadata={ "category": "technology", "isPublic": True, @@ -51,6 +52,7 @@ def test_method_update_with_all_params(self, client: Supermemory) -> None: "tag_1": "ai", "tag_2": "machine-learning", }, + task_type="memory", ) assert_matches_type(DocumentUpdateResponse, document, path=["response"]) @@ -99,6 +101,7 @@ def test_method_list(self, client: Supermemory) -> None: def test_method_list_with_all_params(self, client: Supermemory) -> None: document = client.documents.list( container_tags=["user_123", "project_123"], + filepath="/docs/", filters={ "and_": [ { @@ -208,7 +211,9 @@ def test_method_add_with_all_params(self, client: Supermemory) -> None: container_tags=["string"], custom_id="customId", entity_context="entityContext", + filepath="filepath", metadata={"foo": "string"}, + task_type="memory", ) assert_matches_type(DocumentAddResponse, document, path=["response"]) @@ -256,6 +261,7 @@ def test_method_batch_add_with_all_params(self, client: Supermemory) -> None: "container_tag": "user_123", "container_tags": ["user_123", "project_123"], "custom_id": "mem_abc123", + "filepath": "/documents/reports/file.pdf", "metadata": { "category": "technology", "isPublic": True, @@ -264,11 +270,13 @@ def test_method_batch_add_with_all_params(self, client: Supermemory) -> None: "tag_1": "ai", "tag_2": "machine-learning", }, + "task_type": "memory", } ], container_tag="user_123", container_tags=["user_123", "project_123"], content=None, + filepath="/documents/reports/file.pdf", metadata={ "category": "technology", "isPublic": True, @@ -277,6 +285,7 @@ def test_method_batch_add_with_all_params(self, client: Supermemory) -> None: "tag_1": "ai", "tag_2": "machine-learning", }, + task_type="memory", ) assert_matches_type(DocumentBatchAddResponse, document, path=["response"]) @@ -317,6 +326,7 @@ def test_method_delete_bulk(self, client: Supermemory) -> None: def test_method_delete_bulk_with_all_params(self, client: Supermemory) -> None: document = client.documents.delete_bulk( container_tags=["user_123", "project_123"], + filepath="/docs/old/", ids=["acxV5LHMEsG2hMSNb4umbn", "bxcV5LHMEsG2hMSNb4umbn"], ) assert_matches_type(DocumentDeleteBulkResponse, document, path=["response"]) @@ -428,9 +438,11 @@ def test_method_upload_file_with_all_params(self, client: Supermemory) -> None: file=b"Example data", container_tag="user", container_tags='["user_123", "project_123"]', + filepath="/documents/reports/file.pdf", file_type="image", metadata='{"category": "technology", "isPublic": true, "readingTime": 5}', mime_type="mimeType", + task_type="memory", use_advanced_processing="true", ) assert_matches_type(DocumentUploadFileResponse, document, path=["response"]) @@ -484,6 +496,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncSupermemor container_tags=["user_123", "project_123"], content="This is a detailed article about machine learning concepts...", custom_id="mem_abc123", + filepath="/documents/reports/file.pdf", metadata={ "category": "technology", "isPublic": True, @@ -492,6 +505,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncSupermemor "tag_1": "ai", "tag_2": "machine-learning", }, + task_type="memory", ) assert_matches_type(DocumentUpdateResponse, document, path=["response"]) @@ -540,6 +554,7 @@ async def test_method_list(self, async_client: AsyncSupermemory) -> None: async def test_method_list_with_all_params(self, async_client: AsyncSupermemory) -> None: document = await async_client.documents.list( container_tags=["user_123", "project_123"], + filepath="/docs/", filters={ "and_": [ { @@ -649,7 +664,9 @@ async def test_method_add_with_all_params(self, async_client: AsyncSupermemory) container_tags=["string"], custom_id="customId", entity_context="entityContext", + filepath="filepath", metadata={"foo": "string"}, + task_type="memory", ) assert_matches_type(DocumentAddResponse, document, path=["response"]) @@ -697,6 +714,7 @@ async def test_method_batch_add_with_all_params(self, async_client: AsyncSuperme "container_tag": "user_123", "container_tags": ["user_123", "project_123"], "custom_id": "mem_abc123", + "filepath": "/documents/reports/file.pdf", "metadata": { "category": "technology", "isPublic": True, @@ -705,11 +723,13 @@ async def test_method_batch_add_with_all_params(self, async_client: AsyncSuperme "tag_1": "ai", "tag_2": "machine-learning", }, + "task_type": "memory", } ], container_tag="user_123", container_tags=["user_123", "project_123"], content=None, + filepath="/documents/reports/file.pdf", metadata={ "category": "technology", "isPublic": True, @@ -718,6 +738,7 @@ async def test_method_batch_add_with_all_params(self, async_client: AsyncSuperme "tag_1": "ai", "tag_2": "machine-learning", }, + task_type="memory", ) assert_matches_type(DocumentBatchAddResponse, document, path=["response"]) @@ -758,6 +779,7 @@ async def test_method_delete_bulk(self, async_client: AsyncSupermemory) -> None: async def test_method_delete_bulk_with_all_params(self, async_client: AsyncSupermemory) -> None: document = await async_client.documents.delete_bulk( container_tags=["user_123", "project_123"], + filepath="/docs/old/", ids=["acxV5LHMEsG2hMSNb4umbn", "bxcV5LHMEsG2hMSNb4umbn"], ) assert_matches_type(DocumentDeleteBulkResponse, document, path=["response"]) @@ -869,9 +891,11 @@ async def test_method_upload_file_with_all_params(self, async_client: AsyncSuper file=b"Example data", container_tag="user", container_tags='["user_123", "project_123"]', + filepath="/documents/reports/file.pdf", file_type="image", metadata='{"category": "technology", "isPublic": true, "readingTime": 5}', mime_type="mimeType", + task_type="memory", use_advanced_processing="true", ) assert_matches_type(DocumentUploadFileResponse, document, path=["response"]) diff --git a/tests/api_resources/test_search.py b/tests/api_resources/test_search.py index 265f091..eaabbaf 100644 --- a/tests/api_resources/test_search.py +++ b/tests/api_resources/test_search.py @@ -40,6 +40,7 @@ def test_method_documents_with_all_params(self, client: Supermemory) -> None: container_tags=["user_123"], doc_id="docId", document_threshold=0, + filepath="/docs/", filters={ "or_": [ { @@ -106,6 +107,7 @@ def test_method_execute_with_all_params(self, client: Supermemory) -> None: container_tags=["user_123"], doc_id="docId", document_threshold=0, + filepath="/docs/", filters={ "or_": [ { @@ -168,6 +170,7 @@ def test_method_memories_with_all_params(self, client: Supermemory) -> None: q="machine learning concepts", aggregate=False, container_tag="user_123", + filepath="/docs/", filters={ "or_": [ { @@ -246,6 +249,7 @@ async def test_method_documents_with_all_params(self, async_client: AsyncSuperme container_tags=["user_123"], doc_id="docId", document_threshold=0, + filepath="/docs/", filters={ "or_": [ { @@ -312,6 +316,7 @@ async def test_method_execute_with_all_params(self, async_client: AsyncSupermemo container_tags=["user_123"], doc_id="docId", document_threshold=0, + filepath="/docs/", filters={ "or_": [ { @@ -374,6 +379,7 @@ async def test_method_memories_with_all_params(self, async_client: AsyncSupermem q="machine learning concepts", aggregate=False, container_tag="user_123", + filepath="/docs/", filters={ "or_": [ { diff --git a/tests/test_deepcopy.py b/tests/test_deepcopy.py deleted file mode 100644 index c464e63..0000000 --- a/tests/test_deepcopy.py +++ /dev/null @@ -1,58 +0,0 @@ -from supermemory._utils import deepcopy_minimal - - -def assert_different_identities(obj1: object, obj2: object) -> None: - assert obj1 == obj2 - assert id(obj1) != id(obj2) - - -def test_simple_dict() -> None: - obj1 = {"foo": "bar"} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_dict() -> None: - obj1 = {"foo": {"bar": True}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - - -def test_complex_nested_dict() -> None: - obj1 = {"foo": {"bar": [{"hello": "world"}]}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - assert_different_identities(obj1["foo"]["bar"], obj2["foo"]["bar"]) - assert_different_identities(obj1["foo"]["bar"][0], obj2["foo"]["bar"][0]) - - -def test_simple_list() -> None: - obj1 = ["a", "b", "c"] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_list() -> None: - obj1 = ["a", [1, 2, 3]] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1[1], obj2[1]) - - -class MyObject: ... - - -def test_ignores_other_types() -> None: - # custom classes - my_obj = MyObject() - obj1 = {"foo": my_obj} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert obj1["foo"] is my_obj - - # tuples - obj3 = ("a", "b") - obj4 = deepcopy_minimal(obj3) - assert obj3 is obj4 diff --git a/tests/test_files.py b/tests/test_files.py index fe8388c..2c10e6b 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -4,7 +4,8 @@ import pytest from dirty_equals import IsDict, IsList, IsBytes, IsTuple -from supermemory._files import to_httpx_files, async_to_httpx_files +from supermemory._files import to_httpx_files, deepcopy_with_paths, async_to_httpx_files +from supermemory._utils import extract_files readme_path = Path(__file__).parent.parent.joinpath("README.md") @@ -49,3 +50,99 @@ def test_string_not_allowed() -> None: "file": "foo", # type: ignore } ) + + +def assert_different_identities(obj1: object, obj2: object) -> None: + assert obj1 == obj2 + assert obj1 is not obj2 + + +class TestDeepcopyWithPaths: + def test_copies_top_level_dict(self) -> None: + original = {"file": b"data", "other": "value"} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + + def test_file_value_is_same_reference(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + assert result["file"] is file_bytes + + def test_list_popped_wholesale(self) -> None: + files = [b"f1", b"f2"] + original = {"files": files, "title": "t"} + result = deepcopy_with_paths(original, [["files", ""]]) + assert_different_identities(result, original) + result_files = result["files"] + assert isinstance(result_files, list) + assert_different_identities(result_files, files) + + def test_nested_array_path_copies_list_and_elements(self) -> None: + elem1 = {"file": b"f1", "extra": 1} + elem2 = {"file": b"f2", "extra": 2} + original = {"items": [elem1, elem2]} + result = deepcopy_with_paths(original, [["items", "", "file"]]) + assert_different_identities(result, original) + result_items = result["items"] + assert isinstance(result_items, list) + assert_different_identities(result_items, original["items"]) + assert_different_identities(result_items[0], elem1) + assert_different_identities(result_items[1], elem2) + + def test_empty_paths_returns_same_object(self) -> None: + original = {"foo": "bar"} + result = deepcopy_with_paths(original, []) + assert result is original + + def test_multiple_paths(self) -> None: + f1 = b"file1" + f2 = b"file2" + original = {"a": f1, "b": f2, "c": "unchanged"} + result = deepcopy_with_paths(original, [["a"], ["b"]]) + assert_different_identities(result, original) + assert result["a"] is f1 + assert result["b"] is f2 + assert result["c"] is original["c"] + + def test_extract_files_does_not_mutate_original_top_level(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes, "other": "value"} + + copied = deepcopy_with_paths(original, [["file"]]) + extracted = extract_files(copied, paths=[["file"]]) + + assert extracted == [("file", file_bytes)] + assert original == {"file": file_bytes, "other": "value"} + assert copied == {"other": "value"} + + def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: + file1 = b"f1" + file2 = b"f2" + original = { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + + copied = deepcopy_with_paths(original, [["items", "", "file"]]) + extracted = extract_files(copied, paths=[["items", "", "file"]]) + + assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert original == { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + assert copied == { + "items": [ + {"extra": 1}, + {"extra": 2}, + ], + "title": "example", + }