memmachine-client 0.2.0__py3-none-any.whl
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.
- memmachine/__init__.py +40 -0
- memmachine/common/api/__init__.py +1 -0
- memmachine/common/api/doc.py +366 -0
- memmachine/common/api/spec.py +580 -0
- memmachine/rest_client/README.md +228 -0
- memmachine/rest_client/__init__.py +12 -0
- memmachine/rest_client/client.py +485 -0
- memmachine/rest_client/memory.py +759 -0
- memmachine/rest_client/project.py +208 -0
- memmachine_client-0.2.0.dist-info/METADATA +133 -0
- memmachine_client-0.2.0.dist-info/RECORD +14 -0
- memmachine_client-0.2.0.dist-info/WHEEL +5 -0
- memmachine_client-0.2.0.dist-info/licenses/LICENSE +201 -0
- memmachine_client-0.2.0.dist-info/top_level.txt +1 -0
memmachine/__init__.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Public package exports and utilities for MemMachine."""
|
|
2
|
+
|
|
3
|
+
from memmachine.rest_client import MemMachineClient, Memory, Project
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from memmachine.main.memmachine import MemMachine
|
|
7
|
+
except ImportError:
|
|
8
|
+
# MemMachine is not available in client-only installations
|
|
9
|
+
MemMachine = None # type: ignore
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def setup_nltk() -> None:
|
|
13
|
+
"""Check for and download required NLTK data packages."""
|
|
14
|
+
import logging
|
|
15
|
+
|
|
16
|
+
import nltk
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
logger.info("Checking for required NLTK data...")
|
|
21
|
+
packages = [
|
|
22
|
+
("tokenizers/punkt", "punkt"),
|
|
23
|
+
("tokenizers/punkt_tab", "punkt_tab"),
|
|
24
|
+
("corpora/stopwords", "stopwords"),
|
|
25
|
+
]
|
|
26
|
+
for path, pkg_id in packages:
|
|
27
|
+
try:
|
|
28
|
+
nltk.data.find(path)
|
|
29
|
+
logger.info("NLTK package '%s' is already installed.", pkg_id)
|
|
30
|
+
except LookupError:
|
|
31
|
+
logger.warning("NLTK package '%s' not found. Downloading...", pkg_id)
|
|
32
|
+
nltk.download(pkg_id)
|
|
33
|
+
logger.info("NLTK data setup is complete.")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Only export MemMachine if it's available
|
|
37
|
+
if MemMachine is not None:
|
|
38
|
+
__all__ = ["MemMachine", "MemMachineClient", "Memory", "Project", "setup_nltk"]
|
|
39
|
+
else:
|
|
40
|
+
__all__ = ["MemMachineClient", "Memory", "Project", "setup_nltk"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Shared API definitions for MemMachine client and server."""
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"""API documentation strings for MemMachine server v2."""
|
|
2
|
+
|
|
3
|
+
from typing import ClassVar
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SpecDoc:
|
|
7
|
+
"""Common descriptions for API fields."""
|
|
8
|
+
|
|
9
|
+
ORG_ID = """
|
|
10
|
+
The unique identifier of the organization.
|
|
11
|
+
|
|
12
|
+
- Must not contain slashes (`/`).
|
|
13
|
+
- Must contain only letters, numbers, underscores, hyphens, colon, and Unicode
|
|
14
|
+
characters (e.g., Chinese/Japanese/Korean). No slashes or other symbols
|
|
15
|
+
are allowed.
|
|
16
|
+
|
|
17
|
+
This value determines the namespace the project belongs to.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
ORG_ID_RETURN = """
|
|
21
|
+
The unique identifier of the organization this project belongs to.
|
|
22
|
+
|
|
23
|
+
Returned exactly as stored by the system.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
PROJECT_ID = """
|
|
27
|
+
The identifier of the project.
|
|
28
|
+
|
|
29
|
+
- Must be unique within the organization.
|
|
30
|
+
- Must not contain slashes (`/`).
|
|
31
|
+
- Must contain only letters, numbers, underscores, hyphens, colon, and Unicode
|
|
32
|
+
characters (e.g., Chinese/Japanese/Korean). No slashes or other symbols
|
|
33
|
+
are allowed.
|
|
34
|
+
|
|
35
|
+
This ID is used in API paths and resource locations.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
PROJECT_ID_RETURN = """
|
|
39
|
+
The identifier of the project.
|
|
40
|
+
|
|
41
|
+
This value uniquely identifies the project within the organization.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
PROJECT_DESCRIPTION = """
|
|
45
|
+
A human-readable description of the project.
|
|
46
|
+
Used for display purposes in UIs and dashboards.
|
|
47
|
+
Optional; defaults to an empty string.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
PROJECT_CONFIG = """
|
|
51
|
+
Configuration settings associated with this project.
|
|
52
|
+
|
|
53
|
+
Defines which models (reranker, embedder) to use. If any values within
|
|
54
|
+
`ProjectConfig` are empty, global defaults are applied.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
RERANKER_ID = """
|
|
58
|
+
The name of the reranker model to use for this project.
|
|
59
|
+
|
|
60
|
+
- Must refer to a reranker model defined in the system configuration.
|
|
61
|
+
- If set to an empty string (default), the globally configured reranker will
|
|
62
|
+
be used.
|
|
63
|
+
|
|
64
|
+
Rerankers typically re-score retrieved documents to improve result quality.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
EMBEDDER_ID = """
|
|
68
|
+
The name of the embedder model to use for this project.
|
|
69
|
+
|
|
70
|
+
- Must refer to an embedder model defined in the system configuration.
|
|
71
|
+
- If set to an empty string (default), the globally configured embedder will
|
|
72
|
+
be used.
|
|
73
|
+
|
|
74
|
+
Embedders generate vector embeddings for text to support semantic search and
|
|
75
|
+
similarity operations.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
EPISODE_COUNT = "The total number of episodic memories in the project."
|
|
79
|
+
|
|
80
|
+
MEMORY_CONTENT = "The content or text of the message."
|
|
81
|
+
|
|
82
|
+
MEMORY_PRODUCER = """
|
|
83
|
+
The sender of the message. This is a user-friendly name for
|
|
84
|
+
the LLM to understand the message context. Defaults to 'user'.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
MEMORY_PRODUCE_FOR = """
|
|
88
|
+
The intended recipient of the message. This is a user-friendly name for
|
|
89
|
+
the LLM to understand the message context. Defaults to an empty string.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
MEMORY_TIMESTAMP = """
|
|
93
|
+
The timestamp when the message was created, in ISO 8601 format.
|
|
94
|
+
If not provided, the server assigns the current time.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
MEMORY_ROLE = """
|
|
98
|
+
The role of the message in a conversation (e.g., 'user', 'assistant',
|
|
99
|
+
'system'). Optional; defaults to an empty string.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
MEMORY_METADATA = """
|
|
103
|
+
Additional metadata associated with the message, represented as key-value
|
|
104
|
+
pairs. Optional; defaults to an empty object.
|
|
105
|
+
Retrieval operations may utilize this metadata for filtering.
|
|
106
|
+
Use 'metadata.{key}' to filter based on specific metadata keys.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
MEMORY_MESSAGES = """
|
|
110
|
+
A list of messages to be added (batch input).
|
|
111
|
+
Must contain at least one message.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
MEMORY_UID = "The unique identifier of the memory message."
|
|
115
|
+
|
|
116
|
+
ADD_MEMORY_RESULTS = "The list of results for each added memory message."
|
|
117
|
+
|
|
118
|
+
TOP_K = """
|
|
119
|
+
The maximum number of memories to return in the search results.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
QUERY = """
|
|
123
|
+
The natural language query used for semantic memory search. This should be
|
|
124
|
+
a descriptive string of the information you are looking for.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
FILTER_MEM = """
|
|
128
|
+
An optional string filter applied to the memory metadata. This uses a
|
|
129
|
+
simple query language (e.g., 'metadata.user_id=123') for exact matches.
|
|
130
|
+
Multiple conditions can be combined using AND operators. The metadata
|
|
131
|
+
fields are prefixed with 'metadata.' to distinguish them from other fields.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
MEMORY_TYPES = """
|
|
135
|
+
A list of memory types to include in the search (e.g., Episodic, Semantic).
|
|
136
|
+
If empty, all available types are searched.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
PAGE_SIZE = """
|
|
140
|
+
The maximum number of memories to return per page. Use this for pagination.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
PAGE_NUM = """
|
|
144
|
+
The zero-based page number to retrieve. Use this for pagination.
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
MEMORY_TYPE_SINGLE = """
|
|
148
|
+
The specific memory type to list (e.g., Episodic or Semantic).
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
EPISODIC_ID = """
|
|
152
|
+
The unique ID of the specific episodic memory.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
EPISODIC_IDS = """
|
|
156
|
+
A list of unique IDs of episodic memories."""
|
|
157
|
+
|
|
158
|
+
SEMANTIC_ID = """
|
|
159
|
+
The unique ID of the specific semantic memory.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
SEMANTIC_IDS = """
|
|
163
|
+
A list of unique IDs of semantic memories."""
|
|
164
|
+
|
|
165
|
+
STATUS = """
|
|
166
|
+
The status code of the search operation. 0 typically indicates success.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
CONTENT = """
|
|
170
|
+
The dictionary containing the memory search results (e.g., list of memory
|
|
171
|
+
objects).
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
ERROR_CODE = """
|
|
175
|
+
The http status code if the operation failed."""
|
|
176
|
+
|
|
177
|
+
ERROR_MESSAGE = """
|
|
178
|
+
A descriptive error message if the operation failed."""
|
|
179
|
+
|
|
180
|
+
ERROR_EXCEPTION = """
|
|
181
|
+
The exception details if an error occurred during the operation."""
|
|
182
|
+
|
|
183
|
+
ERROR_TRACE = """
|
|
184
|
+
The stack trace of the exception if available."""
|
|
185
|
+
|
|
186
|
+
ERROR_INTERNAL = """
|
|
187
|
+
The real error that triggered the exception, for internal debugging."""
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class Examples:
|
|
191
|
+
"""Common examples for API fields."""
|
|
192
|
+
|
|
193
|
+
ORG_ID: ClassVar[list[str]] = ["MemVerge", "AI_Labs"]
|
|
194
|
+
PROJECT_ID: ClassVar[list[str]] = ["memmachine", "research123", "qa_pipeline"]
|
|
195
|
+
PROJECT_DESCRIPTION: ClassVar[list[str]] = [
|
|
196
|
+
"Test project for RAG pipeline",
|
|
197
|
+
"Production semantic search index",
|
|
198
|
+
]
|
|
199
|
+
RERANKER: ClassVar[list[str]] = ["bge-reranker-large", "my-custom-reranker"]
|
|
200
|
+
EMBEDDER: ClassVar[list[str]] = ["bge-base-en", "my-embedder"]
|
|
201
|
+
TOP_K: ClassVar[list[int]] = [5, 10, 20]
|
|
202
|
+
QUERY: ClassVar[list[str]] = [
|
|
203
|
+
"What was the user's last conversation about finance?"
|
|
204
|
+
]
|
|
205
|
+
FILTER_MEM: ClassVar[list[str]] = [
|
|
206
|
+
"metadata.user_id=123 AND metadata.session_id=abc",
|
|
207
|
+
]
|
|
208
|
+
MEMORY_TYPES: ClassVar[list[list[str]]] = [["Episodic", "Semantic"]]
|
|
209
|
+
MEMORY_TYPE_SINGLE: ClassVar[list[str]] = ["Episodic", "Semantic"]
|
|
210
|
+
PAGE_SIZE: ClassVar[list[int]] = [50, 100]
|
|
211
|
+
PAGE_NUM: ClassVar[list[int]] = [0, 1, 5, 10]
|
|
212
|
+
EPISODIC_ID: ClassVar[list[str]] = ["123", "345"]
|
|
213
|
+
EPISODIC_IDS: ClassVar[list[list[str]]] = [["123", "345"], ["23"]]
|
|
214
|
+
SEMANTIC_ID: ClassVar[list[str]] = ["12", "23"]
|
|
215
|
+
SEMANTIC_IDS: ClassVar[list[list[str]]] = [["123", "345"], ["23"]]
|
|
216
|
+
SEARCH_RESULT_STATUS: ClassVar[list[int]] = [0]
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class RouterDoc:
|
|
220
|
+
"""Common descriptions for API routers."""
|
|
221
|
+
|
|
222
|
+
CREATE_PROJECT = """
|
|
223
|
+
Create a new project.
|
|
224
|
+
|
|
225
|
+
This endpoint creates a project under the specified organization using the
|
|
226
|
+
provided identifiers and configuration. Both `org_id` and `project_id`
|
|
227
|
+
follow the rules: no slashes; only letters, numbers, underscores,
|
|
228
|
+
hyphens, colon, and Unicode characters.
|
|
229
|
+
|
|
230
|
+
Each project acts as an isolated memory namespace. All memories (episodes)
|
|
231
|
+
inserted into a project belong exclusively to that project. Queries,
|
|
232
|
+
listings, and any background operations such as memory summarization or
|
|
233
|
+
knowledge extraction only access data within the same project. No
|
|
234
|
+
cross-project memory access is allowed.
|
|
235
|
+
|
|
236
|
+
If a project with the same ID already exists within the organization,
|
|
237
|
+
the request will fail with an error.
|
|
238
|
+
|
|
239
|
+
Returns the fully resolved project record, including configuration defaults
|
|
240
|
+
applied by the system.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
GET_PROJECT = """
|
|
244
|
+
Retrieve a project.
|
|
245
|
+
|
|
246
|
+
Returns the project identified by `org_id` and `project_id`, following
|
|
247
|
+
the same rules as project creation.
|
|
248
|
+
|
|
249
|
+
Each project acts as an isolated memory namespace. Queries and operations
|
|
250
|
+
only access memories (episodes) stored within this project. No data from
|
|
251
|
+
other projects is visible or included in any background processing, such as
|
|
252
|
+
memory summarization or knowledge extraction.
|
|
253
|
+
|
|
254
|
+
The response includes the project's description and effective configuration.
|
|
255
|
+
If the project does not exist, a not-found error is returned.
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
GET_EPISODE_COUNT = """
|
|
259
|
+
Retrieve the episode count for a project.
|
|
260
|
+
|
|
261
|
+
An *episode* is the minimal unit of memory stored in the MemMachine system.
|
|
262
|
+
In most cases, a single episode corresponds to one message or interaction
|
|
263
|
+
from a user. Episodes are appended as the project accumulates conversational
|
|
264
|
+
or operational data.
|
|
265
|
+
|
|
266
|
+
This endpoint returns the total number of episodes currently recorded for
|
|
267
|
+
the specified project. If the project does not exist, a not-found error is
|
|
268
|
+
returned.
|
|
269
|
+
"""
|
|
270
|
+
|
|
271
|
+
LIST_PROJECTS = """
|
|
272
|
+
List all projects.
|
|
273
|
+
|
|
274
|
+
Returns a list of all projects accessible within the system. Each entry
|
|
275
|
+
contains the project's organization ID and project ID. Identifiers follow
|
|
276
|
+
the standard rules: no slashes; only letters, numbers, underscores,
|
|
277
|
+
hyphens, colon, and Unicode characters.
|
|
278
|
+
|
|
279
|
+
Projects are isolated memory namespaces. Memories (episodes) belong
|
|
280
|
+
exclusively to their project. All project operations, including queries and
|
|
281
|
+
any background processes (e.g., memory summarization or knowledge
|
|
282
|
+
extraction), only operate within the project's own data. No cross-project
|
|
283
|
+
access is allowed.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
DELETE_PROJECT = """
|
|
287
|
+
Delete a project.
|
|
288
|
+
|
|
289
|
+
Deletes the specified project identified by `org_id` and `project_id`,
|
|
290
|
+
following the same rules as project creation.
|
|
291
|
+
|
|
292
|
+
This operation removes the project and all associated memories (episodes)
|
|
293
|
+
permanently from the system. It cannot be undone.
|
|
294
|
+
|
|
295
|
+
If the project does not exist, a not-found error is returned.
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
ADD_MEMORIES = """
|
|
299
|
+
Add memory messages to a project.
|
|
300
|
+
|
|
301
|
+
The `types` field in the request specifies which memory types to add to:
|
|
302
|
+
- If `types` is empty or not provided, memories are added to all types (Episodic and Semantic)
|
|
303
|
+
- If `types` only contains `"episodic"`, memories are added only to Episodic memory
|
|
304
|
+
- If `types` only contains `"semantic"`, memories are added only to Semantic memory
|
|
305
|
+
- If `types` contains both, memories are added to both types
|
|
306
|
+
|
|
307
|
+
Each memory message represents a discrete piece of information to be stored
|
|
308
|
+
in the project's memory system. Messages can include content, metadata,
|
|
309
|
+
timestamps, and other contextual details.
|
|
310
|
+
|
|
311
|
+
The producer field indicates who created the message, while the
|
|
312
|
+
produced_for field specifies the intended recipient. These fields help
|
|
313
|
+
provide context for the memory and if provided should be user-friendly names.
|
|
314
|
+
|
|
315
|
+
The endpoint accepts a batch of messages to be added in a single request.
|
|
316
|
+
"""
|
|
317
|
+
|
|
318
|
+
SEARCH_MEMORIES = """
|
|
319
|
+
Search memories within a project.
|
|
320
|
+
|
|
321
|
+
System returns the top K relevant memories matching the natural language query.
|
|
322
|
+
The result is sorted by timestamp to help with context.
|
|
323
|
+
|
|
324
|
+
The filter field allows for filtering based on metadata key-value pairs.
|
|
325
|
+
The types field allows specifying which memory types to include in the search.
|
|
326
|
+
"""
|
|
327
|
+
|
|
328
|
+
LIST_MEMORIES = """
|
|
329
|
+
List memories within a project.
|
|
330
|
+
|
|
331
|
+
System returns a paginated list of memories stored in the project.
|
|
332
|
+
The page_size and page_num fields control pagination.
|
|
333
|
+
|
|
334
|
+
The filter field allows for filtering based on metadata key-value pairs.
|
|
335
|
+
The type field allows specifying which memory type to list.
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
DELETE_EPISODIC_MEMORY = """
|
|
339
|
+
Delete episodic memories from a project.
|
|
340
|
+
|
|
341
|
+
This operation permanently removes one or more episodic memories from the
|
|
342
|
+
specified project. You may provide either `episodic_id` to delete a single
|
|
343
|
+
memory or `episodic_ids` to delete multiple memories in one request.
|
|
344
|
+
This action cannot be undone.
|
|
345
|
+
|
|
346
|
+
If any of the specified episodic memories do not exist, a not-found error
|
|
347
|
+
is returned for those entries.
|
|
348
|
+
"""
|
|
349
|
+
|
|
350
|
+
DELETE_SEMANTIC_MEMORY = """
|
|
351
|
+
Delete semantic memories from a project.
|
|
352
|
+
|
|
353
|
+
This operation permanently removes one or more semantic memories from the
|
|
354
|
+
specified project. You may provide either `semantic_id` to delete a single
|
|
355
|
+
memory or `semantic_ids` to delete multiple memories in one request.
|
|
356
|
+
This action cannot be undone.
|
|
357
|
+
|
|
358
|
+
If any of the specified semantic memories do not exist, a not-found error
|
|
359
|
+
is returned for those entries.
|
|
360
|
+
"""
|
|
361
|
+
|
|
362
|
+
METRICS_PROMETHEUS = """
|
|
363
|
+
Expose Prometheus metrics."""
|
|
364
|
+
|
|
365
|
+
HEALTH_CHECK = """
|
|
366
|
+
Health check endpoint to verify server is running."""
|