memmachine-common 0.3.7__tar.gz → 0.3.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memmachine-common
3
- Version: 0.3.7
3
+ Version: 0.3.9
4
4
  Summary: MemMachine Common - Shared API models for MemMachine client and server
5
5
  Author-email: MemMachine <noreply@memmachine.ai>
6
6
  License-Expression: Apache-2.0
@@ -15,6 +15,38 @@ Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
16
  Classifier: Operating System :: OS Independent
17
17
  Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
18
19
  Requires-Dist: pydantic>=2.0.0
19
20
  Requires-Dist: regex>=2023.0.0
20
21
  Requires-Dist: typing-extensions>=4.0.0
22
+
23
+ # MemMachine Common
24
+
25
+ Shared Python models and API types for MemMachine packages.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install memmachine-common
31
+ ```
32
+
33
+ ## What this package provides
34
+
35
+ `memmachine-common` contains the shared Pydantic models and type definitions used by MemMachine Python packages.
36
+
37
+ Typical users do not need to install it directly unless they are building against MemMachine package internals. It is primarily consumed by:
38
+ - `memmachine-client`
39
+ - `memmachine-server`
40
+
41
+ ## Development
42
+
43
+ For local development inside the MemMachine monorepo:
44
+
45
+ ```bash
46
+ pip install -e packages/common
47
+ ```
48
+
49
+ ## Source
50
+
51
+ - Repository: <https://github.com/MemMachine/MemMachine>
52
+ - Issues: <https://github.com/MemMachine/MemMachine/issues>
@@ -0,0 +1,30 @@
1
+ # MemMachine Common
2
+
3
+ Shared Python models and API types for MemMachine packages.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install memmachine-common
9
+ ```
10
+
11
+ ## What this package provides
12
+
13
+ `memmachine-common` contains the shared Pydantic models and type definitions used by MemMachine Python packages.
14
+
15
+ Typical users do not need to install it directly unless they are building against MemMachine package internals. It is primarily consumed by:
16
+ - `memmachine-client`
17
+ - `memmachine-server`
18
+
19
+ ## Development
20
+
21
+ For local development inside the MemMachine monorepo:
22
+
23
+ ```bash
24
+ pip install -e packages/common
25
+ ```
26
+
27
+ ## Source
28
+
29
+ - Repository: <https://github.com/MemMachine/MemMachine>
30
+ - Issues: <https://github.com/MemMachine/MemMachine/issues>
@@ -15,6 +15,7 @@ authors = [
15
15
  {name="MemMachine", email="noreply@memmachine.ai"},
16
16
  ]
17
17
  description = "MemMachine Common - Shared API models for MemMachine client and server"
18
+ readme = "README.md"
18
19
  keywords = ["memmachine", "common", "api", "models"]
