impressmem 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pacer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: impressmem
3
+ Version: 0.1.0
4
+ Summary: Impression-based hierarchical memory management library for AI applications with Redis storage
5
+ Author-email: Weichuan Chen <weichuan.chen@foxmail.com>
6
+ Project-URL: Homepage, https://github.com/chenweichuan/ImpressMem
7
+ Project-URL: Issues, https://github.com/chenweichuan/ImpressMem/issues
8
+ Project-URL: Documentation, https://github.com/chenweichuan/ImpressMem#readme
9
+ Project-URL: Repository, https://github.com/chenweichuan/ImpressMem.git
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: redis>=5.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
26
+ Requires-Dist: black; extra == "dev"
27
+ Requires-Dist: isort; extra == "dev"
28
+ Provides-Extra: llm
29
+ Requires-Dist: openai>=1.0.0; extra == "llm"
30
+ Dynamic: license-file
31
+
32
+ # ImpressMem
33
+
34
+ ImpressMem is an impression-based memory management library for AI applications.
35
+
36
+ ## Installation
37
+
38
+ Requires Redis server running on localhost:6379.
39
+
40
+ ```bash
41
+ pip install impressmem
42
+ ```
43
+
44
+ ## Quick Start
45
+
46
+ ```python
47
+ import asyncio
48
+ from impressmem import Config, ImpressionManager
49
+
50
+ async def main():
51
+ # Initialize configuration
52
+ config = Config(
53
+ bot_name="Bot",
54
+ redis_config={
55
+ "host": "localhost",
56
+ "port": 6379,
57
+ "db": 0
58
+ }
59
+ )
60
+
61
+ # Initialize ImpressionManager
62
+ manager = await ImpressionManager.initialize(config)
63
+
64
+ # Save an impression
65
+ await manager.save_impression(
66
+ clue="USER-NAME",
67
+ content="John Doe",
68
+ category="PersonalInfo",
69
+ labels=["UserProfile", "Identity"],
70
+ pin=False
71
+ )
72
+
73
+ # Get and build memory context
74
+ mixed_impressions = await manager.get_mixed_impressions()
75
+ mixed_labels = await manager.get_mixed_labels()
76
+ recent_categories = await manager.get_recent_categories()
77
+
78
+ memory_context = await manager.build_context()
79
+
80
+ print(memory_context)
81
+ await manager.close()
82
+
83
+ asyncio.run(main())
84
+ ```
85
+
86
+ ## Features
87
+
88
+ - Category, label, clue-based hierarchical memory organization
89
+ - Time-based rolling memory with limits
90
+ - Pinned critical impressions
91
+ - Memory merge operations for organization
92
+ - Redis-based storage for efficiency
93
+ - Text unit-based memory limits for LLM context management
94
+ - **OpenAI-compatible tool definitions for function calling**
95
+
96
+ ## Configuration
97
+
98
+ ### Config
99
+ ```python
100
+ Config(
101
+ bot_name: str,
102
+ redis_config: Dict[str, Any] = ...
103
+ )
104
+ ```
105
+
106
+ ### Memory Limits
107
+ Memory limits can be adjusted through the ImpressionManager class constants:
108
+ - `CATEGORIES_PER_SET`: Maximum categories to keep (default: 500)
109
+ - `LABELS_PER_SET`: Maximum labels to keep (default: 1500)
110
+ - `CLUES_PER_SET`: Maximum clues to keep (default: 500)
111
+ - `IMPRESSION_TEXT_UNITS_PER_SET`: Maximum text units for impressions (default: 15000)
112
+
113
+ ## API Reference
114
+
115
+ ### ImpressionManager
116
+ Core memory management class.
117
+
118
+ ```python
119
+ # Initialize
120
+ manager = await ImpressionManager.initialize(config)
121
+
122
+ # Save
123
+ await manager.save_impression(clue, content, category, labels, pin=False)
124
+
125
+ # Get
126
+ mixed_impressions = await manager.get_mixed_impressions()
127
+ mixed_labels = await manager.get_mixed_labels()
128
+ recent_categories = await manager.get_recent_categories()
129
+ recent_labels = await manager.get_recent_labels()
130
+ recent_clues = await manager.get_recent_clues()
131
+ pinned_clues = await manager.get_pinned_clues()
132
+ category_labels = await manager.get_category_labels(category)
133
+ category_clues = await manager.get_category_clues(category)
134
+ label_clues = await manager.get_label_clues(label)
135
+ impressions = await manager.get_impressions_by_clues(clues)
136
+
137
+ # Build context
138
+ memory_context = await manager.build_context()
139
+
140
+ # Merge
141
+ await manager.merge_categories(old, new)
142
+ await manager.merge_labels(sources, target)
143
+ await manager.merge_clues(sources, target, new_content=None)
144
+
145
+ # Close
146
+ await manager.close()
147
+ ```
148
+
149
+ ### Tools
150
+ OpenAI-compatible tool classes for function calling.
151
+
152
+ ```python
153
+ from impressmem import SaveImpressionTool, OrganizeImpressionsTool, RecallImpressionsTool
154
+
155
+ # Initialize tools
156
+ save_tool = SaveImpressionTool()
157
+ organize_tool = OrganizeImpressionsTool()
158
+ recall_tool = RecallImpressionsTool()
159
+
160
+ # Get tool definitions (for OpenAI function calling)
161
+ save_def = await save_tool.get_definition()
162
+ organize_def = await organize_tool.get_definition()
163
+ recall_def = await recall_tool.get_definition()
164
+
165
+ # Execute tools
166
+ full_result, summary = await save_tool.execute(json.dumps(args))
167
+ ```
168
+
169
+ ### Utility Functions
170
+
171
+ ```python
172
+ from impressmem import slice_new_turn_messages
173
+
174
+ # Slice messages for incremental memory processing
175
+ sliced = slice_new_turn_messages(messages)
176
+ ```
177
+
178
+ ## Examples
179
+
180
+ See the `examples/` directory for more usage examples:
181
+ - `context_example.py` - Build memory context
182
+ - `tools_example.py` - Using the tool classes
183
+
184
+ ## Contributing
185
+
186
+ Contributions are welcome! Please feel free to submit a Pull Request.
187
+
188
+ ## License
189
+
190
+ MIT License
@@ -0,0 +1,159 @@
1
+ # ImpressMem
2
+
3
+ ImpressMem is an impression-based memory management library for AI applications.
4
+
5
+ ## Installation
6
+
7
+ Requires Redis server running on localhost:6379.
8
+
9
+ ```bash
10
+ pip install impressmem
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ import asyncio
17
+ from impressmem import Config, ImpressionManager
18
+
19
+ async def main():
20
+ # Initialize configuration
21
+ config = Config(
22
+ bot_name="Bot",
23
+ redis_config={
24
+ "host": "localhost",
25
+ "port": 6379,
26
+ "db": 0
27
+ }
28
+ )
29
+
30
+ # Initialize ImpressionManager
31
+ manager = await ImpressionManager.initialize(config)
32
+
33
+ # Save an impression
34
+ await manager.save_impression(
35
+ clue="USER-NAME",
36
+ content="John Doe",
37
+ category="PersonalInfo",
38
+ labels=["UserProfile", "Identity"],
39
+ pin=False
40
+ )
41
+
42
+ # Get and build memory context
43
+ mixed_impressions = await manager.get_mixed_impressions()
44
+ mixed_labels = await manager.get_mixed_labels()
45
+ recent_categories = await manager.get_recent_categories()
46
+
47
+ memory_context = await manager.build_context()
48
+
49
+ print(memory_context)
50
+ await manager.close()
51
+
52
+ asyncio.run(main())
53
+ ```
54
+
55
+ ## Features
56
+
57
+ - Category, label, clue-based hierarchical memory organization
58
+ - Time-based rolling memory with limits
59
+ - Pinned critical impressions
60
+ - Memory merge operations for organization
61
+ - Redis-based storage for efficiency
62
+ - Text unit-based memory limits for LLM context management
63
+ - **OpenAI-compatible tool definitions for function calling**
64
+
65
+ ## Configuration
66
+
67
+ ### Config
68
+ ```python
69
+ Config(
70
+ bot_name: str,
71
+ redis_config: Dict[str, Any] = ...
72
+ )
73
+ ```
74
+
75
+ ### Memory Limits
76
+ Memory limits can be adjusted through the ImpressionManager class constants:
77
+ - `CATEGORIES_PER_SET`: Maximum categories to keep (default: 500)
78
+ - `LABELS_PER_SET`: Maximum labels to keep (default: 1500)
79
+ - `CLUES_PER_SET`: Maximum clues to keep (default: 500)
80
+ - `IMPRESSION_TEXT_UNITS_PER_SET`: Maximum text units for impressions (default: 15000)
81
+
82
+ ## API Reference
83
+
84
+ ### ImpressionManager
85
+ Core memory management class.
86
+
87
+ ```python
88
+ # Initialize
89
+ manager = await ImpressionManager.initialize(config)
90
+
91
+ # Save
92
+ await manager.save_impression(clue, content, category, labels, pin=False)
93
+
94
+ # Get
95
+ mixed_impressions = await manager.get_mixed_impressions()
96
+ mixed_labels = await manager.get_mixed_labels()
97
+ recent_categories = await manager.get_recent_categories()
98
+ recent_labels = await manager.get_recent_labels()
99
+ recent_clues = await manager.get_recent_clues()
100
+ pinned_clues = await manager.get_pinned_clues()
101
+ category_labels = await manager.get_category_labels(category)
102
+ category_clues = await manager.get_category_clues(category)
103
+ label_clues = await manager.get_label_clues(label)
104
+ impressions = await manager.get_impressions_by_clues(clues)
105
+
106
+ # Build context
107
+ memory_context = await manager.build_context()
108
+
109
+ # Merge
110
+ await manager.merge_categories(old, new)
111
+ await manager.merge_labels(sources, target)
112
+ await manager.merge_clues(sources, target, new_content=None)
113
+
114
+ # Close
115
+ await manager.close()
116
+ ```
117
+
118
+ ### Tools
119
+ OpenAI-compatible tool classes for function calling.
120
+
121
+ ```python
122
+ from impressmem import SaveImpressionTool, OrganizeImpressionsTool, RecallImpressionsTool
123
+
124
+ # Initialize tools
125
+ save_tool = SaveImpressionTool()
126
+ organize_tool = OrganizeImpressionsTool()
127
+ recall_tool = RecallImpressionsTool()
128
+
129
+ # Get tool definitions (for OpenAI function calling)
130
+ save_def = await save_tool.get_definition()
131
+ organize_def = await organize_tool.get_definition()
132
+ recall_def = await recall_tool.get_definition()
133
+
134
+ # Execute tools
135
+ full_result, summary = await save_tool.execute(json.dumps(args))
136
+ ```
137
+
138
+ ### Utility Functions
139
+
140
+ ```python
141
+ from impressmem import slice_new_turn_messages
142
+
143
+ # Slice messages for incremental memory processing
144
+ sliced = slice_new_turn_messages(messages)
145
+ ```
146
+
147
+ ## Examples
148
+
149
+ See the `examples/` directory for more usage examples:
150
+ - `context_example.py` - Build memory context
151
+ - `tools_example.py` - Using the tool classes
152
+
153
+ ## Contributing
154
+
155
+ Contributions are welcome! Please feel free to submit a Pull Request.
156
+
157
+ ## License
158
+
159
+ MIT License
@@ -0,0 +1,23 @@
1
+ """
2
+ ImpressMem - Impression-based Memory Management Library
3
+ """
4
+
5
+ __version__ = "0.1.0"
6
+
7
+ from impressmem.config import Config
8
+ from impressmem.impression_manager import ImpressionManager
9
+ from impressmem.tools import (
10
+ SaveImpressionTool,
11
+ OrganizeImpressionsTool,
12
+ RecallImpressionsTool,
13
+ )
14
+ from impressmem.utils import slice_new_turn_messages
15
+
16
+ __all__ = [
17
+ "Config",
18
+ "ImpressionManager",
19
+ "SaveImpressionTool",
20
+ "OrganizeImpressionsTool",
21
+ "RecallImpressionsTool",
22
+ "slice_new_turn_messages",
23
+ ]
@@ -0,0 +1,17 @@
1
+ """
2
+ Configuration for ImpressMem
3
+ """
4
+ from dataclasses import dataclass, field
5
+ from typing import Dict, Any
6
+
7
+
8
+ @dataclass
9
+ class Config:
10
+ """Configuration class for ImpressMem
11
+
12
+ Args:
13
+ bot_name: Name of the bot/assistant (default: "Bot")
14
+ redis_config: Redis configuration dictionary (default: {"host": "localhost", "port": 6379, "db": 0})
15
+ """
16
+ bot_name: str = "Bot"
17
+ redis_config: Dict[str, Any] = field(default_factory=lambda: {"host": "localhost", "port": 6379, "db": 0})