openvector_dev 0.1.13__tar.gz → 0.1.15__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.13 → openvector_dev-0.1.15}/PKG-INFO +1 -1
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/pyproject.toml +1 -1
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/api/facade.py +46 -14
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/memory_manager_qdrant.py +2 -2
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/README.md +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/__init__.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/api/__init__.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/bases/__init__.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/bases/embeding_provider_abc.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/bases/memory_manager_abc.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/memory_manager_ram.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/qdrant_adapter.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/redis_short_term.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/schemas/__init__.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/schemas/chunk.py +0 -0
- {openvector_dev-0.1.13 → openvector_dev-0.1.15}/src/lein_vector/sentence_transformer.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
+
import random
|
1
2
|
from collections.abc import Sequence
|
2
3
|
from datetime import UTC, datetime
|
3
|
-
from typing import Optional, Any
|
4
4
|
from uuid import UUID, uuid4
|
5
5
|
|
6
6
|
import redis.asyncio as aioredis
|
@@ -24,6 +24,10 @@ class Memory:
|
|
24
24
|
self._msg_no: dict[int, int] = {}
|
25
25
|
self.merge_n = merge_n
|
26
26
|
|
27
|
+
self._gift_base = 0.02
|
28
|
+
self._gift_growth = 1.15
|
29
|
+
self._gift_fail: dict[tuple[int, str], int] = {}
|
30
|
+
|
27
31
|
self.score_threshold = 0.72
|
28
32
|
|
29
33
|
@classmethod
|
@@ -119,7 +123,9 @@ class Memory:
|
|
119
123
|
await self.long.upsert_chunk_with_vector(new_chunk, vector)
|
120
124
|
|
121
125
|
if curr_no % (block_size * self.merge_n) == 0:
|
122
|
-
merged_text, used_ids = await self.long.merge_old_chunks(
|
126
|
+
merged_text, used_ids = await self.long.merge_old_chunks(
|
127
|
+
user_id=user_id, bot=bot, chunk_type="type0", n=self.merge_n
|
128
|
+
)
|
123
129
|
return merged_text, used_ids
|
124
130
|
else:
|
125
131
|
return None, None
|
@@ -159,19 +165,35 @@ class Memory:
|
|
159
165
|
return self._to_openai(data)
|
160
166
|
|
161
167
|
async def add_short_msg(
|
162
|
-
self,
|
163
|
-
|
168
|
+
self,
|
169
|
+
user_id: int,
|
170
|
+
bot: str,
|
171
|
+
text: str,
|
172
|
+
*,
|
173
|
+
role: str = "user",
|
174
|
+
) -> bool:
|
164
175
|
"""
|
165
|
-
|
166
|
-
|
167
|
-
:param bot: Кодовое имя бота
|
168
|
-
:param text: Сообщение для записи
|
169
|
-
:param role: Роль в диалоге
|
170
|
-
:type role: str = "user"
|
171
|
-
:return:
|
176
|
+
Записывает сообщение и возвращает флаг `is_gift_hint`.
|
177
|
+
Шанс = min(1, p0 * growth**fails).
|
172
178
|
"""
|
173
179
|
await self.short.add(bot=bot, user_id=user_id, role=role, text=text)
|
174
180
|
|
181
|
+
if role != "user":
|
182
|
+
return False
|
183
|
+
|
184
|
+
key = (user_id, bot)
|
185
|
+
fails = self._gift_fail.get(key, 0)
|
186
|
+
|
187
|
+
p0, g = self._gift_base, self._gift_growth
|
188
|
+
p = min(1.0, p0 * (g**fails))
|
189
|
+
|
190
|
+
if random.random() < p:
|
191
|
+
self._gift_fail[key] = 0
|
192
|
+
return True
|
193
|
+
else:
|
194
|
+
self._gift_fail[key] = fails + 1
|
195
|
+
return False
|
196
|
+
|
175
197
|
async def add_summary_chunk(
|
176
198
|
self,
|
177
199
|
user_id: int,
|
@@ -221,12 +243,22 @@ class Memory:
|
|
221
243
|
|
222
244
|
async def delete_memory(self, user_id: int, bot: str) -> None:
|
223
245
|
"""
|
224
|
-
|
225
|
-
|
226
|
-
|
246
|
+
Полная очистка памяти данного (user_id, bot):
|
247
|
+
• short-term (Redis)
|
248
|
+
• long-term (Qdrant)
|
249
|
+
• внутренние счётчики фасада (_msg_no, _gift_fail)
|
227
250
|
"""
|
251
|
+
# 1) short-term (Redis list)
|
252
|
+
await self.short.clear(user_id=user_id, bot=bot)
|
253
|
+
|
254
|
+
# 2) long-term (Qdrant)
|
228
255
|
await self.long.delete_all(user_id, bot)
|
229
256
|
|
257
|
+
# 3) локальные счётчики
|
258
|
+
self._msg_no.pop((user_id, bot), None)
|
259
|
+
self._gift_fail.pop((user_id, bot), None)
|
260
|
+
|
261
|
+
|
230
262
|
@staticmethod
|
231
263
|
def _chunk_texts(chunks: Sequence[Chunk | ChunkPayload]) -> list[str]:
|
232
264
|
"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import asyncio
|
2
2
|
from datetime import UTC, datetime
|
3
|
-
from typing import Any
|
3
|
+
from typing import Any
|
4
4
|
from uuid import UUID
|
5
5
|
|
6
6
|
from lein_vector.bases.memory_manager_abc import MemoryManagerABC
|
@@ -95,7 +95,7 @@ class MemoryManagerQdrant(MemoryManagerABC):
|
|
95
95
|
bot: str,
|
96
96
|
chunk_type: str,
|
97
97
|
n: int = 5,
|
98
|
-
) ->
|
98
|
+
) -> tuple[str | None, list[UUID]]:
|
99
99
|
"""
|
100
100
|
Собрать n старых чанков и вернуть:
|
101
101
|
• merged_text — склеенные сообщения c ролями,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{openvector_dev-0.1.13 → openvector_dev-0.1.15}/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
|