19
20
  classifiers = [
20
21
  "Programming Language :: Python :: 3",
@@ -3,9 +3,10 @@
3
3
  from enum import Enum
4
4
  from typing import Annotated, Any, Literal
5
5
 
6
- from pydantic import BaseModel, Field
6
+ from pydantic import BaseModel, Field, field_validator
7
7
 
8
8
  from memmachine_common.api.doc import SpecDoc
9
+ from memmachine_common.api.spec import validate_properties_schema_types
9
10
 
10
11
 
11
12
  class ResourceStatus(str, Enum):
@@ -61,6 +62,16 @@ class ResourcesStatus(BaseModel):
61
62
  class LongTermMemoryConfigResponse(BaseModel):
62
63
  """Response model for long-term memory configuration."""
63
64
 
65
+ backend: Annotated[
66
+ Literal["declarative", "event"] | None,
67
+ Field(
68
+ default=None,
69
+ description=(
70
+ "Long-term memory backend. None means the writer predates the "
71
+ "discriminator and is treated as 'declarative'."
72
+ ),
73
+ ),
74
+ ]
64
75
  embedder: Annotated[
65
76
  str | None,
66
77
  Field(default=None, description=SpecDoc.LTM_CONFIG_EMBEDDER),
@@ -69,15 +80,52 @@ class LongTermMemoryConfigResponse(BaseModel):
69
80
  str | None,
70
81
  Field(default=None, description=SpecDoc.LTM_CONFIG_RERANKER),
71
82
  ]
83
+ # Declarative-backend only.
72
84
  vector_graph_store: Annotated[
73
85
  str | None,
74
86
  Field(default=None, description=SpecDoc.LTM_CONFIG_VECTOR_GRAPH_STORE),
75
87
  ]
88
+ # Event-backend only.
89
+ vector_store: Annotated[
90
+ str | None,
91
+ Field(
92
+ default=None,
93
+ description="VectorStore resource id (event backend only)",
94
+ ),
95
+ ]
96
+ segment_store: Annotated[
97
+ str | None,
98
+ Field(
99
+ default=None,
100
+ description=(
101
+ "SQL engine resource id backing the segment store (event backend only)"
102
+ ),
103
+ ),
104
+ ]
105
+ properties_schema: Annotated[
106
+ dict[str, str] | None,
107
+ Field(
108
+ default=None,
109
+ description=(
110
+ "User-defined filterable properties (event backend only). Maps "
111
+ 'name to type ("bool", "int", "float", "str", "datetime").'
112
+ ),
113
+ ),
114
+ ]
76
115
  enabled: Annotated[
77
116
  bool,
78
117
  Field(default=True, description=SpecDoc.LTM_CONFIG_ENABLED),
79
118
  ]
80
119
 
120
+ @field_validator("properties_schema")
121
+ @classmethod
122
+ def _validate_properties_schema_types(
123
+ cls, value: dict[str, str] | None
124
+ ) -> dict[str, str] | None:
125
+ if value is None:
126
+ return value
127
+ return validate_properties_schema_types(value)
128
+
81
129
 
82
130
  class ShortTermMemoryConfigResponse(BaseModel):
83
131
  """Response model for short-term memory configuration."""
@@ -368,6 +416,16 @@ class AddLanguageModelSpec(BaseModel):
368
416
  class UpdateLongTermMemorySpec(BaseModel):
369
417
  """Partial update for long-term memory configuration."""
370
418
 
419
+ backend: Annotated[
420
+ Literal["declarative", "event"] | None,
421
+ Field(
422
+ default=None,
423
+ description=(
424
+ "Long-term memory backend. Omit/null to keep the existing "
425
+ "backend; set 'declarative' or 'event' to switch."
426
+ ),
427
+ ),
428
+ ]
371
429
  embedder: Annotated[
372
430
  str | None,
373
431
  Field(default=None, description=SpecDoc.LTM_EMBEDDER),
@@ -376,10 +434,44 @@ class UpdateLongTermMemorySpec(BaseModel):
376
434
  str | None,
377
435
  Field(default=None, description=SpecDoc.LTM_RERANKER),
378
436
  ]
437
+ # Declarative-backend only.
379
438
  vector_graph_store: Annotated[
380
439
  str | None,
381
440
  Field(default=None, description=SpecDoc.LTM_VECTOR_GRAPH_STORE),
382
441
  ]
442
+ # Event-backend only.
443
+ vector_store: Annotated[
444
+ str | None,
445
+ Field(
446
+ default=None,
447
+ description="VectorStore resource id (event backend only)",
448
+ ),
449
+ ]
450
+ segment_store: Annotated[
451
+ str | None,
452
+ Field(
453
+ default=None,
454
+ description=(
455
+ "SQL engine resource id backing the segment store (event backend only)"
456
+ ),
457
+ ),
458
+ ]
459
+ properties_schema: Annotated[
460
+ dict[str, str] | None,
461
+ Field(
462
+ default=None,
463
+ description="User-defined filterable properties (event backend only)",
464
+ ),
465
+ ]
466
+
467
+ @field_validator("properties_schema")
468
+ @classmethod
469
+ def _validate_properties_schema_types(
470
+ cls, value: dict[str, str] | None
471
+ ) -> dict[str, str] | None:
472
+ if value is None:
473
+ return value
474
+ return validate_properties_schema_types(value)
383
475
 
384
476
 
385
477
  class UpdateShortTermMemorySpec(BaseModel):
@@ -729,7 +729,10 @@ class RouterDoc:
729
729
  System returns the top K relevant memories matching the natural language query.
730
730
  The result is sorted by timestamp to help with context.
731
731
 
732
- The filter field allows for filtering based on metadata key-value pairs.
732
+ The filter field accepts the structured filter expression language.
733
+ User-defined metadata keys must be referenced with the `m.` or `metadata.` prefix
734
+ (for example, `m.source = "chat_v3"`). Unknown or unsupported fields are rejected
735
+ instead of being ignored.
733
736
  The set_metadata field scopes semantic memories to matching semantic sets.
734
737
  The types field allows specifying which memory types to include in the search.
735
738
  """
@@ -740,7 +743,10 @@ class RouterDoc:
740
743
  System returns a paginated list of memories stored in the project.
741
744
  The page_size and page_num fields control pagination.
742
745
 
743
- The filter field allows for filtering based on metadata key-value pairs.
746
+ The filter field accepts the structured filter expression language.
747
+ User-defined metadata keys must be referenced with the `m.` or `metadata.` prefix
748
+ (for example, `m.source = "chat_v3"`). Unknown or unsupported fields are rejected
749
+ instead of being ignored.
744
750
  The set_metadata field scopes semantic memories to matching semantic sets.
745
751
  The type field allows specifying which memory type to list.
746
752
  """
@@ -3,7 +3,7 @@
3
3
  import logging
4
4
  from datetime import datetime, timezone
5
5
  from enum import Enum
6
- from typing import Annotated, Any
6
+ from typing import Annotated, Any, Literal
7
7
 
8
8
  import regex
9
9
  from pydantic import (
@@ -26,6 +26,35 @@ UTC = timezone.utc
26
26
  PropertyValue = bool | int | float | str | datetime
27
27
  """Type for stored property values (duplicated here to avoid server dependency)."""
28
28
 
29
+ # Canonical type-name set accepted in `properties_schema`. Mirrors
30
+ # `memmachine_server.common.data_types.PROPERTY_TYPE_NAME_TO_PROPERTY_TYPE` but
31
+ # lives here so the API contract validates types at request time rather than
32
+ # deferring failures to service-locator wire-up.
33
+ VALID_PROPERTY_TYPE_NAMES: frozenset[str] = frozenset(
34
+ {"bool", "int", "float", "str", "datetime"}
35
+ )
36
+
37
+
38
+ def validate_properties_schema_types(value: dict[str, str]) -> dict[str, str]:
39
+ """Reject unknown type names in `properties_schema`.
40
+
41
+ Without this check, an unknown type name like `"date"` or `"integer"` is
42
+ only caught later when service-locator builds the VectorStore collection
43
+ schema — surfacing as a 500 instead of a 400 at API time.
44
+ """
45
+ bad = sorted(
46
+ f"{name}={type_name!r}"
47
+ for name, type_name in value.items()
48
+ if type_name not in VALID_PROPERTY_TYPE_NAMES
49
+ )
50
+ if bad:
51
+ raise ValueError(
52
+ "properties_schema contains unknown type names "
53
+ f"(allowed: {sorted(VALID_PROPERTY_TYPE_NAMES)}): {bad}"
54
+ )
55
+ return value
56
+
57
+
29
58
  DEFAULT_ORG_AND_PROJECT_ID = "universal"
30
59
 
31
60
  logger = logging.getLogger(__name__)
@@ -182,11 +211,27 @@ class ProjectConfig(BaseModel):
182
211
  """
183
212
  Project configuration model.
184
213
 
185
- This section defines which reranker and embedder models should be used for
186
- the project. If any field is left empty (""), the system automatically falls
187
- back to the globally configured defaults in the server configuration file.
214
+ Identifies the long-term-memory backend and the resource ids it should
215
+ bind to. If any string field is left empty (""), the server falls back to
216
+ its globally-configured defaults.
217
+
218
+ Backend selection:
219
+ - `backend="event"` (default for new projects): uses VectorStore +
220
+ SegmentStore. Requires `vector_store` and `segment_store`.
221
+ - `backend="declarative"`: uses VectorGraphStore. Requires
222
+ `vector_graph_store`.
223
+ - Empty/null `backend`: server falls back to its parse-time default
224
+ (declarative, for backwards compatibility with pre-discriminator clients).
188
225
  """
189
226
 
227
+ backend: Annotated[
228
+ Literal["declarative", "event"] | None,
229
+ Field(
230
+ default=None,
231
+ description=("Long-term memory backend. New projects should set 'event'."),
232
+ ),
233
+ ]
234
+
190
235
  reranker: Annotated[
191
236
  str,
192
237
  Field(
@@ -205,6 +250,48 @@ class ProjectConfig(BaseModel):
205
250
  ),
206
251
  ]
207
252
 
253
+ # Declarative-backend resource id.
254
+ vector_graph_store: Annotated[
255
+ str,
256
+ Field(
257
+ default="",
258
+ description="VectorGraphStore resource id (declarative backend only)",
259
+ ),
260
+ ]
261
+
262
+ # Event-backend resource ids.
263
+ vector_store: Annotated[
264
+ str,
265
+ Field(
266
+ default="",
267
+ description="VectorStore resource id (event backend only)",
268
+ ),
269
+ ]
270
+ segment_store: Annotated[
271
+ str,
272
+ Field(
273
+ default="",
274
+ description=(
275
+ "SQL engine resource id backing the segment store (event backend only)"
276
+ ),
277
+ ),
278
+ ]
279
+ properties_schema: Annotated[
280
+ dict[str, str],
281
+ Field(
282
+ default_factory=dict,
283
+ description=(
284
+ "User-defined filterable properties (event backend only). Maps "
285
+ 'name to type ("bool", "int", "float", "str", "datetime").'
286
+ ),
287
+ ),
288
+ ]
289
+
290
+ @field_validator("properties_schema")
291
+ @classmethod
292
+ def _validate_properties_schema_types(cls, value: dict[str, str]) -> dict[str, str]:
293
+ return validate_properties_schema_types(value)
294
+
208
295
 
209
296
  class CreateProjectSpec(BaseModel):
210
297
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memmachine-common
3
- Version: 0.3.7
3
+ Version: 0.3.9
4
4
  Summary: MemMachine Common - Shared API models for MemMachine client and server
5
5
  Author-email: MemMachine <noreply@memmachine.ai>
6
6
  License-Expression: Apache-2.0
@@ -15,6 +15,38 @@ Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
16
  Classifier: Operating System :: OS Independent
17
17
  Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
18
19
  Requires-Dist: pydantic>=2.0.0
19
20
  Requires-Dist: regex>=2023.0.0
20
21
  Requires-Dist: typing-extensions>=4.0.0
22
+
23
+ # MemMachine Common
24
+
25
+ Shared Python models and API types for MemMachine packages.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install memmachine-common
31
+ ```
32
+
33
+ ## What this package provides
34
+
35
+ `memmachine-common` contains the shared Pydantic models and type definitions used by MemMachine Python packages.
36
+
37
+ Typical users do not need to install it directly unless they are building against MemMachine package internals. It is primarily consumed by:
38
+ - `memmachine-client`
39
+ - `memmachine-server`
40
+
41
+ ## Development
42
+
43
+ For local development inside the MemMachine monorepo:
44
+
45
+ ```bash
46
+ pip install -e packages/common
47
+ ```
48
+
49
+ ## Source
50
+
51
+ - Repository: <https://github.com/MemMachine/MemMachine>
52
+ - Issues: <https://github.com/MemMachine/MemMachine/issues>
@@ -1,3 +1,4 @@
1
+ README.md
1
2
  pyproject.toml
2
3
  src/memmachine_common/__init__.py
3
4
  src/memmachine_common.egg-info/PKG-INFO