mdb-engine 0.7.3__py3-none-any.whl → 0.7.5__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.
- mdb_engine/__init__.py +1 -1
- mdb_engine/cli/main.py +1 -1
- mdb_engine/core/engine.py +3 -2
- mdb_engine/core/service_initialization.py +5 -4
- mdb_engine/core/types.py +2 -2
- mdb_engine/dependencies.py +3 -3
- mdb_engine/memory/README.md +231 -27
- mdb_engine/memory/__init__.py +9 -0
- mdb_engine/memory/base.py +224 -0
- mdb_engine/memory/service.py +415 -162
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/METADATA +1 -1
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/RECORD +16 -15
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/WHEEL +0 -0
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/entry_points.txt +0 -0
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/licenses/LICENSE +0 -0
- {mdb_engine-0.7.3.dist-info → mdb_engine-0.7.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Base Memory Service Interface
|
|
3
|
+
|
|
4
|
+
Abstract base class for memory service implementations.
|
|
5
|
+
This allows for extensibility with different memory providers (Mem0, LangChain, custom, etc.)
|
|
6
|
+
while maintaining a consistent API.
|
|
7
|
+
|
|
8
|
+
This module is part of MDB_ENGINE - MongoDB Engine.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from abc import ABC, abstractmethod
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MemoryServiceError(Exception):
|
|
16
|
+
"""Base exception for all memory service errors."""
|
|
17
|
+
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BaseMemoryService(ABC):
|
|
22
|
+
"""
|
|
23
|
+
Abstract base class for memory service implementations.
|
|
24
|
+
|
|
25
|
+
This class defines the interface that all memory service implementations must follow.
|
|
26
|
+
Concrete implementations (e.g., Mem0MemoryService) inherit from this class and
|
|
27
|
+
implement the abstract methods.
|
|
28
|
+
|
|
29
|
+
All memory operations are scoped per user_id for safety and data isolation.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def add(
|
|
34
|
+
self,
|
|
35
|
+
messages: str | list[dict[str, str]],
|
|
36
|
+
user_id: str | None = None,
|
|
37
|
+
metadata: dict[str, Any] | None = None,
|
|
38
|
+
bucket_id: str | None = None,
|
|
39
|
+
bucket_type: str | None = None,
|
|
40
|
+
raw_content: str | None = None,
|
|
41
|
+
**kwargs,
|
|
42
|
+
) -> list[dict[str, Any]]:
|
|
43
|
+
"""
|
|
44
|
+
Add memories with user scoping and metadata convenience.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
messages: Memory content as a string or list of message dicts
|
|
48
|
+
user_id: User ID for scoping (optional but recommended)
|
|
49
|
+
metadata: Additional metadata to store with the memory
|
|
50
|
+
bucket_id: Bucket ID for organizing memories
|
|
51
|
+
bucket_type: Type of bucket (e.g., "general", "file", "conversation")
|
|
52
|
+
raw_content: Raw content to store alongside extracted facts
|
|
53
|
+
**kwargs: Additional provider-specific arguments
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
List of created memory objects with their IDs and metadata
|
|
57
|
+
"""
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
@abstractmethod
|
|
61
|
+
def inject(
|
|
62
|
+
self,
|
|
63
|
+
memory: str | dict[str, Any],
|
|
64
|
+
user_id: str | None = None,
|
|
65
|
+
metadata: dict[str, Any] | None = None,
|
|
66
|
+
**kwargs,
|
|
67
|
+
) -> dict[str, Any]:
|
|
68
|
+
"""
|
|
69
|
+
Manually inject a memory without LLM inference.
|
|
70
|
+
|
|
71
|
+
This method allows direct insertion of memories without going through
|
|
72
|
+
the inference pipeline. Useful for manually adding facts, preferences,
|
|
73
|
+
or other structured data.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
memory: Memory content as a string or dict with memory/text/content key
|
|
77
|
+
user_id: User ID for scoping (optional but recommended)
|
|
78
|
+
metadata: Additional metadata to store with the memory
|
|
79
|
+
**kwargs: Additional provider-specific arguments
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Created memory object with ID and metadata
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
MemoryServiceError: If injection operation fails
|
|
86
|
+
ValueError: If memory content is invalid or empty
|
|
87
|
+
"""
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def get_all(
|
|
92
|
+
self,
|
|
93
|
+
user_id: str | None = None,
|
|
94
|
+
limit: int = 100,
|
|
95
|
+
filters: dict[str, Any] | None = None,
|
|
96
|
+
**kwargs,
|
|
97
|
+
) -> list[dict[str, Any]]:
|
|
98
|
+
"""
|
|
99
|
+
Get all memories with optional filtering.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
user_id: User ID to filter memories (optional)
|
|
103
|
+
limit: Maximum number of memories to return
|
|
104
|
+
filters: Additional filters to apply (provider-specific)
|
|
105
|
+
**kwargs: Additional provider-specific arguments
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
List of memory objects
|
|
109
|
+
"""
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
@abstractmethod
|
|
113
|
+
def search(
|
|
114
|
+
self,
|
|
115
|
+
query: str,
|
|
116
|
+
user_id: str | None = None,
|
|
117
|
+
limit: int = 5,
|
|
118
|
+
filters: dict[str, Any] | None = None,
|
|
119
|
+
**kwargs,
|
|
120
|
+
) -> list[dict[str, Any]]:
|
|
121
|
+
"""
|
|
122
|
+
Perform semantic search across memories.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
query: Search query string
|
|
126
|
+
user_id: User ID to scope search (optional)
|
|
127
|
+
limit: Maximum number of results to return
|
|
128
|
+
filters: Additional metadata filters to apply
|
|
129
|
+
**kwargs: Additional provider-specific arguments
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
List of memory objects matching the query, ordered by relevance
|
|
133
|
+
"""
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
@abstractmethod
|
|
137
|
+
def get(
|
|
138
|
+
self,
|
|
139
|
+
memory_id: str,
|
|
140
|
+
user_id: str | None = None,
|
|
141
|
+
**kwargs,
|
|
142
|
+
) -> dict[str, Any] | None:
|
|
143
|
+
"""
|
|
144
|
+
Get a single memory by ID.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
memory_id: Unique identifier for the memory
|
|
148
|
+
user_id: User ID for security scoping (optional)
|
|
149
|
+
**kwargs: Additional provider-specific arguments
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Memory object if found, None otherwise
|
|
153
|
+
"""
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
@abstractmethod
|
|
157
|
+
def delete(
|
|
158
|
+
self,
|
|
159
|
+
memory_id: str,
|
|
160
|
+
user_id: str | None = None,
|
|
161
|
+
**kwargs,
|
|
162
|
+
) -> bool:
|
|
163
|
+
"""
|
|
164
|
+
Delete a single memory by ID.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
memory_id: Unique identifier for the memory to delete
|
|
168
|
+
user_id: User ID for security scoping (optional)
|
|
169
|
+
**kwargs: Additional provider-specific arguments
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
True if deletion was successful, False otherwise
|
|
173
|
+
"""
|
|
174
|
+
pass
|
|
175
|
+
|
|
176
|
+
@abstractmethod
|
|
177
|
+
def delete_all(
|
|
178
|
+
self,
|
|
179
|
+
user_id: str | None = None,
|
|
180
|
+
**kwargs,
|
|
181
|
+
) -> bool:
|
|
182
|
+
"""
|
|
183
|
+
Delete all memories for a user.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
user_id: User ID whose memories should be deleted (optional)
|
|
187
|
+
**kwargs: Additional provider-specific arguments
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
True if deletion was successful, False otherwise
|
|
191
|
+
"""
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
@abstractmethod
|
|
195
|
+
def update(
|
|
196
|
+
self,
|
|
197
|
+
memory_id: str,
|
|
198
|
+
user_id: str | None = None,
|
|
199
|
+
memory: str | None = None,
|
|
200
|
+
data: str | dict[str, Any] | None = None,
|
|
201
|
+
messages: str | list[dict[str, str]] | None = None,
|
|
202
|
+
metadata: dict[str, Any] | None = None,
|
|
203
|
+
**kwargs,
|
|
204
|
+
) -> dict[str, Any] | None:
|
|
205
|
+
"""
|
|
206
|
+
Update an existing memory's content and/or metadata.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
memory_id: Unique identifier for the memory to update (required)
|
|
210
|
+
user_id: User ID for security scoping (optional)
|
|
211
|
+
memory: New memory content as a string (optional)
|
|
212
|
+
data: Alternative parameter for content (string or dict) (optional)
|
|
213
|
+
messages: Alternative way to provide content as messages (optional)
|
|
214
|
+
metadata: Metadata updates (optional)
|
|
215
|
+
**kwargs: Additional provider-specific arguments
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
Updated memory object if successful, None if memory not found
|
|
219
|
+
|
|
220
|
+
Raises:
|
|
221
|
+
MemoryServiceError: If update operation fails
|
|
222
|
+
ValueError: If memory_id is invalid or empty
|
|
223
|
+
"""
|
|
224
|
+
pass
|