mem-llm 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mem-llm might be problematic. Click here for more details.

mem_llm/mem_agent.py CHANGED
@@ -64,6 +64,7 @@ class MemAgent:
64
64
  config_file: Optional[str] = None,
65
65
  use_sql: bool = True,
66
66
  memory_dir: Optional[str] = None,
67
+ db_path: Optional[str] = None,
67
68
  load_knowledge_base: bool = True,
68
69
  ollama_url: str = "http://localhost:11434",
69
70
  check_connection: bool = False,
@@ -73,7 +74,8 @@ class MemAgent:
73
74
  model: LLM model to use
74
75
  config_file: Configuration file (optional)
75
76
  use_sql: Use SQL database (True) or JSON (False)
76
- memory_dir: Memory directory
77
+ memory_dir: Memory directory (for JSON mode or if db_path not specified)
78
+ db_path: SQLite database path (for SQL mode, e.g., ":memory:" or "path/to/db.db")
77
79
  load_knowledge_base: Automatically load knowledge base
78
80
  ollama_url: Ollama API URL
79
81
  check_connection: Verify Ollama connection on startup (default: False)
@@ -120,12 +122,29 @@ class MemAgent:
120
122
  self.has_knowledge_base: bool = False # Track KB status
121
123
  self.has_tools: bool = False # Track tools status
122
124
 
123
- # Memory system selection
125
+ # Memory system
124
126
  if use_sql and ADVANCED_AVAILABLE:
125
127
  # SQL memory (advanced)
126
- db_path = memory_dir or self.config.get("memory.db_path", "memories.db") if self.config else "memories.db"
127
- self.memory = SQLMemoryManager(db_path)
128
- self.logger.info(f"SQL memory system active: {db_path}")
128
+ # Determine database path
129
+ if db_path:
130
+ # Use provided db_path (can be ":memory:" for in-memory DB)
131
+ final_db_path = db_path
132
+ elif memory_dir:
133
+ final_db_path = memory_dir
134
+ elif self.config:
135
+ final_db_path = self.config.get("memory.db_path", "memories/memories.db")
136
+ else:
137
+ final_db_path = "memories/memories.db"
138
+
139
+ # Ensure memories directory exists (skip for :memory:)
140
+ import os
141
+ if final_db_path != ":memory:":
142
+ db_dir = os.path.dirname(final_db_path)
143
+ if db_dir and not os.path.exists(db_dir):
144
+ os.makedirs(db_dir, exist_ok=True)
145
+
146
+ self.memory = SQLMemoryManager(final_db_path)
147
+ self.logger.info(f"SQL memory system active: {final_db_path}")
129
148
  else:
130
149
  # JSON memory (simple)
131
150
  json_dir = memory_dir or self.config.get("memory.json_dir", "memories") if self.config else "memories"
@@ -203,10 +222,13 @@ class MemAgent:
203
222
  if ADVANCED_AVAILABLE and hasattr(self, 'config') and self.config:
204
223
  log_config = self.config.get("logging", {})
205
224
 
225
+ # Default to WARNING level to keep console clean (users can override in config)
226
+ default_level = "WARNING"
227
+
206
228
  if log_config.get("enabled", True):
207
229
  # Only console logging (no file) - keep workspace clean
