openvector_dev 0.1.26__tar.gz → 0.1.27__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.
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/PKG-INFO +1 -1
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/pyproject.toml +1 -1
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/api/facade.py +17 -5
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/redis_short_term.py +15 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/README.md +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/__init__.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/api/__init__.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/bases/__init__.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/bases/embeding_provider_abc.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/bases/memory_manager_abc.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/memory_manager_qdrant.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/memory_manager_ram.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/qdrant_adapter.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/schemas/__init__.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/schemas/chunk.py +0 -0
- {openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/sentence_transformer.py +0 -0
|
@@ -13,7 +13,7 @@ from lein_vector.sentence_transformer import EmbeddingProviderGemini
|
|
|
13
13
|
log = logging.getLogger(__name__)
|
|
14
14
|
|
|
15
15
|
class Memory:
|
|
16
|
-
def __init__(self, short_term, memory_manager, embedder, merge_n: int,
|
|
16
|
+
def __init__(self, short_term, memory_manager, embedder, redis_conn, merge_n: int,
|
|
17
17
|
gift_base: float, gift_growth: float, score_threshold: float):
|
|
18
18
|
"""
|
|
19
19
|
:param short_term: Кратковременное хранилище сообщений пользователя (RedisShortTermMemory).
|
|
@@ -25,6 +25,7 @@ class Memory:
|
|
|
25
25
|
self.long = memory_manager
|
|
26
26
|
self.embed = embedder
|
|
27
27
|
self._msg_no: dict[int, int] = {}
|
|
28
|
+
self.r = redis_conn
|
|
28
29
|
self.merge_n = merge_n
|
|
29
30
|
|
|
30
31
|
self._gift_base = gift_base
|
|
@@ -109,8 +110,7 @@ class Memory:
|
|
|
109
110
|
:param save_pair: Флаг, сохранять ли пару сообщений при достижении block_size
|
|
110
111
|
"""
|
|
111
112
|
key = (user_id, bot)
|
|
112
|
-
curr_no = self.
|
|
113
|
-
self._msg_no[key] = curr_no
|
|
113
|
+
curr_no = await self.r.incr(f"msg_no:{bot}:{user_id}")
|
|
114
114
|
ts = datetime.now(UTC).timestamp()
|
|
115
115
|
await self.short.add(
|
|
116
116
|
bot=bot,
|
|
@@ -209,8 +209,7 @@ class Memory:
|
|
|
209
209
|
|
|
210
210
|
key = (user_id, bot)
|
|
211
211
|
fails = self._gift_fail.get(key, 0)
|
|
212
|
-
|
|
213
|
-
self._msg_no[key] = curr_no
|
|
212
|
+
await self.r.incr(f"msg_no:{bot}:{user_id}")
|
|
214
213
|
|
|
215
214
|
p0, g = self._gift_base, self._gift_growth
|
|
216
215
|
p = min(1.0, p0 * (g**fails))
|
|
@@ -270,6 +269,19 @@ class Memory:
|
|
|
270
269
|
if old_chunks:
|
|
271
270
|
await self.long.delete_chunks(user_id, old_chunks)
|
|
272
271
|
|
|
272
|
+
async def drop_last_short(
|
|
273
|
+
self, user_id: int, bot: str, n: int = 2
|
|
274
|
+
) -> list[dict]:
|
|
275
|
+
"""
|
|
276
|
+
Удалить N последних сообщений из short-term и вернуть их содержимое.
|
|
277
|
+
Пригодится, если нужно «отмотать» историю.
|
|
278
|
+
"""
|
|
279
|
+
removed = await self.short.pop_last(user_id=user_id, bot=bot, n=n)
|
|
280
|
+
# счётчик сообщений, чтобы merge-триггер продолжал работать
|
|
281
|
+
if removed:
|
|
282
|
+
await self.r.decrby(f"msg_no:{bot}:{user_id}", len(removed))
|
|
283
|
+
return removed
|
|
284
|
+
|
|
273
285
|
async def delete_memory(self, user_id: int, bot: str) -> None:
|
|
274
286
|
"""
|
|
275
287
|
Полная очистка памяти данного (user_id, bot):
|
|
@@ -90,3 +90,18 @@ class RedisShortTermMemory:
|
|
|
90
90
|
return None
|
|
91
91
|
raw = await self.r.lrange(self._key(user_id, bot=bot), -chunk_size, -1)
|
|
92
92
|
return [self._load(r) for r in raw]
|
|
93
|
+
|
|
94
|
+
async def pop_last(self, user_id: int, bot: str, n: int = 2) -> list[dict]:
|
|
95
|
+
"""
|
|
96
|
+
Снять (и вернуть) N последних сообщений (по-умолчанию 2).
|
|
97
|
+
Если сообщений меньше – вернёт всё оставшееся.
|
|
98
|
+
"""
|
|
99
|
+
key = self._key(user_id, bot)
|
|
100
|
+
pipe = self.r.pipeline()
|
|
101
|
+
await pipe.rpop(key, n)
|
|
102
|
+
raw, = await pipe.execute()
|
|
103
|
+
if raw is None:
|
|
104
|
+
return []
|
|
105
|
+
if isinstance(raw, list):
|
|
106
|
+
return [self._load(x) for x in raw[::-1]]
|
|
107
|
+
return [self._load(raw)]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openvector_dev-0.1.26 → openvector_dev-0.1.27}/src/lein_vector/bases/embeding_provider_abc.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|