openvector_dev 0.1.10__py3-none-any.whl → 0.1.12__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.
- lein_vector/api/facade.py +5 -2
- {openvector_dev-0.1.10.dist-info → openvector_dev-0.1.12.dist-info}/METADATA +1 -1
- {openvector_dev-0.1.10.dist-info → openvector_dev-0.1.12.dist-info}/RECORD +4 -5
- lein_vector/short_term.py +0 -48
- {openvector_dev-0.1.10.dist-info → openvector_dev-0.1.12.dist-info}/WHEEL +0 -0
lein_vector/api/facade.py
CHANGED
@@ -32,6 +32,7 @@ class Memory:
|
|
32
32
|
host: str,
|
33
33
|
port: int,
|
34
34
|
collection: str,
|
35
|
+
redis_url: str,
|
35
36
|
vector_size: int = 768,
|
36
37
|
api_key: str | None = None,
|
37
38
|
short_maxlen: int = 20,
|
@@ -41,12 +42,13 @@ class Memory:
|
|
41
42
|
:param host: Адрес Qdrant.
|
42
43
|
:param port: Порт Qdrant.
|
43
44
|
:param collection: Название коллекции Qdrant.
|
45
|
+
:param redis_url: Ссылка на подключение к Redis
|
44
46
|
:param vector_size: Размерность векторного пространства.
|
45
47
|
:param api_key: Ключ для эмбеддера (если требуется).
|
46
48
|
:param short_maxlen: Максимальная длина окна кратковременной памяти.
|
47
49
|
:returns: Экземпляр Memory с инициализированными зависимостями.
|
48
50
|
"""
|
49
|
-
_redis = aioredis.from_url(
|
51
|
+
_redis = aioredis.from_url(redis_url, decode_responses=True)
|
50
52
|
short_mem = RedisShortTermMemory(_redis, maxlen=short_maxlen)
|
51
53
|
embedder = EmbeddingProviderGemini(api_key=api_key)
|
52
54
|
adapter = QdrantAdapter(host, port, collection, vector_size)
|
@@ -117,7 +119,8 @@ class Memory:
|
|
117
119
|
await self.long.upsert_chunk_with_vector(new_chunk, vector)
|
118
120
|
|
119
121
|
if curr_no % (block_size * self.merge_n) == 0:
|
120
|
-
|
122
|
+
merged_text, used_ids = await self.long.merge_old_chunks(user_id=user_id, bot=bot, chunk_type="type0", n=self.merge_n)
|
123
|
+
return merged_text, used_ids
|
121
124
|
else:
|
122
125
|
return None, None
|
123
126
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
lein_vector/__init__.py,sha256=ieXy65X4eVzUtSHNvlh00s4aMwKReafNni4s2q68z3Q,496
|
2
2
|
lein_vector/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
lein_vector/api/facade.py,sha256=
|
3
|
+
lein_vector/api/facade.py,sha256=s8tHif2zUJuS3eqGQQ14Zq-6sHjzW73_2V6P1qFne8M,9871
|
4
4
|
lein_vector/bases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
lein_vector/bases/embeding_provider_abc.py,sha256=WBpVC6ra-SYqhJeZs8R8U679wfGebXgwOOVPIii-IvY,265
|
6
6
|
lein_vector/bases/memory_manager_abc.py,sha256=NE13Lz-3aX3RjkRhsd5FsezPNk0xju34fFpO3Fa1n9A,1755
|
@@ -11,7 +11,6 @@ lein_vector/redis_short_term.py,sha256=uCcncjgXAlNAY46b3_Pjvrn_G0NEI16kRRR9hxayz
|
|
11
11
|
lein_vector/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
12
|
lein_vector/schemas/chunk.py,sha256=qq2J7UM94AhKXKg_gnErac5GQF9DCoaEeEHyxZg_xuk,1202
|
13
13
|
lein_vector/sentence_transformer.py,sha256=SjjIa43Y7JxcU9VkpT2Ml-CVXb8tqmrbMutZN6O_I6s,1853
|
14
|
-
|
15
|
-
openvector_dev-0.1.
|
16
|
-
openvector_dev-0.1.
|
17
|
-
openvector_dev-0.1.10.dist-info/RECORD,,
|
14
|
+
openvector_dev-0.1.12.dist-info/METADATA,sha256=dNLKK0aun5DoVYmLFUOFne1WSw8PFjKbhm7W0gttB7I,3168
|
15
|
+
openvector_dev-0.1.12.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
16
|
+
openvector_dev-0.1.12.dist-info/RECORD,,
|
lein_vector/short_term.py
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
from collections import deque
|
2
|
-
from datetime import datetime
|
3
|
-
|
4
|
-
|
5
|
-
class ShortTermMemory:
|
6
|
-
def __init__(self, maxlen: int = 10):
|
7
|
-
self._buffer: deque = deque(maxlen=maxlen)
|
8
|
-
|
9
|
-
def add(
|
10
|
-
self,
|
11
|
-
codename: str,
|
12
|
-
user_id: int,
|
13
|
-
role: str,
|
14
|
-
text: str,
|
15
|
-
ts: datetime | None = None,
|
16
|
-
**extra
|
17
|
-
) -> None:
|
18
|
-
"""Добавить сообщение в память (роль, текст, ts - время, по умолчанию now)."""
|
19
|
-
if ts is None:
|
20
|
-
ts = datetime.now()
|
21
|
-
self._buffer.append({"role": role, "text": text, "ts": ts, **extra})
|
22
|
-
|
23
|
-
def window(self, n: int | None = None) -> list[dict]:
|
24
|
-
"""Получить последние n сообщений (по умолчанию все)."""
|
25
|
-
if n is None or n > len(self._buffer):
|
26
|
-
return list(self._buffer)
|
27
|
-
return list(self._buffer)[-n:]
|
28
|
-
|
29
|
-
def clear(self) -> None:
|
30
|
-
"""Очистить память."""
|
31
|
-
self._buffer.clear()
|
32
|
-
|
33
|
-
def load(self, history: list[dict]) -> None:
|
34
|
-
"""Инициализировать память списком сообщений."""
|
35
|
-
self._buffer.clear()
|
36
|
-
for msg in history[-self._buffer.maxlen :]:
|
37
|
-
self._buffer.append(msg)
|
38
|
-
|
39
|
-
def to_list(self) -> list[dict]:
|
40
|
-
"""Выгрузить всю память как список."""
|
41
|
-
return list(self._buffer)
|
42
|
-
|
43
|
-
def chunk_for_vector(self, chunk_size: int = 6) -> list[dict] | None:
|
44
|
-
"""Сформировать чанк для векторной БД — N последних сообщений по хронологии."""
|
45
|
-
if len(self._buffer) < chunk_size:
|
46
|
-
return None
|
47
|
-
# Забираем chunk_size старейших, но не очищаем (внешний код решает)
|
48
|
-
return list(self._buffer)[-chunk_size:]
|
File without changes
|