API Reference
This page provides comprehensive API documentation for memg-core.
Public API
The main interface for memg-core is through the public API module:
Public API for memg-core - designed for long-running servers.
Provides MemgClient for explicit initialization and module-level functions for environment-based usage.
_CLIENT = None
module-attribute
DatabaseClients
DDL-only database setup - creates schemas and returns raw clients.
NO INTERFACES - pure schema creation only. Consumer must create interfaces separately using returned raw clients.
Attributes:
Name | Type | Description |
---|---|---|
qdrant_client |
QdrantClient | None
|
Pre-initialized QdrantClient. |
kuzu_connection |
Connection | None
|
Pre-initialized Kuzu connection. |
db_name |
Database name. |
|
qdrant_path |
Path to Qdrant database. |
|
kuzu_path |
Path to Kuzu database. |
|
yaml_translator |
YAML translator instance. |
Source code in src/memg_core/utils/db_clients.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
__init__(yaml_path=None)
Create DDL-only database client wrapper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str | None
|
Path to YAML schema file. User must provide - no defaults. |
None
|
Source code in src/memg_core/utils/db_clients.py
40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
close()
Close all database connections and cleanup resources.
Should be called when database clients are no longer needed.
Source code in src/memg_core/utils/db_clients.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
get_embedder()
Get embedder instance.
Returns:
Name | Type | Description |
---|---|---|
Embedder |
Embedder
|
Instance for generating vectors. |
Source code in src/memg_core/utils/db_clients.py
182 183 184 185 186 187 188 |
|
get_kuzu_interface()
Get Kuzu interface using the initialized connection.
Returns:
Name | Type | Description |
---|---|---|
KuzuInterface |
KuzuInterface
|
Configured with the DDL-created connection. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If connection not initialized (call init_dbs first). |
Source code in src/memg_core/utils/db_clients.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
get_qdrant_interface()
Get Qdrant interface using the initialized client.
Returns:
Name | Type | Description |
---|---|---|
QdrantInterface |
QdrantInterface
|
Configured with the DDL-created client and collection. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If client not initialized (call init_dbs first). |
Source code in src/memg_core/utils/db_clients.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
get_yaml_translator()
Get the YAML translator used for schema operations.
Returns:
Name | Type | Description |
---|---|---|
YamlTranslator |
YamlTranslator
|
Instance used during DDL operations. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If YAML translator not initialized. |
Source code in src/memg_core/utils/db_clients.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
init_dbs(db_path, db_name)
Initialize databases with structured paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_path
|
str
|
Base database directory. |
required |
db_name
|
str
|
Database name (used for collection and file names). |
required |
Source code in src/memg_core/utils/db_clients.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
MemgClient
Client for memg-core operations - initialize once, use throughout server lifetime.
Provides a clean interface for memory operations with explicit resource management.
Source code in src/memg_core/api/public.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
__init__(yaml_path, db_path)
Initialize client for long-running server usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str
|
Path to YAML schema configuration file. |
required |
db_path
|
str
|
Base directory path for database storage. |
required |
Source code in src/memg_core/api/public.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
add_memory(memory_type, payload, user_id)
Add memory and return HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_type
|
str
|
Entity type from YAML schema (e.g., 'task', 'note'). |
required |
payload
|
dict[str, Any]
|
Memory data conforming to YAML schema. |
required |
user_id
|
str
|
Owner of the memory. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Human-readable ID (HRID) for the created memory. |
Source code in src/memg_core/api/public.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
add_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type, to_memory_type, user_id, properties=None)
Add relationship between memories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema. |
required |
from_memory_type
|
str
|
Source memory entity type. |
required |
to_memory_type
|
str
|
Target memory entity type. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
properties
|
dict[str, Any] | None
|
Optional relationship properties. |
None
|
Source code in src/memg_core/api/public.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
close()
Close client and cleanup resources.
Should be called when the client is no longer needed to free database connections.
Source code in src/memg_core/api/public.py
233 234 235 236 237 238 239 |
|
delete_memory(hrid, user_id, memory_type=None)
Delete memory by HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID of the memory to delete. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False otherwise. |
Source code in src/memg_core/api/public.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
delete_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type=None, to_memory_type=None, user_id=None)
Delete relationship between memories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema. |
required |
from_memory_type
|
str | None
|
Source memory entity type (inferred from HRID if not provided). |
None
|
to_memory_type
|
str | None
|
Target memory entity type (inferred from HRID if not provided). |
None
|
user_id
|
str | None
|
User ID for ownership verification (required). |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False if relationship not found. |
Source code in src/memg_core/api/public.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
get_memories(user_id, memory_type=None, filters=None, limit=50, offset=0, include_neighbors=False, hops=1)
Get multiple memories with filtering and optional graph expansion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type filter (e.g., "task", "note"). |
None
|
filters
|
dict[str, Any] | None
|
Optional field filters (e.g., {"status": "open", "priority": "high"}). |
None
|
limit
|
int
|
Maximum number of memories to return (default 50). |
50
|
offset
|
int
|
Number of memories to skip for pagination (default 0). |
0
|
include_neighbors
|
bool
|
Whether to include neighbor nodes via graph traversal. |
False
|
hops
|
int
|
Number of hops for neighbor expansion (default 1). |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of memory data with full payloads. |
Source code in src/memg_core/api/public.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
get_memory(hrid, user_id, memory_type=None)
Get a single memory by HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable identifier of the memory. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Memory data with full payload, or None if not found. |
Source code in src/memg_core/api/public.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
search(query, user_id, memory_type=None, limit=10, score_threshold=None, decay_threshold=None, **kwargs)
Search memories with explicit seed/neighbor separation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to search for. |
required |
user_id
|
str
|
User ID for filtering results. |
required |
memory_type
|
str | None
|
Optional memory type filter. |
None
|
limit
|
int
|
Maximum number of results to return. |
10
|
score_threshold
|
float | None
|
Minimum similarity score threshold (0.0-1.0). |
None
|
decay_threshold
|
float | None
|
Minimum neighbor relevance threshold (0.0-1.0). |
None
|
**kwargs
|
Additional search parameters. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
SearchResult |
SearchResult
|
Search result with explicit seed/neighbor separation, including full payloads for seeds and relationships. |
Source code in src/memg_core/api/public.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
update_memory(hrid, payload_updates, user_id, memory_type=None)
Update memory with partial payload changes (patch-style update).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Memory HRID to update. |
required |
payload_updates
|
dict[str, Any]
|
Dictionary of fields to update (only changed fields). |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if update succeeded, False otherwise. |
Source code in src/memg_core/api/public.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
MemoryService
Unified memory service - handles indexing, search, and deletion operations.
Provides a clean, class-based interface for all memory operations using DatabaseClients for both DDL initialization and CRUD interface access. Eliminates the need for scattered interface creation.
Attributes:
Name | Type | Description |
---|---|---|
qdrant |
Qdrant interface instance. |
|
kuzu |
Kuzu interface instance. |
|
embedder |
Embedder instance. |
|
yaml_translator |
YAML translator instance. |
|
hrid_tracker |
HRID tracker instance. |
Source code in src/memg_core/core/pipelines/indexer.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
__init__(db_clients)
Initialize MemoryService with DatabaseClients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_clients
|
DatabaseClients instance (after init_dbs() called). |
required |
Source code in src/memg_core/core/pipelines/indexer.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
add_memory(memory_type, payload, user_id, collection=None)
Add a memory to both graph and vector storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_type
|
str
|
Entity type from YAML schema (e.g., 'task', 'note'). |
required |
payload
|
dict[str, Any]
|
Memory data conforming to YAML schema. |
required |
user_id
|
str
|
Owner of the memory. |
required |
collection
|
str | None
|
Optional Qdrant collection override. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Memory HRID (Human-readable ID string). |
Raises:
Type | Description |
---|---|
ProcessingError
|
If validation fails or storage operations fail. |
Source code in src/memg_core/core/pipelines/indexer.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
add_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type, to_memory_type, user_id, properties=None)
Add a relationship between two memories using HRIDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema (e.g., 'ANNOTATES'). |
required |
from_memory_type
|
str
|
Source memory entity type. |
required |
to_memory_type
|
str
|
Target memory entity type. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
properties
|
dict[str, Any] | None
|
Optional relationship properties. |
None
|
Raises:
Type | Description |
---|---|
ProcessingError
|
If relationship creation fails. |
Source code in src/memg_core/core/pipelines/indexer.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
delete_memory(memory_hrid, memory_type, user_id)
Delete a memory from both storages using HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_hrid
|
str
|
Memory HRID to delete. |
required |
memory_type
|
str
|
Memory entity type. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded. |
Source code in src/memg_core/core/pipelines/indexer.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
delete_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type=None, to_memory_type=None, user_id=None)
Delete a relationship between two memories using HRIDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema (e.g., 'ANNOTATES'). |
required |
from_memory_type
|
str | None
|
Source memory entity type (inferred from HRID if not provided). |
None
|
to_memory_type
|
str | None
|
Target memory entity type (inferred from HRID if not provided). |
None
|
user_id
|
str | None
|
User ID for ownership verification (required). |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False if relationship not found. |
Raises:
Type | Description |
---|---|
ProcessingError
|
If relationship deletion fails or parameters invalid. |
Source code in src/memg_core/core/pipelines/indexer.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
update_memory(hrid, payload_updates, user_id, memory_type=None, collection=None)
Update memory with partial payload changes (patch-style update).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Memory HRID to update. |
required |
payload_updates
|
dict[str, Any]
|
Dictionary of fields to update (only changed fields). |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
collection
|
str | None
|
Optional Qdrant collection override. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if update succeeded. |
Raises:
Type | Description |
---|---|
ProcessingError
|
If update fails or memory not found. |
Source code in src/memg_core/core/pipelines/indexer.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
SearchResult
Bases: BaseModel
Search result with explicit seed/neighbor separation.
Attributes:
Name | Type | Description |
---|---|---|
memories |
list[MemorySeed]
|
List of memory seeds with full payloads and relationships. |
neighbors |
list[MemoryNeighbor]
|
List of memory neighbors with anchor-only payloads. |
Source code in src/memg_core/core/models.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
SearchService
Unified search service - handles all search and retrieval operations.
Provides GraphRAG search functionality using DatabaseClients for interface access. Eliminates the need to pass interfaces as function parameters.
Attributes:
Name | Type | Description |
---|---|---|
qdrant |
Qdrant interface instance. |
|
kuzu |
Kuzu interface instance. |
|
embedder |
Embedder instance. |
|
yaml_translator |
YAML translator instance. |
|
hrid_tracker |
HRID tracker instance. |
Source code in src/memg_core/core/pipelines/retrieval.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
__init__(db_clients)
Initialize SearchService with DatabaseClients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_clients
|
DatabaseClients instance (after init_dbs() called). |
required |
Source code in src/memg_core/core/pipelines/retrieval.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
get_memories(user_id, memory_type=None, filters=None, limit=50, offset=0, include_neighbors=False, hops=1)
Get multiple memories with filtering and optional graph expansion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type filter (e.g., "task", "note"). |
None
|
filters
|
dict[str, Any] | None
|
Optional field filters (e.g., {"status": "open", "priority": "high"}). |
None
|
limit
|
int
|
Maximum number of memories to return (default 50). |
50
|
offset
|
int
|
Number of memories to skip for pagination (default 0). |
0
|
include_neighbors
|
bool
|
Whether to include neighbor nodes via graph traversal. |
False
|
hops
|
int
|
Number of hops for neighbor expansion (default 1). |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of memory data with full payloads. |
Source code in src/memg_core/core/pipelines/retrieval.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
get_memory(hrid, user_id, memory_type=None, collection=None)
Get a single memory by HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable identifier of the memory. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
collection
|
str | None
|
Optional Qdrant collection override. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Memory data with full payload, or None if not found. |
Source code in src/memg_core/core/pipelines/retrieval.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
get_memory_neighbors(memory_id, memory_type, user_id, relation_types=None, direction='any', limit=10)
Get related memories through graph relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_id
|
str
|
Memory ID to find neighbors for |
required |
memory_type
|
str
|
Memory entity type |
required |
user_id
|
str
|
User ID for isolation |
required |
relation_types
|
list[str] | None
|
Filter by specific relationship types |
None
|
direction
|
str
|
"in", "out", or "any" |
'any'
|
limit
|
int
|
Maximum number of neighbors |
10
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
List of neighbor memories with relationship info |
Source code in src/memg_core/core/pipelines/retrieval.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
|
search(query, user_id, limit=5, *, memory_type=None, relation_names=None, neighbor_limit=5, hops=1, include_semantic=True, include_details='self', modified_within_days=None, filters=None, projection=None, score_threshold=None, decay_threshold=None)
GraphRAG search: vector seeds → graph expansion → semantic enhancement.
This method encapsulates the graph_rag_search logic as a class method, eliminating the need to pass interfaces as parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Search query text (required). |
required |
user_id
|
str
|
User ID for filtering (required). |
required |
limit
|
int
|
Maximum results to return (default: 5). |
5
|
memory_type
|
str | None
|
Optional memory type filter. |
None
|
relation_names
|
list[str] | None
|
Specific relations to expand (None = all relations). |
None
|
neighbor_limit
|
int
|
Max neighbors per seed (default: 5). |
5
|
hops
|
int
|
Number of graph hops to expand (default: 1). |
1
|
include_semantic
|
bool
|
Enable semantic expansion via see_also (default: True). |
True
|
include_details
|
str
|
"self" (full payload) or "none" (anchor only) for seeds. |
'self'
|
modified_within_days
|
int | None
|
Filter by recency (e.g., last 7 days). |
None
|
filters
|
dict[str, Any] | None
|
Custom field-based filtering (e.g., {"project": "memg-core"}). |
None
|
projection
|
dict[str, list[str]] | None
|
Control which fields to return per memory type. |
None
|
score_threshold
|
float | None
|
Minimum similarity score threshold (0.0-1.0). |
None
|
decay_threshold
|
float | None
|
Minimum neighbor relevance threshold (0.0-1.0). |
None
|
Returns:
Name | Type | Description |
---|---|---|
SearchResult |
SearchResult
|
Search result with explicit seed/neighbor separation. |
Source code in src/memg_core/core/pipelines/retrieval.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
YamlTranslator
Translates YAML schema definitions to Pydantic models for strict validation.
Attributes:
Name | Type | Description |
---|---|---|
yaml_path |
Path to YAML schema file. |
|
_schema |
dict[str, Any] | None
|
Cached schema dictionary. |
Source code in src/memg_core/core/yaml_translator.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
schema
property
Get the loaded YAML schema, loading it if necessary.
__init__(yaml_path=None)
Initialize YamlTranslator with YAML schema path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str | None
|
Path to YAML schema file. If None, uses MEMG_YAML_SCHEMA env var. |
None
|
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If YAML path not provided or TypeRegistry initialization fails. |
Source code in src/memg_core/core/yaml_translator.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
build_anchor_text(memory)
Build anchor text for embedding from YAML-defined anchor field.
NO hardcoded field names - reads anchor field from YAML schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory
|
Memory object containing payload data. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor text for embedding. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field is missing or invalid. |
Source code in src/memg_core/core/yaml_translator.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
create_memory_from_yaml(memory_type, payload, user_id)
Create a Memory object from YAML-validated payload.
Source code in src/memg_core/core/yaml_translator.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
|
debug_relation_map()
Return a nested relation map for debugging/printing.
Structure: { source: { target: [ {name, predicate, directed, description} ... ] } }
Source code in src/memg_core/core/yaml_translator.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
get_anchor_field(entity_name)
Get the anchor field name for the given entity type from YAML schema.
Now reads from vector.anchored_to instead of separate anchor field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of the entity type. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor field name. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field not found. |
Source code in src/memg_core/core/yaml_translator.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
get_entity_model(entity_name)
Get Pydantic model from TypeRegistry - NO REDUNDANCY.
Source code in src/memg_core/core/yaml_translator.py
619 620 621 |
|
get_entity_types()
Get list of available entity types from YAML schema.
Source code in src/memg_core/core/yaml_translator.py
123 124 125 |
|
get_labels_for_predicates(source_type, predicates, neighbor_label=None)
Expand predicate names to concrete relationship labels for a given source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_type
|
str
|
Source entity type name |
required |
predicates
|
list[str] | None
|
List of predicate names to include (case-insensitive). If None, include all. |
required |
neighbor_label
|
str | None
|
Optional target entity type filter (case-insensitive) |
None
|
Returns:
Type | Description |
---|---|
list[str]
|
List of concrete relationship labels (table names) matching the filter. |
Source code in src/memg_core/core/yaml_translator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
get_relations_for_source(entity_name)
Get normalized relation specs for a source entity in target-first schema.
Returns list of dicts with keys
- source (str)
- target (str)
- name (str | None)
- description (str | None)
- predicate (str)
- directed (bool)
Source code in src/memg_core/core/yaml_translator.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
get_see_also_config(entity_name)
Get the see_also configuration for the given entity type from YAML schema.
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
Dict with keys: enabled, threshold, limit, target_types |
dict[str, Any] | None
|
None if see_also is not configured for this entity |
Source code in src/memg_core/core/yaml_translator.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
relationship_table_name(source, predicate, target, *, directed=True)
staticmethod
Generate relationship table name.
For now, table name does not encode direction; direction affects creation/query semantics. Canonicalization for undirected pairs can be added here later if decided.
Source code in src/memg_core/core/yaml_translator.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
validate_memory_against_yaml(memory_type, payload)
Validate memory payload against YAML schema and return cleaned payload.
Source code in src/memg_core/core/yaml_translator.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
|
_get_client()
Get or create singleton client from environment variables.
Returns:
Name | Type | Description |
---|---|---|
MemgClient |
MemgClient
|
Singleton client instance. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If required environment variables are not set. |
Source code in src/memg_core/api/public.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
add_memory(memory_type, payload, user_id)
Add memory using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_type
|
str
|
Entity type from YAML schema (e.g., 'task', 'note'). |
required |
payload
|
dict[str, Any]
|
Memory data conforming to YAML schema. |
required |
user_id
|
str
|
Owner of the memory. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Human-readable ID (HRID) for the created memory. |
Source code in src/memg_core/api/public.py
268 269 270 271 272 273 274 275 276 277 278 279 |
|
add_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type, to_memory_type, user_id, properties=None)
Add relationship using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema. |
required |
from_memory_type
|
str
|
Source memory entity type. |
required |
to_memory_type
|
str
|
Target memory entity type. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
properties
|
dict[str, Any] | None
|
Optional relationship properties. |
None
|
Source code in src/memg_core/api/public.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
create_memory_service(db_clients)
Factory function to create a MemoryService instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_clients
|
DatabaseClients instance (after init_dbs() called). |
required |
Returns:
Name | Type | Description |
---|---|---|
MemoryService |
MemoryService
|
Configured MemoryService instance. |
Source code in src/memg_core/core/pipelines/indexer.py
437 438 439 440 441 442 443 444 445 446 |
|
create_search_service(db_clients)
Factory function to create a SearchService instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_clients
|
DatabaseClients instance (after init_dbs() called). |
required |
Returns:
Name | Type | Description |
---|---|---|
SearchService |
SearchService
|
Configured SearchService instance. |
Source code in src/memg_core/core/pipelines/retrieval.py
482 483 484 485 486 487 488 489 490 491 |
|
delete_memory(hrid, user_id, memory_type=None)
Delete memory using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID of the memory to delete. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False otherwise. |
Source code in src/memg_core/api/public.py
317 318 319 320 321 322 323 324 325 326 327 328 |
|
delete_relationship(from_memory_hrid, to_memory_hrid, relation_type, from_memory_type=None, to_memory_type=None, user_id=None)
Delete relationship using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_memory_hrid
|
str
|
Source memory HRID. |
required |
to_memory_hrid
|
str
|
Target memory HRID. |
required |
relation_type
|
str
|
Relationship type from YAML schema. |
required |
from_memory_type
|
str | None
|
Source memory entity type (inferred from HRID if not provided). |
None
|
to_memory_type
|
str | None
|
Target memory entity type (inferred from HRID if not provided). |
None
|
user_id
|
str | None
|
User ID for ownership verification (required). |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False if relationship not found. |
Source code in src/memg_core/api/public.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
get_memories(user_id, memory_type=None, filters=None, limit=50, offset=0, include_neighbors=False, hops=1)
Get memories using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type filter (e.g., "task", "note"). |
None
|
filters
|
dict[str, Any] | None
|
Optional field filters (e.g., {"status": "open", "priority": "high"}). |
None
|
limit
|
int
|
Maximum number of memories to return (default 50). |
50
|
offset
|
int
|
Number of memories to skip for pagination (default 0). |
0
|
include_neighbors
|
bool
|
Whether to include neighbor nodes via graph traversal. |
False
|
hops
|
int
|
Number of hops for neighbor expansion (default 1). |
1
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of memory data with full payloads. |
Source code in src/memg_core/api/public.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
get_memory(hrid, user_id, memory_type=None)
Get memory using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable identifier of the memory. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Memory data with full payload, or None if not found. |
Source code in src/memg_core/api/public.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
get_services()
Get services from singleton client (MCP server compatibility).
Returns:
Type | Description |
---|---|
tuple[MemoryService, SearchService, YamlTranslator]
|
tuple[MemoryService, SearchService, YamlTranslator]: Service instances for direct access. |
Source code in src/memg_core/api/public.py
471 472 473 474 475 476 477 478 479 |
|
search(query, user_id, memory_type=None, limit=10, score_threshold=None, decay_threshold=None, **kwargs)
Search memories using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to search for. |
required |
user_id
|
str
|
User ID for filtering results. |
required |
memory_type
|
str | None
|
Optional memory type filter. |
None
|
limit
|
int
|
Maximum number of results to return. |
10
|
score_threshold
|
float | None
|
Minimum similarity score threshold (0.0-1.0). |
None
|
decay_threshold
|
float | None
|
Minimum neighbor relevance threshold (0.0-1.0). |
None
|
**kwargs
|
Additional search parameters. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
SearchResult |
SearchResult
|
Search result with explicit seed/neighbor separation, including full payloads for seeds and relationships. |
Source code in src/memg_core/api/public.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
shutdown_services()
Shutdown singleton client.
Closes database connections and cleans up resources.
Source code in src/memg_core/api/public.py
459 460 461 462 463 464 465 466 467 |
|
update_memory(hrid, payload_updates, user_id, memory_type=None)
Update memory using environment-based client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Memory HRID to update. |
required |
payload_updates
|
dict[str, Any]
|
Dictionary of fields to update (only changed fields). |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
memory_type
|
str | None
|
Optional memory type hint (inferred from HRID if not provided). |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if update succeeded, False otherwise. |
Source code in src/memg_core/api/public.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
Core Models
Core data models and types:
Core models for the memory system.
_MAX_SCORE_TOLERANCE = 1.001
module-attribute
Memory
Bases: BaseModel
Core memory model with YAML-driven payload validation.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
Unique identifier (UUID or HRID). |
user_id |
str
|
Owner of the memory. |
memory_type |
str
|
Entity type from YAML schema. |
payload |
dict[str, Any]
|
Entity-specific fields. |
vector |
list[float] | None
|
Embedding vector. |
created_at |
datetime
|
Creation timestamp. |
updated_at |
datetime | None
|
Last update timestamp. |
hrid |
str | None
|
Human-readable identifier. |
Source code in src/memg_core/core/models.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
__getattr__(item)
Dynamic attribute access for YAML-defined payload fields ONLY.
No fallback logic, no backward compatibility. If the field is not in the payload dictionary, raises AttributeError immediately. This enforces strict YAML schema compliance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item
|
str
|
Field name to access. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Field value from payload. |
Raises:
Type | Description |
---|---|
AttributeError
|
If field is not in payload. |
Source code in src/memg_core/core/models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
memory_type_not_empty(v)
classmethod
Validate that memory_type is not empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
str
|
Memory type value. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Stripped memory type. |
Raises:
Type | Description |
---|---|
ValueError
|
If memory_type is empty or whitespace. |
Source code in src/memg_core/core/models.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
to_entity_model()
Project this Memory into a dynamic Pydantic entity model.
Returns an instance of the auto-generated model class that matches the entity type defined in the YAML schema. Only non-system fields are included.
Returns:
Name | Type | Description |
---|---|---|
BaseModel |
Dynamic Pydantic model instance. |
Source code in src/memg_core/core/models.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
to_kuzu_node()
Export a minimal node for Kuzu, containing only core fields.
NO hardcoded fields - only system fields stored in graph.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Node data for Kuzu storage. |
Source code in src/memg_core/core/models.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
to_qdrant_payload()
DEPRECATED: Serializes to a strict {'core': ..., 'entity': ...} structure.
This method is deprecated and will be removed in a future version. The current implementation uses flat payload structure directly in MemoryStore.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Deprecated payload structure. |
Source code in src/memg_core/core/models.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
MemoryNeighbor
Bases: BaseModel
Memory neighbor with anchor-only payload.
Attributes:
Name | Type | Description |
---|---|---|
hrid |
str
|
Human-readable identifier. |
memory_type |
str
|
Entity type from YAML schema. |
payload |
dict[str, Any]
|
Anchor-only payload (statement field only). |
Source code in src/memg_core/core/models.py
262 263 264 265 266 267 268 269 270 271 272 273 |
|
MemoryPoint
Bases: BaseModel
Memory with embedding vector for Qdrant.
Attributes:
Name | Type | Description |
---|---|---|
memory |
Memory
|
Memory instance. |
vector |
list[float]
|
Embedding vector. |
point_id |
str | None
|
Qdrant point ID. |
Source code in src/memg_core/core/models.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
vector_not_empty(v)
classmethod
Validate that vector is not empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
Vector to validate. |
required |
Returns:
Type | Description |
---|---|
list[float]: Validated vector. |
Raises:
Type | Description |
---|---|
ValueError
|
If vector is empty. |
Source code in src/memg_core/core/models.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
MemorySeed
Bases: BaseModel
Memory seed with full payload and explicit relationships.
Attributes:
Name | Type | Description |
---|---|---|
hrid |
str
|
Human-readable identifier. |
memory_type |
str
|
Entity type from YAML schema. |
payload |
dict[str, Any]
|
Full entity payload. |
score |
float
|
Vector similarity score to query. |
relationships |
list[RelationshipInfo]
|
List of relationships to other memories. |
Source code in src/memg_core/core/models.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
normalize_score(v)
classmethod
Normalize similarity scores to handle floating-point precision errors.
Source code in src/memg_core/core/models.py
251 252 253 254 255 256 257 258 259 |
|
ProcessingResult
Bases: BaseModel
Result from memory processing pipelines - type-agnostic.
Attributes:
Name | Type | Description |
---|---|---|
success |
bool
|
Whether processing succeeded. |
memories_created |
list[Memory]
|
List of created memories. |
errors |
list[str]
|
List of error messages. |
processing_time_ms |
float | None
|
Processing time in milliseconds. |
Source code in src/memg_core/core/models.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
total_created
property
Total memories created (all types).
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of memories created. |
RelationshipInfo
Bases: BaseModel
Relationship information between memories.
Attributes:
Name | Type | Description |
---|---|---|
relation_type |
str
|
Type of relationship (e.g., FIXES, ADDRESSES). |
target_hrid |
str
|
HRID of the target memory. |
scores |
dict[str, float]
|
Scoring information for the relationship. |
Source code in src/memg_core/core/models.py
216 217 218 219 220 221 222 223 224 225 226 227 |
|
SearchResult
Bases: BaseModel
Search result with explicit seed/neighbor separation.
Attributes:
Name | Type | Description |
---|---|---|
memories |
list[MemorySeed]
|
List of memory seeds with full payloads and relationships. |
neighbors |
list[MemoryNeighbor]
|
List of memory neighbors with anchor-only payloads. |
Source code in src/memg_core/core/models.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
get_entity_model(entity_name)
Get Pydantic model for entity from global registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of the entity. |
required |
Returns:
Type | Description |
---|---|
type[BaseModel]
|
type[BaseModel]: Pydantic model class. |
Source code in src/memg_core/core/types.py
421 422 423 424 425 426 427 428 429 430 |
|
Configuration
Configuration management:
Memory System Configuration - minimal and essential settings
DEFAULT_MEMG_CONFIG = MemGConfig()
module-attribute
DEFAULT_SYSTEM_CONFIG = MemorySystemConfig()
module-attribute
MemGConfig
dataclass
Core memory system configuration.
Attributes:
Name | Type | Description |
---|---|---|
similarity_threshold |
float
|
Threshold for conflict detection (0.0-1.0). |
score_threshold |
float
|
Minimum score for search results (0.0-1.0). |
high_similarity_threshold |
float
|
Threshold for duplicate detection (0.0-1.0). |
decay_rate |
float
|
Graph traversal decay rate per hop (0.0-1.0). |
decay_threshold |
float
|
Minimum neighbor relevance threshold (0.0-1.0). |
enable_ai_type_verification |
bool
|
Enable AI-based type detection. |
enable_temporal_reasoning |
bool
|
Enable temporal reasoning. |
vector_dimension |
int
|
Embedding dimension size. |
batch_processing_size |
int
|
Batch size for bulk operations. |
embedder_model |
str
|
FastEmbed model name. |
template_name |
str
|
Active template name. |
qdrant_collection_name |
str
|
Qdrant collection name. |
kuzu_database_path |
str
|
Kuzu database path. |
Source code in src/memg_core/core/config.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
__post_init__()
Validate configuration parameters.
Raises:
Type | Description |
---|---|
ValueError
|
If any threshold values are outside valid range [0.0, 1.0]. |
Source code in src/memg_core/core/config.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
from_dict(config_dict)
classmethod
Create configuration from dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_dict
|
dict[str, Any]
|
Dictionary containing configuration values. |
required |
Returns:
Name | Type | Description |
---|---|---|
MemGConfig |
MemGConfig
|
Configuration instance. |
Source code in src/memg_core/core/config.py
89 90 91 92 93 94 95 96 97 98 99 |
|
from_env()
classmethod
Create configuration from environment variables.
Each instance should use explicit environment variables for isolation. The core memory system doesn't know or care about server ports.
Returns:
Name | Type | Description |
---|---|---|
MemGConfig |
MemGConfig
|
Configuration instance with environment-derived values. |
Source code in src/memg_core/core/config.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
to_dict()
Convert configuration to dictionary.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Dictionary representation of configuration. |
Source code in src/memg_core/core/config.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
MemorySystemConfig
dataclass
Core memory system configuration - NO SERVER CONCERNS.
Attributes:
Name | Type | Description |
---|---|---|
memg |
MemGConfig
|
Core memory configuration instance. |
debug_mode |
bool
|
Enable debug mode. |
log_level |
str
|
Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL). |
Source code in src/memg_core/core/config.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
__post_init__()
Validate core system configuration.
Raises:
Type | Description |
---|---|
ValueError
|
If log_level is not a valid logging level. |
Source code in src/memg_core/core/config.py
146 147 148 149 150 151 152 153 |
|
from_env()
classmethod
Create core memory system configuration from environment variables.
Returns:
Name | Type | Description |
---|---|---|
MemorySystemConfig |
MemorySystemConfig
|
Configuration instance with environment-derived values. |
Source code in src/memg_core/core/config.py
155 156 157 158 159 160 161 162 163 164 165 166 |
|
get_config()
Get system configuration, preferring environment variables.
Returns:
Name | Type | Description |
---|---|---|
MemorySystemConfig |
MemorySystemConfig
|
System configuration instance. |
Source code in src/memg_core/core/config.py
174 175 176 177 178 179 180 |
|
Exceptions
Exception classes:
Custom exception hierarchy for the memory system - minimal set.
ConfigurationError
Bases: MemorySystemError
Configuration-related errors (env vars, validation).
Source code in src/memg_core/core/exceptions.py
38 39 |
|
DatabaseError
Bases: MemorySystemError
Database operation failures (Qdrant, Kuzu).
Source code in src/memg_core/core/exceptions.py
42 43 |
|
MemorySystemError
Bases: Exception
Base exception for all memory system errors.
Attributes:
Name | Type | Description |
---|---|---|
message |
Error message. |
|
operation |
Operation that caused the error. |
|
context |
Additional context information. |
|
original_error |
Original exception that was wrapped. |
Source code in src/memg_core/core/exceptions.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
ProcessingError
Bases: MemorySystemError
Memory processing operation failures (catch-all for processing).
Source code in src/memg_core/core/exceptions.py
50 51 |
|
ValidationError
Bases: MemorySystemError
Data validation failures (schema, input format).
Source code in src/memg_core/core/exceptions.py
46 47 |
|
handle_with_context(operation)
Decorator for consistent error handling with context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operation
|
str
|
Operation name for error context. |
required |
Returns:
Name | Type | Description |
---|---|---|
callable |
Decorated function with error handling. |
Source code in src/memg_core/core/exceptions.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
wrap_exception(original_error, operation, context=None)
Wrap a generic exception in an appropriate MemorySystemError subclass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_error
|
Exception
|
Original exception to wrap. |
required |
operation
|
str
|
Operation that caused the error. |
required |
context
|
dict[str, Any] | None
|
Additional context information. |
None
|
Returns:
Name | Type | Description |
---|---|---|
MemorySystemError |
MemorySystemError
|
Wrapped exception with appropriate subclass. |
Source code in src/memg_core/core/exceptions.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
YAML Schema
YAML schema handling:
YAML Translator: validates payloads using TypeRegistry and resolves anchor text.
STRICT YAML-FIRST: This module enforces the single-YAML-orchestrates-everything principle. NO flexibility, NO migration support, NO fallbacks.
Uses TypeRegistry as SINGLE SOURCE OF TRUTH for all entity definitions. All type building and validation delegated to TypeRegistry - zero redundancy.
Memory
Bases: BaseModel
Core memory model with YAML-driven payload validation.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
Unique identifier (UUID or HRID). |
user_id |
str
|
Owner of the memory. |
memory_type |
str
|
Entity type from YAML schema. |
payload |
dict[str, Any]
|
Entity-specific fields. |
vector |
list[float] | None
|
Embedding vector. |
created_at |
datetime
|
Creation timestamp. |
updated_at |
datetime | None
|
Last update timestamp. |
hrid |
str | None
|
Human-readable identifier. |
Source code in src/memg_core/core/models.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
__getattr__(item)
Dynamic attribute access for YAML-defined payload fields ONLY.
No fallback logic, no backward compatibility. If the field is not in the payload dictionary, raises AttributeError immediately. This enforces strict YAML schema compliance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item
|
str
|
Field name to access. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Field value from payload. |
Raises:
Type | Description |
---|---|
AttributeError
|
If field is not in payload. |
Source code in src/memg_core/core/models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
memory_type_not_empty(v)
classmethod
Validate that memory_type is not empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
str
|
Memory type value. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Stripped memory type. |
Raises:
Type | Description |
---|---|
ValueError
|
If memory_type is empty or whitespace. |
Source code in src/memg_core/core/models.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
to_entity_model()
Project this Memory into a dynamic Pydantic entity model.
Returns an instance of the auto-generated model class that matches the entity type defined in the YAML schema. Only non-system fields are included.
Returns:
Name | Type | Description |
---|---|---|
BaseModel |
Dynamic Pydantic model instance. |
Source code in src/memg_core/core/models.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
to_kuzu_node()
Export a minimal node for Kuzu, containing only core fields.
NO hardcoded fields - only system fields stored in graph.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Node data for Kuzu storage. |
Source code in src/memg_core/core/models.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
to_qdrant_payload()
DEPRECATED: Serializes to a strict {'core': ..., 'entity': ...} structure.
This method is deprecated and will be removed in a future version. The current implementation uses flat payload structure directly in MemoryStore.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Deprecated payload structure. |
Source code in src/memg_core/core/models.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
MemorySystemError
Bases: Exception
Base exception for all memory system errors.
Attributes:
Name | Type | Description |
---|---|---|
message |
Error message. |
|
operation |
Operation that caused the error. |
|
context |
Additional context information. |
|
original_error |
Original exception that was wrapped. |
Source code in src/memg_core/core/exceptions.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
YamlTranslator
Translates YAML schema definitions to Pydantic models for strict validation.
Attributes:
Name | Type | Description |
---|---|---|
yaml_path |
Path to YAML schema file. |
|
_schema |
dict[str, Any] | None
|
Cached schema dictionary. |
Source code in src/memg_core/core/yaml_translator.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
schema
property
Get the loaded YAML schema, loading it if necessary.
__init__(yaml_path=None)
Initialize YamlTranslator with YAML schema path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str | None
|
Path to YAML schema file. If None, uses MEMG_YAML_SCHEMA env var. |
None
|
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If YAML path not provided or TypeRegistry initialization fails. |
Source code in src/memg_core/core/yaml_translator.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
build_anchor_text(memory)
Build anchor text for embedding from YAML-defined anchor field.
NO hardcoded field names - reads anchor field from YAML schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory
|
Memory object containing payload data. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor text for embedding. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field is missing or invalid. |
Source code in src/memg_core/core/yaml_translator.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
create_memory_from_yaml(memory_type, payload, user_id)
Create a Memory object from YAML-validated payload.
Source code in src/memg_core/core/yaml_translator.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
|
debug_relation_map()
Return a nested relation map for debugging/printing.
Structure: { source: { target: [ {name, predicate, directed, description} ... ] } }
Source code in src/memg_core/core/yaml_translator.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
get_anchor_field(entity_name)
Get the anchor field name for the given entity type from YAML schema.
Now reads from vector.anchored_to instead of separate anchor field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of the entity type. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor field name. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field not found. |
Source code in src/memg_core/core/yaml_translator.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
get_entity_model(entity_name)
Get Pydantic model from TypeRegistry - NO REDUNDANCY.
Source code in src/memg_core/core/yaml_translator.py
619 620 621 |
|
get_entity_types()
Get list of available entity types from YAML schema.
Source code in src/memg_core/core/yaml_translator.py
123 124 125 |
|
get_labels_for_predicates(source_type, predicates, neighbor_label=None)
Expand predicate names to concrete relationship labels for a given source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_type
|
str
|
Source entity type name |
required |
predicates
|
list[str] | None
|
List of predicate names to include (case-insensitive). If None, include all. |
required |
neighbor_label
|
str | None
|
Optional target entity type filter (case-insensitive) |
None
|
Returns:
Type | Description |
---|---|
list[str]
|
List of concrete relationship labels (table names) matching the filter. |
Source code in src/memg_core/core/yaml_translator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
get_relations_for_source(entity_name)
Get normalized relation specs for a source entity in target-first schema.
Returns list of dicts with keys
- source (str)
- target (str)
- name (str | None)
- description (str | None)
- predicate (str)
- directed (bool)
Source code in src/memg_core/core/yaml_translator.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
get_see_also_config(entity_name)
Get the see_also configuration for the given entity type from YAML schema.
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
Dict with keys: enabled, threshold, limit, target_types |
dict[str, Any] | None
|
None if see_also is not configured for this entity |
Source code in src/memg_core/core/yaml_translator.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
relationship_table_name(source, predicate, target, *, directed=True)
staticmethod
Generate relationship table name.
For now, table name does not encode direction; direction affects creation/query semantics. Canonicalization for undirected pairs can be added here later if decided.
Source code in src/memg_core/core/yaml_translator.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
validate_memory_against_yaml(memory_type, payload)
Validate memory payload against YAML schema and return cleaned payload.
Source code in src/memg_core/core/yaml_translator.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
|
YamlTranslatorError
Bases: MemorySystemError
Error in YAML schema translation or validation.
Attributes:
Name | Type | Description |
---|---|---|
message |
Error message. |
|
operation |
Operation that caused the error. |
|
context |
Additional context information. |
|
original_error |
Original exception that was wrapped. |
Source code in src/memg_core/core/yaml_translator.py
23 24 25 26 27 28 29 30 31 |
|
get_entity_model(entity_name)
Get Pydantic model for entity from global registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of the entity. |
required |
Returns:
Type | Description |
---|---|
type[BaseModel]
|
type[BaseModel]: Pydantic model class. |
Source code in src/memg_core/core/types.py
421 422 423 424 425 426 427 428 429 430 |
|
initialize_types_from_yaml(yaml_path)
Initialize global type registry from YAML - call once at startup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str
|
Path to YAML schema file. |
required |
Source code in src/memg_core/core/types.py
457 458 459 460 461 462 463 |
|
Utilities
HRID Management
Human-readable ID utilities:
HRID generator and parser for MEMG Core.
Format: {TYPE_UPPER}_{AAA000} - TYPE: uppercase alphanumeric type name (no spaces) - AAA: base26 letters A–Z (wraps after ZZZ) - 000–999: numeric suffix
_COUNTERS = {}
module-attribute
_HRID_RE = re.compile('^(?P<type>[A-Z0-9_]+)_(?P<alpha>[A-Z]{3})(?P<num>\\d{3})$')
module-attribute
DatabaseError
Bases: MemorySystemError
Database operation failures (Qdrant, Kuzu).
Source code in src/memg_core/core/exceptions.py
42 43 |
|
StorageQueryInterface
Bases: Protocol
Protocol for storage backends that can query for existing HRIDs.
Attributes:
Name | Type | Description |
---|---|---|
vector |
Query embedding vector. |
|
limit |
Maximum number of results. |
|
collection |
Optional collection name. |
|
user_id |
User ID for filtering. |
|
filters |
Additional search filters. |
Source code in src/memg_core/utils/hrid.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
search_points(vector, limit=5, collection=None, user_id=None, filters=None)
Search for points with optional filtering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
list[float]
|
Query embedding vector. |
required |
limit
|
int
|
Maximum number of results. |
5
|
collection
|
str | None
|
Optional collection name. |
None
|
user_id
|
str | None
|
User ID for filtering. |
None
|
filters
|
dict[str, Any] | None
|
Additional search filters. |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of search results. |
Source code in src/memg_core/utils/hrid.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
_alpha_to_idx(alpha)
Convert alpha string to index: AAA -> 0, AAB -> 1, ..., ZZZ -> 17575.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
str
|
Three-letter alpha string (AAA-ZZZ). |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Numeric index. |
Source code in src/memg_core/utils/hrid.py
58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
_idx_to_alpha(idx)
Convert index to alpha string: 0 -> AAA, 1 -> AAB, ..., 17575 -> ZZZ.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx
|
int
|
Numeric index (0-17575). |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Three-letter alpha string. |
Source code in src/memg_core/utils/hrid.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
_initialize_counter_from_storage(type_name, user_id, storage=None)
Initialize counter by querying storage for highest existing HRID of this type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_name
|
str
|
The memory type to check (e.g., 'note', 'task') |
required |
user_id
|
str
|
User ID for scoped HRID lookup |
required |
storage
|
StorageQueryInterface | None
|
Storage interface to query for existing HRIDs |
None
|
Returns:
Type | Description |
---|---|
tuple[int, int]
|
tuple[int, int]: (alpha_idx, num) representing the next available counter position |
Notes
- If no storage provided or no existing HRIDs found, returns (0, -1) for fresh start
- Queries storage for memories of the given type and finds the highest HRID
- Parses the highest HRID to determine the next counter position
Source code in src/memg_core/utils/hrid.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
_initialize_counter_from_tracker(type_name, user_id, hrid_tracker)
Initialize counter by querying HridTracker for highest existing HRID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_name
|
str
|
The memory type to check (e.g., 'note', 'task') |
required |
user_id
|
str
|
User ID for scoped HRID lookup |
required |
hrid_tracker
|
HridTracker instance to query |
required |
Returns:
Type | Description |
---|---|
tuple[int, int]
|
tuple[int, int]: (alpha_idx, num) representing the next available counter position |
Source code in src/memg_core/utils/hrid.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
_type_key(t)
Deterministic numeric key for type names to enable cross-type ordering. Encodes up to the first 8 chars in base-37 (A–Z=1–26, 0–9=27–36).
Source code in src/memg_core/utils/hrid.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
generate_hrid(type_name, user_id, hrid_tracker=None)
Generate the next HRID for the given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_name
|
str
|
The memory type (e.g., 'note', 'task'). |
required |
user_id
|
str
|
User ID for scoped HRID generation. |
required |
hrid_tracker
|
Optional HridTracker instance for querying existing HRIDs. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The next HRID in format TYPE_AAA000. |
Notes
- Uses HridTracker to query HridMapping table for existing HRIDs.
- Falls back to in-memory counter if no tracker provided.
- Ensures no duplicates by checking complete HRID history.
Source code in src/memg_core/utils/hrid.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_logger(component)
Get a logger for a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
str
|
Component name. |
required |
Returns:
Type | Description |
---|---|
Logger
|
logging.Logger: Logger instance for the component. |
Source code in src/memg_core/core/logging.py
157 158 159 160 161 162 163 164 165 166 |
|
hrid_to_index(hrid)
Convert HRID into a single integer index for ordering across types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
HRID string to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Single integer index for cross-type ordering. |
Source code in src/memg_core/utils/hrid.py
296 297 298 299 300 301 302 303 304 305 306 307 |
|
parse_hrid(hrid)
Parse HRID into (type, alpha, num).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
HRID string to parse. |
required |
Returns:
Type | Description |
---|---|
tuple[str, str, int]
|
tuple[str, str, int]: (type, alpha, num) components. |
Raises:
Type | Description |
---|---|
ValueError
|
If HRID format is invalid. |
Source code in src/memg_core/utils/hrid.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
reset_counters()
Reset all in-memory HRID counters.
This is used for testing to simulate system restarts. In production, counters are automatically initialized from database.
Source code in src/memg_core/utils/hrid.py
310 311 312 313 314 315 316 317 |
|
HRID Tracker: UUID ↔ HRID translation and lifecycle management.
Handles all HRID mapping operations using the existing KuzuInterface. Provides transparent translation between user-facing HRIDs and internal UUIDs.
DatabaseError
Bases: MemorySystemError
Database operation failures (Qdrant, Kuzu).
Source code in src/memg_core/core/exceptions.py
42 43 |
|
HridTracker
Manages HRID ↔ UUID mappings using KuzuInterface.
Attributes:
Name | Type | Description |
---|---|---|
kuzu |
Pre-configured Kuzu interface for database operations. |
Source code in src/memg_core/utils/hrid_tracker.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
__init__(kuzu_interface)
Initialize with existing KuzuInterface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kuzu_interface
|
KuzuInterface
|
Pre-configured Kuzu interface for database operations. |
required |
Source code in src/memg_core/utils/hrid_tracker.py
23 24 25 26 27 28 29 |
|
create_mapping(hrid, uuid, memory_type, user_id)
Create new HRID ↔ UUID mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID. |
required |
uuid
|
str
|
Internal UUID. |
required |
memory_type
|
str
|
Entity type (e.g., 'task', 'note'). |
required |
user_id
|
str
|
User ID for scoped mapping. |
required |
Raises:
Type | Description |
---|---|
DatabaseError
|
If mapping creation fails. |
Source code in src/memg_core/utils/hrid_tracker.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
exists(hrid)
Check if HRID exists (active, not deleted).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if HRID exists and is active. |
Source code in src/memg_core/utils/hrid_tracker.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
get_highest_hrid(memory_type, user_id)
Get highest HRID for a memory type (for generation).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory_type
|
str
|
Entity type to check (case insensitive). |
required |
user_id
|
str
|
User ID for scoped HRID lookup. |
required |
Returns:
Type | Description |
---|---|
tuple[str, int, int] | None
|
tuple[str, int, int] | None: (hrid, alpha_idx, num) or None if no HRIDs exist. |
Source code in src/memg_core/utils/hrid_tracker.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
get_hrid(uuid, user_id)
Translate UUID to HRID with user verification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
str
|
Internal UUID. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Human-readable ID string. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If UUID not found, deleted, or doesn't belong to user. |
Source code in src/memg_core/utils/hrid_tracker.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
get_uuid(hrid, user_id)
Translate HRID to UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID (e.g., 'TASK_AAA001'). |
required |
user_id
|
str
|
User ID for scoped lookup. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
UUID string for internal operations. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If HRID not found or is deleted. |
Source code in src/memg_core/utils/hrid_tracker.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
mark_deleted(hrid)
Mark HRID mapping as deleted (soft delete)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
Human-readable ID to mark as deleted |
required |
Raises:
Type | Description |
---|---|
DatabaseError
|
If marking as deleted fails |
Source code in src/memg_core/utils/hrid_tracker.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
KuzuInterface
Pure CRUD wrapper around Kuzu database - NO DDL operations.
Attributes:
Name | Type | Description |
---|---|---|
conn |
Pre-initialized Kuzu connection. |
|
yaml_translator |
Optional YAML translator for relationship operations. |
Source code in src/memg_core/core/interfaces/kuzu.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
__init__(connection, yaml_translator=None)
Initialize with pre-created connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection
|
Connection
|
Pre-initialized Kuzu connection from DatabaseClients. |
required |
yaml_translator
|
Optional YamlTranslator for relationship operations. |
None
|
Source code in src/memg_core/core/interfaces/kuzu.py
20 21 22 23 24 25 26 27 28 |
|
add_node(table, properties)
Add a node to the graph - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Node table name. |
required |
properties
|
dict[str, Any]
|
Node properties. |
required |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node creation fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
add_relationship(from_table, to_table, rel_type, from_id, to_id, user_id, props=None)
Add relationship between nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_table
|
str
|
Source node table name. |
required |
to_table
|
str
|
Target node table name. |
required |
rel_type
|
str
|
Relationship type. |
required |
from_id
|
str
|
Source node ID. |
required |
to_id
|
str
|
Target node ID. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
props
|
dict[str, Any] | None
|
Optional relationship properties. |
None
|
Raises:
Type | Description |
---|---|
DatabaseError
|
If relationship creation fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
delete_node(table, node_uuid, user_id)
Delete a single node by UUID
Source code in src/memg_core/core/interfaces/kuzu.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
delete_relationship(from_table, to_table, rel_type, from_id, to_id, user_id)
Delete relationship between nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_table
|
str
|
Source node table name. |
required |
to_table
|
str
|
Target node table name. |
required |
rel_type
|
str
|
Relationship type. |
required |
from_id
|
str
|
Source node ID. |
required |
to_id
|
str
|
Target node ID. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False if relationship not found. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If relationship deletion fails due to system error. |
Source code in src/memg_core/core/interfaces/kuzu.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
get_nodes(user_id, node_type=None, filters=None, limit=50, offset=0)
Get multiple nodes with filtering and pagination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
User ID for ownership verification. |
required |
node_type
|
str | None
|
Optional node type filter (e.g., "task", "note"). |
None
|
filters
|
dict[str, Any] | None
|
Optional field filters (e.g., {"status": "open"}). |
None
|
limit
|
int
|
Maximum number of nodes to return. |
50
|
offset
|
int
|
Number of nodes to skip for pagination. |
0
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of node data from Kuzu. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node retrieval fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
neighbors(node_label, node_uuid, user_id, rel_types=None, direction='any', limit=10, neighbor_label=None)
Fetch neighbors of a node by UUID only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_label
|
str
|
Node type/table name (e.g., "Memory", "bug") - NOT a UUID. |
required |
node_uuid
|
str
|
UUID of the specific node to find neighbors for. |
required |
user_id
|
str
|
User ID for isolation - only return neighbors belonging to this user. |
required |
rel_types
|
list[str] | None
|
List of relationship types to filter by. |
None
|
direction
|
str
|
"in", "out", or "any" for relationship direction. |
'any'
|
limit
|
int
|
Maximum number of neighbors to return. |
10
|
neighbor_label
|
str | None
|
Type of neighbor nodes to return. |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of neighbor nodes with relationship info. |
Raises:
Type | Description |
---|---|
ValueError
|
If node_label is a UUID or node_uuid is not a UUID. |
DatabaseError
|
If neighbor query fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
query(cypher, params=None)
Execute Cypher query and return results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cypher
|
str
|
Cypher query string. |
required |
params
|
dict[str, Any] | None
|
Query parameters. |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: Query results. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If query execution fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
update_node(table, node_uuid, properties, user_id)
Update a node in the graph - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Node table name. |
required |
node_uuid
|
str
|
UUID of the node to update. |
required |
properties
|
dict[str, Any]
|
Node properties to update. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if update succeeded, False if node not found. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node update fails due to system error. |
Source code in src/memg_core/core/interfaces/kuzu.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
_alpha_to_idx(alpha)
Convert alpha string to index: AAA -> 0, AAB -> 1, ..., ZZZ -> 17575.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
str
|
Three-letter alpha string (AAA-ZZZ). |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Numeric index. |
Source code in src/memg_core/utils/hrid.py
58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
parse_hrid(hrid)
Parse HRID into (type, alpha, num).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hrid
|
str
|
HRID string to parse. |
required |
Returns:
Type | Description |
---|---|
tuple[str, str, int]
|
tuple[str, str, int]: (type, alpha, num) components. |
Raises:
Type | Description |
---|---|
ValueError
|
If HRID format is invalid. |
Source code in src/memg_core/utils/hrid.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
Database Clients
Database client utilities:
Database client management - thin layer for explicit database setup.
User controls database paths. No fallbacks. No automation.
DatabaseClients
DDL-only database setup - creates schemas and returns raw clients.
NO INTERFACES - pure schema creation only. Consumer must create interfaces separately using returned raw clients.
Attributes:
Name | Type | Description |
---|---|---|
qdrant_client |
QdrantClient | None
|
Pre-initialized QdrantClient. |
kuzu_connection |
Connection | None
|
Pre-initialized Kuzu connection. |
db_name |
Database name. |
|
qdrant_path |
Path to Qdrant database. |
|
kuzu_path |
Path to Kuzu database. |
|
yaml_translator |
YAML translator instance. |
Source code in src/memg_core/utils/db_clients.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
__init__(yaml_path=None)
Create DDL-only database client wrapper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str | None
|
Path to YAML schema file. User must provide - no defaults. |
None
|
Source code in src/memg_core/utils/db_clients.py
40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
close()
Close all database connections and cleanup resources.
Should be called when database clients are no longer needed.
Source code in src/memg_core/utils/db_clients.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
get_embedder()
Get embedder instance.
Returns:
Name | Type | Description |
---|---|---|
Embedder |
Embedder
|
Instance for generating vectors. |
Source code in src/memg_core/utils/db_clients.py
182 183 184 185 186 187 188 |
|
get_kuzu_interface()
Get Kuzu interface using the initialized connection.
Returns:
Name | Type | Description |
---|---|---|
KuzuInterface |
KuzuInterface
|
Configured with the DDL-created connection. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If connection not initialized (call init_dbs first). |
Source code in src/memg_core/utils/db_clients.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
get_qdrant_interface()
Get Qdrant interface using the initialized client.
Returns:
Name | Type | Description |
---|---|---|
QdrantInterface |
QdrantInterface
|
Configured with the DDL-created client and collection. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If client not initialized (call init_dbs first). |
Source code in src/memg_core/utils/db_clients.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
get_yaml_translator()
Get the YAML translator used for schema operations.
Returns:
Name | Type | Description |
---|---|---|
YamlTranslator |
YamlTranslator
|
Instance used during DDL operations. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If YAML translator not initialized. |
Source code in src/memg_core/utils/db_clients.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
init_dbs(db_path, db_name)
Initialize databases with structured paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_path
|
str
|
Base database directory. |
required |
db_name
|
str
|
Database name (used for collection and file names). |
required |
Source code in src/memg_core/utils/db_clients.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
DatabaseError
Bases: MemorySystemError
Database operation failures (Qdrant, Kuzu).
Source code in src/memg_core/core/exceptions.py
42 43 |
|
Embedder
Local embedder using FastEmbed - no API keys required.
Attributes:
Name | Type | Description |
---|---|---|
model_name |
Name of the embedding model being used. |
|
model |
FastEmbed TextEmbedding instance. |
Source code in src/memg_core/core/interfaces/embedder.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
__init__(model_name=None)
Initialize the FastEmbed embedder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str | None
|
Model to use. Defaults to config or snowflake-arctic-embed-xs. |
None
|
Source code in src/memg_core/core/interfaces/embedder.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
get_embedding(text)
Get embedding for a single text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Text to embed. |
required |
Returns:
Type | Description |
---|---|
list[float]
|
list[float]: Embedding vector. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If FastEmbed returns empty embedding. |
Source code in src/memg_core/core/interfaces/embedder.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_embeddings(texts)
Get embeddings for multiple texts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
list[str]
|
List of texts to embed. |
required |
Returns:
Type | Description |
---|---|
list[list[float]]
|
list[list[float]]: List of embedding vectors. |
Source code in src/memg_core/core/interfaces/embedder.py
53 54 55 56 57 58 59 60 61 62 63 |
|
GraphRegister
Generates DDL statements for graph databases using TypeRegistry.
Database-agnostic design - generates DDL that can be adapted for: - Kuzu (current) - Neo4j (future) - ArangoDB (future) - Any graph database with node/relationship tables
Source code in src/memg_core/utils/graph_register.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
__init__(type_registry=None, yaml_translator=None)
Initialize GraphRegister with TypeRegistry and YamlTranslator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_registry
|
TypeRegistry | None
|
TypeRegistry instance. If None, uses global singleton. |
None
|
yaml_translator
|
YamlTranslator | None
|
YamlTranslator for accessing full YAML schema. Optional. |
None
|
Source code in src/memg_core/utils/graph_register.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
generate_all_ddl()
Generate all DDL statements for complete schema setup.
Returns:
Type | Description |
---|---|
list[str]
|
List of all DDL statements needed for schema creation |
Source code in src/memg_core/utils/graph_register.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
generate_all_entity_tables_ddl()
Generate DDL for all entity tables from TypeRegistry.
Returns:
Type | Description |
---|---|
list[str]
|
List of DDL strings, one per entity table |
Source code in src/memg_core/utils/graph_register.py
110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
generate_entity_table_ddl(entity_name)
Generate DDL for a single entity table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of entity type (e.g., 'task', 'bug') |
required |
Returns:
Type | Description |
---|---|
str
|
DDL string for creating the entity table |
Raises:
Type | Description |
---|---|
DatabaseError
|
If entity not found in TypeRegistry |
Source code in src/memg_core/utils/graph_register.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
generate_hrid_mapping_table_ddl()
Generate DDL for HRID mapping table (system table).
Returns:
Type | Description |
---|---|
str
|
DDL string for HRID mapping table |
Source code in src/memg_core/utils/graph_register.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
generate_relationship_tables_ddl()
Generate DDL for relationship tables from YAML schema using YamlTranslator.
Uses YamlTranslator to discover relations and centralized table naming. Handles directed/undirected semantics for table creation.
Returns:
Type | Description |
---|---|
list[str]
|
List of DDL strings for relationship tables |
Raises:
Type | Description |
---|---|
DatabaseError
|
If YamlTranslator not provided or schema access fails |
Source code in src/memg_core/utils/graph_register.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
KuzuInterface
Pure CRUD wrapper around Kuzu database - NO DDL operations.
Attributes:
Name | Type | Description |
---|---|---|
conn |
Pre-initialized Kuzu connection. |
|
yaml_translator |
Optional YAML translator for relationship operations. |
Source code in src/memg_core/core/interfaces/kuzu.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
__init__(connection, yaml_translator=None)
Initialize with pre-created connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection
|
Connection
|
Pre-initialized Kuzu connection from DatabaseClients. |
required |
yaml_translator
|
Optional YamlTranslator for relationship operations. |
None
|
Source code in src/memg_core/core/interfaces/kuzu.py
20 21 22 23 24 25 26 27 28 |
|
add_node(table, properties)
Add a node to the graph - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Node table name. |
required |
properties
|
dict[str, Any]
|
Node properties. |
required |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node creation fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
add_relationship(from_table, to_table, rel_type, from_id, to_id, user_id, props=None)
Add relationship between nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_table
|
str
|
Source node table name. |
required |
to_table
|
str
|
Target node table name. |
required |
rel_type
|
str
|
Relationship type. |
required |
from_id
|
str
|
Source node ID. |
required |
to_id
|
str
|
Target node ID. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
props
|
dict[str, Any] | None
|
Optional relationship properties. |
None
|
Raises:
Type | Description |
---|---|
DatabaseError
|
If relationship creation fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
delete_node(table, node_uuid, user_id)
Delete a single node by UUID
Source code in src/memg_core/core/interfaces/kuzu.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
delete_relationship(from_table, to_table, rel_type, from_id, to_id, user_id)
Delete relationship between nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_table
|
str
|
Source node table name. |
required |
to_table
|
str
|
Target node table name. |
required |
rel_type
|
str
|
Relationship type. |
required |
from_id
|
str
|
Source node ID. |
required |
to_id
|
str
|
Target node ID. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded, False if relationship not found. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If relationship deletion fails due to system error. |
Source code in src/memg_core/core/interfaces/kuzu.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
get_nodes(user_id, node_type=None, filters=None, limit=50, offset=0)
Get multiple nodes with filtering and pagination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
User ID for ownership verification. |
required |
node_type
|
str | None
|
Optional node type filter (e.g., "task", "note"). |
None
|
filters
|
dict[str, Any] | None
|
Optional field filters (e.g., {"status": "open"}). |
None
|
limit
|
int
|
Maximum number of nodes to return. |
50
|
offset
|
int
|
Number of nodes to skip for pagination. |
0
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of node data from Kuzu. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node retrieval fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
neighbors(node_label, node_uuid, user_id, rel_types=None, direction='any', limit=10, neighbor_label=None)
Fetch neighbors of a node by UUID only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_label
|
str
|
Node type/table name (e.g., "Memory", "bug") - NOT a UUID. |
required |
node_uuid
|
str
|
UUID of the specific node to find neighbors for. |
required |
user_id
|
str
|
User ID for isolation - only return neighbors belonging to this user. |
required |
rel_types
|
list[str] | None
|
List of relationship types to filter by. |
None
|
direction
|
str
|
"in", "out", or "any" for relationship direction. |
'any'
|
limit
|
int
|
Maximum number of neighbors to return. |
10
|
neighbor_label
|
str | None
|
Type of neighbor nodes to return. |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of neighbor nodes with relationship info. |
Raises:
Type | Description |
---|---|
ValueError
|
If node_label is a UUID or node_uuid is not a UUID. |
DatabaseError
|
If neighbor query fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
query(cypher, params=None)
Execute Cypher query and return results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cypher
|
str
|
Cypher query string. |
required |
params
|
dict[str, Any] | None
|
Query parameters. |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: Query results. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If query execution fails. |
Source code in src/memg_core/core/interfaces/kuzu.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
update_node(table, node_uuid, properties, user_id)
Update a node in the graph - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table
|
str
|
Node table name. |
required |
node_uuid
|
str
|
UUID of the node to update. |
required |
properties
|
dict[str, Any]
|
Node properties to update. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if update succeeded, False if node not found. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If node update fails due to system error. |
Source code in src/memg_core/core/interfaces/kuzu.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
QdrantInterface
Pure CRUD wrapper around QdrantClient - NO DDL operations.
Attributes:
Name | Type | Description |
---|---|---|
client |
Pre-initialized QdrantClient. |
|
collection_name |
Name of the Qdrant collection. |
Source code in src/memg_core/core/interfaces/qdrant.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__init__(client, collection_name)
Initialize with pre-created client and collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
QdrantClient
|
Pre-initialized QdrantClient from DatabaseClients. |
required |
collection_name
|
str
|
Name of pre-created collection. |
required |
Source code in src/memg_core/core/interfaces/qdrant.py
28 29 30 31 32 33 34 35 36 |
|
add_point(vector, payload, point_id=None, collection=None)
Add a single point to collection - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
list[float]
|
Embedding vector. |
required |
payload
|
dict[str, Any]
|
Point payload data. |
required |
point_id
|
str | None
|
Optional point ID (auto-generated if None). |
None
|
collection
|
str | None
|
Optional collection name override. |
None
|
Returns:
Type | Description |
---|---|
tuple[bool, str]
|
tuple[bool, str]: (success, point_id) where success indicates if operation succeeded. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If point addition fails. |
Source code in src/memg_core/core/interfaces/qdrant.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
delete_points(point_ids, user_id, collection=None)
Delete points by IDs with user ownership verification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_ids
|
list[str]
|
List of point IDs to delete. |
required |
user_id
|
str
|
User ID for ownership verification. |
required |
collection
|
str | None
|
Optional collection name override. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if deletion succeeded. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If points not found or don't belong to user, or deletion fails. |
Source code in src/memg_core/core/interfaces/qdrant.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
get_collection_info(collection=None)
Get collection information - pure read operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection
|
str | None
|
Optional collection name override. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: Collection information including existence, vector count, point count, and config. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If collection info retrieval fails. |
Source code in src/memg_core/core/interfaces/qdrant.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
get_point(point_id, collection=None)
Get a single point by ID - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_id
|
str
|
ID of the point to retrieve. |
required |
collection
|
str | None
|
Optional collection name override. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Point data including id, vector, and payload, or None if not found. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If retrieval fails. |
Source code in src/memg_core/core/interfaces/qdrant.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
search_points(vector, limit=5, collection=None, filters=None, score_threshold=None)
Search for similar points with mandatory user isolation - pure CRUD operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector
|
list[float]
|
Query embedding vector. |
required |
limit
|
int
|
Maximum number of results. |
5
|
collection
|
str | None
|
Optional collection name override. |
None
|
filters
|
dict[str, Any] | None
|
Search filters (must include user_id for security). |
None
|
score_threshold
|
float | None
|
Minimum similarity score threshold (0.0-1.0). |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of search results with id, score, and payload. |
Raises:
Type | Description |
---|---|
DatabaseError
|
If search fails or user_id is missing from filters. |
Source code in src/memg_core/core/interfaces/qdrant.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
YamlTranslator
Translates YAML schema definitions to Pydantic models for strict validation.
Attributes:
Name | Type | Description |
---|---|---|
yaml_path |
Path to YAML schema file. |
|
_schema |
dict[str, Any] | None
|
Cached schema dictionary. |
Source code in src/memg_core/core/yaml_translator.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
schema
property
Get the loaded YAML schema, loading it if necessary.
__init__(yaml_path=None)
Initialize YamlTranslator with YAML schema path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
str | None
|
Path to YAML schema file. If None, uses MEMG_YAML_SCHEMA env var. |
None
|
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If YAML path not provided or TypeRegistry initialization fails. |
Source code in src/memg_core/core/yaml_translator.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
build_anchor_text(memory)
Build anchor text for embedding from YAML-defined anchor field.
NO hardcoded field names - reads anchor field from YAML schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory
|
Memory object containing payload data. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor text for embedding. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field is missing or invalid. |
Source code in src/memg_core/core/yaml_translator.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
create_memory_from_yaml(memory_type, payload, user_id)
Create a Memory object from YAML-validated payload.
Source code in src/memg_core/core/yaml_translator.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
|
debug_relation_map()
Return a nested relation map for debugging/printing.
Structure: { source: { target: [ {name, predicate, directed, description} ... ] } }
Source code in src/memg_core/core/yaml_translator.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
get_anchor_field(entity_name)
Get the anchor field name for the given entity type from YAML schema.
Now reads from vector.anchored_to instead of separate anchor field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_name
|
str
|
Name of the entity type. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Anchor field name. |
Raises:
Type | Description |
---|---|
YamlTranslatorError
|
If anchor field not found. |
Source code in src/memg_core/core/yaml_translator.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
get_entity_model(entity_name)
Get Pydantic model from TypeRegistry - NO REDUNDANCY.
Source code in src/memg_core/core/yaml_translator.py
619 620 621 |
|
get_entity_types()
Get list of available entity types from YAML schema.
Source code in src/memg_core/core/yaml_translator.py
123 124 125 |
|
get_labels_for_predicates(source_type, predicates, neighbor_label=None)
Expand predicate names to concrete relationship labels for a given source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_type
|
str
|
Source entity type name |
required |
predicates
|
list[str] | None
|
List of predicate names to include (case-insensitive). If None, include all. |
required |
neighbor_label
|
str | None
|
Optional target entity type filter (case-insensitive) |
None
|
Returns:
Type | Description |
---|---|
list[str]
|
List of concrete relationship labels (table names) matching the filter. |
Source code in src/memg_core/core/yaml_translator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
get_relations_for_source(entity_name)
Get normalized relation specs for a source entity in target-first schema.
Returns list of dicts with keys
- source (str)
- target (str)
- name (str | None)
- description (str | None)
- predicate (str)
- directed (bool)
Source code in src/memg_core/core/yaml_translator.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
get_see_also_config(entity_name)
Get the see_also configuration for the given entity type from YAML schema.
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
Dict with keys: enabled, threshold, limit, target_types |
dict[str, Any] | None
|
None if see_also is not configured for this entity |
Source code in src/memg_core/core/yaml_translator.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
relationship_table_name(source, predicate, target, *, directed=True)
staticmethod
Generate relationship table name.
For now, table name does not encode direction; direction affects creation/query semantics. Canonicalization for undirected pairs can be added here later if decided.
Source code in src/memg_core/core/yaml_translator.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
validate_memory_against_yaml(memory_type, payload)
Validate memory payload against YAML schema and return cleaned payload.
Source code in src/memg_core/core/yaml_translator.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
|
get_config()
Get system configuration, preferring environment variables.
Returns:
Name | Type | Description |
---|---|---|
MemorySystemConfig |
MemorySystemConfig
|
System configuration instance. |
Source code in src/memg_core/core/config.py
174 175 176 177 178 179 180 |
|