openvector_dev 0.1.5__tar.gz → 0.1.6__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.5 → openvector_dev-0.1.6}/PKG-INFO +1 -1
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/pyproject.toml +1 -1
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/api/facade.py +39 -19
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/memory_manager_qdrant.py +1 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/README.md +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/__init__.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/api/__init__.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/bases/__init__.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/bases/embeding_provider_abc.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/bases/memory_manager_abc.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/memory_manager_ram.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/qdrant_adapter.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/redis_short_term.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/schemas/__init__.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/schemas/chunk.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/sentence_transformer.py +0 -0
- {openvector_dev-0.1.5 → openvector_dev-0.1.6}/src/lein_vector/short_term.py +0 -0
@@ -7,6 +7,7 @@ import redis.asyncio as aioredis
|
|
7
7
|
from lein_vector import MemoryManagerQdrant, QdrantAdapter, RedisShortTermMemory
|
8
8
|
from lein_vector.schemas.chunk import Chunk, ChunkPayload
|
9
9
|
from lein_vector.sentence_transformer import EmbeddingProviderGemini
|
10
|
+
import warnings
|
10
11
|
|
11
12
|
|
12
13
|
class Memory:
|
@@ -62,6 +63,11 @@ class Memory:
|
|
62
63
|
:param history_n: Размер окна кратковременной памяти.
|
63
64
|
:returns: Словарь с short_term и long_term сообщениями.
|
64
65
|
"""
|
66
|
+
warnings.warn(
|
67
|
+
"Заменили на низкоуровневые методы",
|
68
|
+
DeprecationWarning,
|
69
|
+
stacklevel=2
|
70
|
+
)
|
65
71
|
key = (user_id, bot)
|
66
72
|
curr_no = self._msg_no.get(key, 0) + 1
|
67
73
|
self._msg_no[key] = curr_no
|
@@ -100,6 +106,11 @@ class Memory:
|
|
100
106
|
:param history_n: Размер окна кратковременной памяти.
|
101
107
|
:returns: Данные short_term и long_term в формате OpenAI-совместимого вывода.
|
102
108
|
"""
|
109
|
+
warnings.warn(
|
110
|
+
"Заменили на низкоуровневые методы",
|
111
|
+
DeprecationWarning,
|
112
|
+
stacklevel=2
|
113
|
+
)
|
103
114
|
data = await self.step_user(user_id, bot, user_msg, topk=topk, history_n=history_n)
|
104
115
|
data["short_term"] = self._to_openai(data["short_term"])
|
105
116
|
data["long_term"] = self._chunk_texts(data["long_term"])
|
@@ -127,11 +138,12 @@ class Memory:
|
|
127
138
|
save_pair: bool = True,
|
128
139
|
):
|
129
140
|
"""
|
130
|
-
|
131
|
-
:param
|
132
|
-
:param
|
133
|
-
:param
|
134
|
-
:param
|
141
|
+
Добавляет в чанк памяти ответ ассистента.
|
142
|
+
:param user_id: Идентификатор пользователя
|
143
|
+
:param gf_msg: Сообщение от gf (assistant)
|
144
|
+
:param bot: Идентификатор бота
|
145
|
+
:param block_size: Размер блока для сохранения в долговременной памяти
|
146
|
+
:param save_pair: Флаг, сохранять ли пару сообщений при достижении block_size
|
135
147
|
"""
|
136
148
|
key = (user_id, bot)
|
137
149
|
curr_no = self._msg_no.get(key, 0) + 1
|
@@ -170,12 +182,30 @@ class Memory:
|
|
170
182
|
if curr_no % 40 == 0:
|
171
183
|
await self.long.merge_old_chunks(user_id, "type0", n=self.merge_n)
|
172
184
|
|
173
|
-
async def
|
185
|
+
async def get_long_memories(self, user_id: int, bot: str, search_terms: list[str], topk: int = 3) -> list:
|
174
186
|
"""
|
175
|
-
|
176
|
-
:
|
187
|
+
Возвращает ТОЛЬКО длительную память по списку тем.
|
188
|
+
:param bot: Кодовое имя бота
|
189
|
+
:param user_id: Идентификатор пользователя
|
190
|
+
:param search_terms: Список поисковых запросов (строк)
|
191
|
+
:param topk: Количество возвращаемых чанков на запрос
|
192
|
+
:returns: Список релевантных чанков
|
177
193
|
"""
|
178
|
-
|
194
|
+
# wtf: Добавить фильтр только саммари
|
195
|
+
search_terms = [await self.embed.get_embedding(term) for term in search_terms]
|
196
|
+
return await self.long.retrieve_by_embeddings(user_id, search_terms, topk,
|
197
|
+
bot=bot, score_threshold=0.72, filter_={"chunk_type": "type1"})
|
198
|
+
|
199
|
+
async def get_short_memories(self, user_id: int, bot: str, n_memories: int = 20) -> list:
|
200
|
+
"""
|
201
|
+
Возвращает ТОЛЬКО кратковременную память по списку тем
|
202
|
+
:param bot: Кодовое имя бота
|
203
|
+
:param user_id: Идентификатор пользователя
|
204
|
+
:param n_memories: Количество последних сообщений кратковременной памяти
|
205
|
+
:returns: Список сообщений
|
206
|
+
"""
|
207
|
+
data = await self.short.window(user_id, bot, n_memories)
|
208
|
+
return self._to_openai(data)
|
179
209
|
|
180
210
|
async def _get_long_term(
|
181
211
|
self, user_id: int, embedding: list[float], topk: int = 3
|
@@ -188,16 +218,6 @@ class Memory:
|
|
188
218
|
"""
|
189
219
|
return await self.long.retrieve_by_embedding(user_id, embedding, topk)
|
190
220
|
|
191
|
-
async def get_memories(self, user_id: int, search_terms: list[str], topk: int = 3) -> list:
|
192
|
-
"""
|
193
|
-
:param user_id: Идентификатор пользователя.
|
194
|
-
:param search_terms: Список поисковых запросов (строк).
|
195
|
-
:param topk: Количество возвращаемых чанков на запрос.
|
196
|
-
:returns: Список релевантных чанков.
|
197
|
-
"""
|
198
|
-
search_terms = [await self.embed.get_embedding(term) for term in search_terms]
|
199
|
-
return await self.long.retrieve_by_embeddings(user_id, search_terms, topk)
|
200
|
-
|
201
221
|
async def _add_to_short(self, role: str, text: str) -> None:
|
202
222
|
"""
|
203
223
|
:param role: Роль сообщения.
|
@@ -144,6 +144,7 @@ class MemoryManagerQdrant(MemoryManagerABC):
|
|
144
144
|
async def retrieve_filtered(
|
145
145
|
self, user_id: int, bot: str, filter_: dict[str, Any], topk: int = 10
|
146
146
|
) -> list[ChunkPayload]:
|
147
|
+
raise NotImplementedError
|
147
148
|
q_filter = {"user_id": user_id, "bot": bot}
|
148
149
|
q_filter.update(filter_)
|
149
150
|
return await self.qdrant.get_all_chunks_with_filter(q_filter, topk=topk)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{openvector_dev-0.1.5 → openvector_dev-0.1.6}/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
|
File without changes
|