208
230
  logging.basicConfig(
209
- level=getattr(logging, log_config.get("level", "INFO")),
231
+ level=getattr(logging, log_config.get("level", default_level)),
210
232
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
211
233
  handlers=[
212
234
  logging.StreamHandler() # Console only
@@ -214,6 +236,9 @@ class MemAgent:
214
236
  )
215
237
 
216
238
  self.logger = logging.getLogger("MemAgent")
239
+
240
+ # Set default level for mem_llm loggers
241
+ logging.getLogger("mem_llm").setLevel(getattr(logging, log_config.get("level", default_level)))
217
242
 
218
243
  def _setup_advanced_features(self, load_knowledge_base: bool) -> None:
219
244
  """Setup advanced features"""
mem_llm/memory_db.py CHANGED
@@ -14,12 +14,18 @@ from pathlib import Path
14
14
  class SQLMemoryManager:
15
15
  """SQLite-based memory management system with thread-safety"""
16
16
 
17
- def __init__(self, db_path: str = "memories.db"):
17
+ def __init__(self, db_path: str = "memories/memories.db"):
18
18
  """
19
19
  Args:
20
20
  db_path: SQLite database file path
21
21
  """
22
22
  self.db_path = Path(db_path)
23
+
24
+ # Ensure directory exists
25
+ db_dir = self.db_path.parent
26
+ if not db_dir.exists():
27
+ db_dir.mkdir(parents=True, exist_ok=True)
28
+
23
29
  self.conn = None
24
30
  self._lock = threading.RLock() # Reentrant lock for thread safety
25
31
  self._init_database()
mem_llm/thread_safe_db.py CHANGED
@@ -124,7 +124,7 @@ class ConnectionPool:
124
124
  class ThreadSafeSQLMemory:
125
125
  """Thread-safe wrapper for SQL memory operations"""
126
126
 
127
- def __init__(self, db_path: str = "memories.db", pool_size: int = 5):
127
+ def __init__(self, db_path: str = "memories/memories.db", pool_size: int = 5):
128
128
  """
129
129
  Initialize thread-safe SQL memory
130
130
 
@@ -133,6 +133,12 @@ class ThreadSafeSQLMemory:
133
133
  pool_size: Connection pool size
134
134
  """
135
135
  self.db_path = Path(db_path)
136
+
137
+ # Ensure directory exists
138
+ db_dir = self.db_path.parent
139
+ if not db_dir.exists():
140
+ db_dir.mkdir(parents=True, exist_ok=True)
141
+
136
142
  self.pool = ConnectionPool(str(db_path), pool_size)
137
143
  self.logger = logging.getLogger(__name__)
138
144
  self._init_database()
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mem-llm
3
- Version: 1.1.0
4
- Summary: Memory-enabled AI assistant with local LLM support - Now with security and performance improvements
3
+ Version: 1.2.0
4
+ Summary: Memory-enabled AI assistant with local LLM support - Now with data import/export and multi-database support
5
5
  Author-email: "C. Emre Karataş" <karatasqemre@gmail.com>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/emredeveloper/Mem-LLM
@@ -33,6 +33,24 @@ Requires-Dist: flask-cors>=4.0.0; extra == "web"
33
33
  Provides-Extra: api
34
34
  Requires-Dist: fastapi>=0.104.0; extra == "api"
35
35
  Requires-Dist: uvicorn>=0.24.0; extra == "api"
36
+ Provides-Extra: postgresql
37
+ Requires-Dist: psycopg2-binary>=2.9.9; extra == "postgresql"
38
+ Provides-Extra: mongodb
39
+ Requires-Dist: pymongo>=4.6.0; extra == "mongodb"
40
+ Provides-Extra: databases
41
+ Requires-Dist: psycopg2-binary>=2.9.9; extra == "databases"
42
+ Requires-Dist: pymongo>=4.6.0; extra == "databases"
43
+ Provides-Extra: all
44
+ Requires-Dist: pytest>=7.4.0; extra == "all"
45
+ Requires-Dist: pytest-cov>=4.1.0; extra == "all"
46
+ Requires-Dist: black>=23.7.0; extra == "all"
47
+ Requires-Dist: flake8>=6.1.0; extra == "all"
48
+ Requires-Dist: flask>=3.0.0; extra == "all"
49
+ Requires-Dist: flask-cors>=4.0.0; extra == "all"
50
+ Requires-Dist: fastapi>=0.104.0; extra == "all"
51
+ Requires-Dist: uvicorn>=0.24.0; extra == "all"
52
+ Requires-Dist: psycopg2-binary>=2.9.9; extra == "all"
53
+ Requires-Dist: pymongo>=4.6.0; extra == "all"
36
54
 
37
55
  # 🧠 Mem-LLM
38
56
 
@@ -44,16 +62,23 @@ Requires-Dist: uvicorn>=0.24.0; extra == "api"
44
62
 
45
63
  Mem-LLM is a powerful Python library that brings persistent memory capabilities to local Large Language Models. Build AI assistants that remember user interactions, manage knowledge bases, and work completely offline with Ollama.
46
64
 
47
- ## 🆕 What's New in v1.1.0
65
+ ## 🔗 Links
48
66
 
49
- - 🛡️ **Prompt Injection Protection**: Detects and blocks 15+ attack patterns (opt-in with `enable_security=True`)
50
- - **Thread-Safe Operations**: Fixed all race conditions, supports 200+ concurrent writes
51
- - 🔄 **Retry Logic**: Exponential backoff for network errors (3 retries: 1s, 2s, 4s)
52
- - 📝 **Structured Logging**: Production-ready logging with `MemLLMLogger`
53
- - 💾 **SQLite WAL Mode**: Write-Ahead Logging for better concurrency (15K+ msg/s)
54
- - ✅ **100% Backward Compatible**: All v1.0.x code works without changes
67
+ - **PyPI**: https://pypi.org/project/mem-llm/
68
+ - **GitHub**: https://github.com/emredeveloper/Mem-LLM
69
+ - **Issues**: https://github.com/emredeveloper/Mem-LLM/issues
70
+ - **Documentation**: See examples/ directory
55
71
 
56
- [See full changelog](CHANGELOG.md#110---2025-10-21)
72
+ ## 🆕 What's New in v1.2.0
73
+
74
+ - � **Conversation Summarization**: Automatic conversation compression (~40-60% token reduction)
75
+ - 📤 **Data Export/Import**: JSON, CSV, SQLite, PostgreSQL, MongoDB support
76
+ - 🗄️ **Multi-Database**: Enterprise-ready PostgreSQL & MongoDB integration
77
+ - �️ **In-Memory DB**: Use `:memory:` for temporary operations
78
+ - � **Cleaner Logs**: Default WARNING level for production-ready output
79
+ - � **Bug Fixes**: Database path handling, organized SQLite files
80
+
81
+ [See full changelog](CHANGELOG.md#120---2025-10-21)
57
82
 
58
83
  ## ✨ Key Features
59
84
 
@@ -70,15 +95,38 @@ Mem-LLM is a powerful Python library that brings persistent memory capabilities
70
95
  - 🛡️ **Prompt Injection Protection** (v1.1.0+) - Advanced security against prompt attacks (opt-in)
71
96
  - ⚡ **High Performance** (v1.1.0+) - Thread-safe operations, 15K+ msg/s throughput
72
97
  - 🔄 **Retry Logic** (v1.1.0+) - Automatic exponential backoff for network errors
98
+ - 📊 **Conversation Summarization** (v1.2.0+) - Automatic token compression (~40-60% reduction)
99
+ - 📤 **Data Export/Import** (v1.2.0+) - Multi-format support (JSON, CSV, SQLite, PostgreSQL, MongoDB)
73
100
 
74
101
  ## 🚀 Quick Start
75
102
 
76
103
  ### Installation
77
104
 
105
+ **Basic Installation:**
78
106
  ```bash
79
107
  pip install mem-llm
80
108
  ```
81
109
 
110
+ **With Optional Dependencies:**
111
+ ```bash
112
+ # PostgreSQL support
113
+ pip install mem-llm[postgresql]
114
+
115
+ # MongoDB support
116
+ pip install mem-llm[mongodb]
117
+
118
+ # All database support (PostgreSQL + MongoDB)
119
+ pip install mem-llm[databases]
120
+
121
+ # All optional features
122
+ pip install mem-llm[all]
123
+ ```
124
+
125
+ **Upgrade:**
126
+ ```bash
127
+ pip install -U mem-llm
128
+ ```
129
+
82
130
  ### Prerequisites
83
131
 
84
132
  Install and start [Ollama](https://ollama.ai):
@@ -391,33 +439,8 @@ stats = agent.get_memory_stats()
391
439
  - **MemoryTools**: Search, export, statistics
392
440
  - **ConfigManager**: YAML configuration
393
441
  - **CLI**: Command-line interface
394
-
395
- ## 🧪 Testing
396
-
397
- Run the comprehensive test suite:
398
-
399
- ```bash
400
- # Install dev dependencies
401
- pip install -r requirements-dev.txt
402
-
403
- # Run all tests (34+ automated tests)
404
- cd tests
405
- python run_all_tests.py
406
-
407
- # Run specific test
408
- python -m pytest test_mem_agent.py -v
409
- ```
410
-
411
- ### Test Coverage
412
- - ✅ Core imports and dependencies
413
- - ✅ CLI functionality
414
- - ✅ Ollama connection and models
415
- - ✅ JSON memory operations
416
- - ✅ SQL memory operations
417
- - ✅ MemAgent features
418
- - ✅ Configuration management
419
- - ✅ Multi-user scenarios
420
- - ✅ Hallucination detection
442
+ - **ConversationSummarizer**: Token compression (v1.2.0+)
443
+ - **DataExporter/DataImporter**: Multi-database support (v1.2.0+)
421
444
 
422
445
  ## 📝 Examples
423
446
 
@@ -430,53 +453,32 @@ The `examples/` directory contains ready-to-run demonstrations:
430
453
  5. **05_knowledge_base.py** - FAQ/support system
431
454
  6. **06_cli_demo.py** - Command-line interface examples
432
455
  7. **07_document_config.py** - Configuration from documents
456
+ 8. **08_conversation_summarization.py** - Token compression with auto-summary (v1.2.0+)
457
+ 9. **09_data_export_import.py** - Multi-format export/import demo (v1.2.0+)
458
+ 10. **10_database_connection_test.py** - Enterprise PostgreSQL/MongoDB migration (v1.2.0+)
433
459
 
434
- ## 🛠️ Development
435
-
436
- ### Setup Development Environment
437
-
438
- ```bash
439
- git clone https://github.com/emredeveloper/Mem-LLM.git
440
- cd Mem-LLM
441
- pip install -e .
442
- pip install -r requirements-dev.txt
443
- ```
444
-
445
- ### Running Tests
446
-
447
- ```bash
448
- pytest tests/ -v --cov=mem_llm
449
- ```
450
-
451
- ### Building Package
452
-
453
- ```bash
454
- python -m build
455
- twine upload dist/*
456
- ```
457
-
458
- ## 📋 Requirements
459
-
460
- ### Core Dependencies
461
- - Python 3.8+
462
- - requests>=2.31.0
463
- - pyyaml>=6.0.1
464
- - click>=8.1.0
465
-
466
- ### Optional Dependencies
467
- - pytest>=7.4.0 (for testing)
468
- - flask>=3.0.0 (for web interface)
469
- - fastapi>=0.104.0 (for API server)
460
+ ## 📊 Project Status
470
461
 
471
- ## 🤝 Contributing
462
+ - **Version**: 1.2.0
463
+ - **Status**: Production Ready
464
+ - **Last Updated**: October 21, 2025
465
+ - **Test Coverage**: 16/16 automated tests (100% success rate)
466
+ - **Performance**: Thread-safe operations, <1ms search latency
467
+ - **Databases**: SQLite, PostgreSQL, MongoDB, In-Memory
472
468
 
473
- Contributions are welcome! Please feel free to submit a Pull Request.
469
+ ## 📈 Roadmap
474
470
 
475
- 1. Fork the repository
476
- 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
477
- 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
478
- 4. Push to the branch (`git push origin feature/AmazingFeature`)
479
- 5. Open a Pull Request
471
+ - [x] ~~Thread-safe operations~~ (v1.1.0)
472
+ - [x] ~~Prompt injection protection~~ (v1.1.0)
473
+ - [x] ~~Structured logging~~ (v1.1.0)
474
+ - [x] ~~Retry logic~~ (v1.1.0)
475
+ - [x] ~~Conversation Summarization~~ (v1.2.0)
476
+ - [x] ~~Multi-Database Export/Import~~ (v1.2.0)
477
+ - [x] ~~In-Memory Database~~ (v1.2.0)
478
+ - [ ] Web UI dashboard
479
+ - [ ] REST API server
480
+ - [ ] Vector database integration
481
+ - [ ] Advanced analytics dashboard
480
482
 
481
483
  ## 📄 License
482
484
 
@@ -494,35 +496,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
494
496
  - Inspired by the need for privacy-focused AI assistants
495
497
  - Thanks to all contributors and users
496
498
 
497
- ## 📊 Project Status
498
-
499
- - **Version**: 1.1.0
500
- - **Status**: Production Ready
501
- - **Last Updated**: October 21, 2025
502
- - **Performance**: 15,346 msg/s write throughput, <1ms search latency
503
- - **Thread-Safe**: Supports 200+ concurrent operations
504
- - **Test Coverage**: 44+ automated tests (100% success rate)
505
-
506
- ## 🔗 Links
507
-
508
- - **PyPI**: https://pypi.org/project/mem-llm/
509
- - **GitHub**: https://github.com/emredeveloper/Mem-LLM
510
- - **Issues**: https://github.com/emredeveloper/Mem-LLM/issues
511
- - **Documentation**: See examples/ directory
512
-
513
- ## 📈 Roadmap
514
-
515
- - [x] ~~Thread-safe operations~~ (v1.1.0)
516
- - [x] ~~Prompt injection protection~~ (v1.1.0)
517
- - [x] ~~Structured logging~~ (v1.1.0)
518
- - [x] ~~Retry logic~~ (v1.1.0)
519
- - [ ] Web UI dashboard
520
- - [ ] REST API server
521
- - [ ] Vector database integration
522
- - [ ] Multi-language support
523
- - [ ] Cloud backup options
524
- - [ ] Advanced analytics
525
-
526
499
  ---
527
500
 
528
501
  **⭐ If you find this project useful, please give it a star on GitHub!**
@@ -1,21 +1,23 @@
1
- mem_llm/__init__.py,sha256=tOh6_NntQjk8QbEEDYEThOfGZTGwKQwgznWGWg0I6V4,1700
1
+ mem_llm/__init__.py,sha256=0ZWXpX9U5-gen1seDNqO8nFz3_D1bWZgO9EwerCiF64,2200
2
2
  mem_llm/cli.py,sha256=DiqQyBZknN8pVagY5jXH85_LZ6odVGopfpa-7DILNNE,8666
3
3
  mem_llm/config.yaml.example,sha256=lgmfaU5pxnIm4zYxwgCcgLSohNx1Jw6oh3Qk0Xoe2DE,917
4
4
  mem_llm/config_from_docs.py,sha256=YFhq1SWyK63C-TNMS73ncNHg8sJ-XGOf2idWVCjxFco,4974
5
- mem_llm/config_manager.py,sha256=8PIHs21jZWlI-eG9DgekjOvNxU3-U4xH7SbT8Gr-Z6M,7075
5
+ mem_llm/config_manager.py,sha256=is4m0ISBIfv4PInGjrpvhxy0A7p9_BQ_UoJeayaIT3A,7084
6
+ mem_llm/conversation_summarizer.py,sha256=yCG2pKrAJf7xjaG6DPXL0i9eesMZnnzjKTpuyLHMTPQ,12509
7
+ mem_llm/data_export_import.py,sha256=gQIdD0hBY23qcRvx139yE15RWHXPinL_EoRNY7iabj0,22592
6
8
  mem_llm/dynamic_prompt.py,sha256=8H99QVDRJSVtGb_o4sdEPnG1cJWuer3KiD-nuL1srTA,10244
7
9
  mem_llm/knowledge_loader.py,sha256=oSNhfYYcx7DlZLVogxnbSwaIydq_Q3__RDJFeZR2XVw,2699
8
10
  mem_llm/llm_client.py,sha256=3F04nlnRWRlhkQ3aZO-OfsxeajB2gwbIDfClu04cyb0,8709
9
11
  mem_llm/logger.py,sha256=dZUmhGgFXtDsDBU_D4kZlJeMp6k-VNPaBcyTt7rZYKE,4507
10
- mem_llm/mem_agent.py,sha256=HC-XHzyHowkabOeGF49ypEAPi3ymmX1j_nlCMwSFxOY,32107
11
- mem_llm/memory_db.py,sha256=EC894gaNpBzxHsiPx2WlQ4R0EBuZ0ZKYAm4Q3YpOdEE,14531
12
+ mem_llm/mem_agent.py,sha256=1HFg-cmDe2D4y-jY--XSJiuyEkReDph6fbCLrybvt_I,33246
13
+ mem_llm/memory_db.py,sha256=4HbxgfhPrijbBKsEv4ncmjZeK-RhtLkyWBrg-quCsNE,14715
12
14
  mem_llm/memory_manager.py,sha256=CZI3A8pFboHQIgeiXB1h2gZK7mgfbVSU3IxuqE-zXtc,9978
13
15
  mem_llm/memory_tools.py,sha256=ARANFqu_bmL56SlV1RzTjfQsJj-Qe2QvqY0pF92hDxU,8678
14
16
  mem_llm/prompt_security.py,sha256=ehAi6aLiXj0gFFhpyjwEr8LentSTJwOQDLbINV7SaVM,9960
15
17
  mem_llm/retry_handler.py,sha256=z5ZcSQKbvVeNK7plagTLorvOeoYgRpQcsX3PpNqUjKM,6389
16
- mem_llm/thread_safe_db.py,sha256=7dTwATSJf1w5NMXNKg0n2Whv2F6LsdytRcUQ4Ruz_wg,10144
17
- mem_llm-1.1.0.dist-info/METADATA,sha256=VQ69D7mKe-56-_xBVx5fq1dYdyqj1nenlquxEMnll5k,15175
18
- mem_llm-1.1.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
19
- mem_llm-1.1.0.dist-info/entry_points.txt,sha256=z9bg6xgNroIobvCMtnSXeFPc-vI1nMen8gejHCdnl0U,45
20
- mem_llm-1.1.0.dist-info/top_level.txt,sha256=_fU1ML-0JwkaxWdhqpwtmTNaJEOvDMQeJdA8d5WqDn8,8
21
- mem_llm-1.1.0.dist-info/RECORD,,
18
+ mem_llm/thread_safe_db.py,sha256=Fq-wSn4ua1qiR6M4ZTIy7UT1IlFj5xODNExgub1blbU,10328
19
+ mem_llm-1.2.0.dist-info/METADATA,sha256=63n22mzPVN414NOxGthMxHkY8YqAhP1_DFdMlcno80w,15442
20
+ mem_llm-1.2.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
21
+ mem_llm-1.2.0.dist-info/entry_points.txt,sha256=z9bg6xgNroIobvCMtnSXeFPc-vI1nMen8gejHCdnl0U,45
22
+ mem_llm-1.2.0.dist-info/top_level.txt,sha256=_fU1ML-0JwkaxWdhqpwtmTNaJEOvDMQeJdA8d5WqDn8,8
23
+ mem_llm-1.2.0.dist-info/RECORD,,