Chat memory
labridge.func_modules.memory.chat.chat_memory
¶
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory
¶
Bases: VectorMemory
This class is used to store the chat history, involving the logs of called tools in chat.
PARAMETER | DESCRIPTION |
---|---|
vector_index |
The vector database.
TYPE:
|
retriever_kwargs |
Not used. Refer to
TYPE:
|
persist_dir |
The save directory.
TYPE:
|
Note
In the vector index, the metadata LOG_DATE_NAME
and LOG_TIME_NAME
are recorded for each chat log node, they are
useful for filtering in retrieving.
The metadata date
and time
is recorded in a list format for the convenience of metadata filtering.
For example: ['2024-08-10'], ['09:05:03'].
Source code in labridge\func_modules\memory\chat\chat_memory.py
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 |
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.memory_id: str
property
¶
The memory_id is either a user_id or a chat_group_id.
RETURNS | DESCRIPTION |
---|---|
str
|
The memory id of this ChatMemory.
TYPE:
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.from_memory_id(memory_id, embed_model, retriever_kwargs, description=None, group_members=None)
classmethod
¶
Construct from the memory_id. If the corresponding persist_dir of the memory_id does not exist, a new ChatMemory will be created.
PARAMETER | DESCRIPTION |
---|---|
memory_id |
a user_id of a lab member or a chat_group_id.
TYPE:
|
embed_model |
The used embedding model.
TYPE:
|
retriever_kwargs |
Not used.
TYPE:
|
description |
The description of this ChatMemory.
TYPE:
|
group_members |
If the memory_id is a chat_group_id, the group members must be given.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ChatVectorMemory |
Source code in labridge\func_modules\memory\chat\chat_memory.py
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 |
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.from_storage(persist_dir, embed_model, retriever_kwargs)
classmethod
¶
Load from an existing storage.
PARAMETER | DESCRIPTION |
---|---|
persist_dir |
The save path of the storage.
TYPE:
|
embed_model |
The used embedding model.
TYPE:
|
retriever_kwargs |
Not used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ChatVectorMemory |
Source code in labridge\func_modules\memory\chat\chat_memory.py
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 |
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.is_chat_group_memory()
¶
Whether this class records the history of a chat group or not.
Source code in labridge\func_modules\memory\chat\chat_memory.py
117 118 119 120 121 122 123 124 125 |
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.put(message)
¶
Put chat history.
Metadata: LOG_DATE_NAME
: [date, ]; LOG_TIME_NAME
: [time, ]
The node_id of the Last Text Node is stored in the node MEMORY_LAST_NODE_ID_NAME
Every time a New Text Node is put in, execute:
- Last Text Node -> next_node = New Text Node
- New Text Node -> prev_node = Last Text Node
- let New Text Node be the Last Text Node
PARAMETER | DESCRIPTION |
---|---|
message |
a chat message.
TYPE:
|
Source code in labridge\func_modules\memory\chat\chat_memory.py
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 |
|
labridge.func_modules.memory.chat.chat_memory.ChatVectorMemory.update_node(node_id, node)
¶
Update a node in the vector index.
PARAMETER | DESCRIPTION |
---|---|
node_id |
The node_id of the node to be updated.
TYPE:
|
node |
The new node.
TYPE:
|
Source code in labridge\func_modules\memory\chat\chat_memory.py
207 208 209 210 211 212 213 214 215 216 |
|
labridge.func_modules.memory.chat.chat_memory.update_chat_memory(memory_id, chat_messages, embed_model=None)
¶
Update the user/chat_group specific chat memory.
PARAMETER | DESCRIPTION |
---|---|
memory_id |
user_id or chat_group_id
TYPE:
|
chat_messages |
New chat messages.
TYPE:
|
embed_model |
The used embedding model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None or an Error string. |
Source code in labridge\func_modules\memory\chat\chat_memory.py
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 |
|