ai-parrot 0.8.3__cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.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.
Potentially problematic release.
This version of ai-parrot might be problematic. Click here for more details.
- ai_parrot-0.8.3.dist-info/LICENSE +21 -0
- ai_parrot-0.8.3.dist-info/METADATA +306 -0
- ai_parrot-0.8.3.dist-info/RECORD +128 -0
- ai_parrot-0.8.3.dist-info/WHEEL +6 -0
- ai_parrot-0.8.3.dist-info/top_level.txt +2 -0
- parrot/__init__.py +30 -0
- parrot/bots/__init__.py +5 -0
- parrot/bots/abstract.py +1115 -0
- parrot/bots/agent.py +492 -0
- parrot/bots/basic.py +9 -0
- parrot/bots/bose.py +17 -0
- parrot/bots/chatbot.py +271 -0
- parrot/bots/cody.py +17 -0
- parrot/bots/copilot.py +117 -0
- parrot/bots/data.py +730 -0
- parrot/bots/dataframe.py +103 -0
- parrot/bots/hrbot.py +15 -0
- parrot/bots/interfaces/__init__.py +1 -0
- parrot/bots/interfaces/retrievers.py +12 -0
- parrot/bots/notebook.py +619 -0
- parrot/bots/odoo.py +17 -0
- parrot/bots/prompts/__init__.py +41 -0
- parrot/bots/prompts/agents.py +91 -0
- parrot/bots/prompts/data.py +214 -0
- parrot/bots/retrievals/__init__.py +1 -0
- parrot/bots/retrievals/constitutional.py +19 -0
- parrot/bots/retrievals/multi.py +122 -0
- parrot/bots/retrievals/retrieval.py +610 -0
- parrot/bots/tools/__init__.py +7 -0
- parrot/bots/tools/eda.py +325 -0
- parrot/bots/tools/pdf.py +50 -0
- parrot/bots/tools/plot.py +48 -0
- parrot/bots/troc.py +16 -0
- parrot/conf.py +170 -0
- parrot/crew/__init__.py +3 -0
- parrot/crew/tools/__init__.py +22 -0
- parrot/crew/tools/bing.py +13 -0
- parrot/crew/tools/config.py +43 -0
- parrot/crew/tools/duckgo.py +62 -0
- parrot/crew/tools/file.py +24 -0
- parrot/crew/tools/google.py +168 -0
- parrot/crew/tools/gtrends.py +16 -0
- parrot/crew/tools/md2pdf.py +25 -0
- parrot/crew/tools/rag.py +42 -0
- parrot/crew/tools/search.py +32 -0
- parrot/crew/tools/url.py +21 -0
- parrot/exceptions.cpython-312-x86_64-linux-gnu.so +0 -0
- parrot/handlers/__init__.py +4 -0
- parrot/handlers/agents.py +292 -0
- parrot/handlers/bots.py +196 -0
- parrot/handlers/chat.py +192 -0
- parrot/interfaces/__init__.py +6 -0
- parrot/interfaces/database.py +27 -0
- parrot/interfaces/http.py +805 -0
- parrot/interfaces/images/__init__.py +0 -0
- parrot/interfaces/images/plugins/__init__.py +18 -0
- parrot/interfaces/images/plugins/abstract.py +58 -0
- parrot/interfaces/images/plugins/exif.py +709 -0
- parrot/interfaces/images/plugins/hash.py +52 -0
- parrot/interfaces/images/plugins/vision.py +104 -0
- parrot/interfaces/images/plugins/yolo.py +66 -0
- parrot/interfaces/images/plugins/zerodetect.py +197 -0
- parrot/llms/__init__.py +1 -0
- parrot/llms/abstract.py +69 -0
- parrot/llms/anthropic.py +58 -0
- parrot/llms/gemma.py +15 -0
- parrot/llms/google.py +44 -0
- parrot/llms/groq.py +67 -0
- parrot/llms/hf.py +45 -0
- parrot/llms/openai.py +61 -0
- parrot/llms/pipes.py +114 -0
- parrot/llms/vertex.py +89 -0
- parrot/loaders/__init__.py +9 -0
- parrot/loaders/abstract.py +628 -0
- parrot/loaders/files/__init__.py +0 -0
- parrot/loaders/files/abstract.py +39 -0
- parrot/loaders/files/text.py +63 -0
- parrot/loaders/txt.py +26 -0
- parrot/manager.py +333 -0
- parrot/models.py +504 -0
- parrot/py.typed +0 -0
- parrot/stores/__init__.py +11 -0
- parrot/stores/abstract.py +248 -0
- parrot/stores/chroma.py +188 -0
- parrot/stores/duck.py +162 -0
- parrot/stores/embeddings/__init__.py +10 -0
- parrot/stores/embeddings/abstract.py +46 -0
- parrot/stores/embeddings/base.py +52 -0
- parrot/stores/embeddings/bge.py +20 -0
- parrot/stores/embeddings/fastembed.py +17 -0
- parrot/stores/embeddings/google.py +18 -0
- parrot/stores/embeddings/huggingface.py +20 -0
- parrot/stores/embeddings/ollama.py +14 -0
- parrot/stores/embeddings/openai.py +26 -0
- parrot/stores/embeddings/transformers.py +21 -0
- parrot/stores/embeddings/vertexai.py +17 -0
- parrot/stores/empty.py +10 -0
- parrot/stores/faiss.py +160 -0
- parrot/stores/milvus.py +397 -0
- parrot/stores/postgres.py +653 -0
- parrot/stores/qdrant.py +170 -0
- parrot/tools/__init__.py +23 -0
- parrot/tools/abstract.py +68 -0
- parrot/tools/asknews.py +33 -0
- parrot/tools/basic.py +51 -0
- parrot/tools/bby.py +359 -0
- parrot/tools/bing.py +13 -0
- parrot/tools/docx.py +343 -0
- parrot/tools/duck.py +62 -0
- parrot/tools/execute.py +56 -0
- parrot/tools/gamma.py +28 -0
- parrot/tools/google.py +170 -0
- parrot/tools/gvoice.py +301 -0
- parrot/tools/results.py +278 -0
- parrot/tools/stack.py +27 -0
- parrot/tools/weather.py +70 -0
- parrot/tools/wikipedia.py +58 -0
- parrot/tools/zipcode.py +198 -0
- parrot/utils/__init__.py +2 -0
- parrot/utils/parsers/__init__.py +5 -0
- parrot/utils/parsers/toml.cpython-312-x86_64-linux-gnu.so +0 -0
- parrot/utils/toml.py +11 -0
- parrot/utils/types.cpython-312-x86_64-linux-gnu.so +0 -0
- parrot/utils/uv.py +11 -0
- parrot/version.py +10 -0
- resources/users/__init__.py +5 -0
- resources/users/handlers.py +13 -0
- resources/users/models.py +205 -0
parrot/stores/milvus.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import List, Optional, Union
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
from langchain.docstore.document import Document
|
|
5
|
+
# Milvus Database
|
|
6
|
+
from pymilvus import (
|
|
7
|
+
db,
|
|
8
|
+
connections,
|
|
9
|
+
FieldSchema,
|
|
10
|
+
CollectionSchema,
|
|
11
|
+
DataType,
|
|
12
|
+
Collection,
|
|
13
|
+
MilvusClient
|
|
14
|
+
)
|
|
15
|
+
from pymilvus.exceptions import MilvusException
|
|
16
|
+
from langchain_milvus import Milvus # pylint: disable=import-error, E0611
|
|
17
|
+
from langchain.memory import VectorStoreRetrieverMemory
|
|
18
|
+
from navconfig.logging import logging
|
|
19
|
+
from .abstract import AbstractStore
|
|
20
|
+
from ..conf import (
|
|
21
|
+
MILVUS_HOST,
|
|
22
|
+
MILVUS_PROTOCOL,
|
|
23
|
+
MILVUS_PORT,
|
|
24
|
+
MILVUS_URL,
|
|
25
|
+
MILVUS_TOKEN,
|
|
26
|
+
MILVUS_USER,
|
|
27
|
+
MILVUS_PASSWORD,
|
|
28
|
+
MILVUS_SECURE,
|
|
29
|
+
MILVUS_SERVER_NAME,
|
|
30
|
+
MILVUS_CA_CERT,
|
|
31
|
+
MILVUS_SERVER_CERT,
|
|
32
|
+
MILVUS_SERVER_KEY,
|
|
33
|
+
MILVUS_USE_TLSv2
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
logging.getLogger(name='pymilvus').setLevel(logging.WARNING)
|
|
38
|
+
|
|
39
|
+
class MilvusConnection:
|
|
40
|
+
"""
|
|
41
|
+
Context Manager for Milvus Connections.
|
|
42
|
+
"""
|
|
43
|
+
def __init__(self, alias: str = 'default', **kwargs):
|
|
44
|
+
self._connected: bool = False
|
|
45
|
+
self.credentials = kwargs
|
|
46
|
+
self.alias: str = alias
|
|
47
|
+
|
|
48
|
+
def connect(self, alias: str = None, **kwargs):
|
|
49
|
+
if not alias:
|
|
50
|
+
alias = self.alias
|
|
51
|
+
conn = connections.connect(
|
|
52
|
+
alias=alias,
|
|
53
|
+
**kwargs
|
|
54
|
+
)
|
|
55
|
+
self._connected = True
|
|
56
|
+
return alias
|
|
57
|
+
|
|
58
|
+
def is_connected(self):
|
|
59
|
+
return self._connected
|
|
60
|
+
|
|
61
|
+
def close(self, alias: str = None):
|
|
62
|
+
try:
|
|
63
|
+
connections.disconnect(alias=alias)
|
|
64
|
+
finally:
|
|
65
|
+
self._connected = False
|
|
66
|
+
|
|
67
|
+
def __enter__(self):
|
|
68
|
+
self.connect(alias=self.alias, **self.credentials)
|
|
69
|
+
return self
|
|
70
|
+
|
|
71
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
72
|
+
self.close(alias=self.alias)
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class MilvusStore(AbstractStore):
|
|
77
|
+
"""MilvusStore class.
|
|
78
|
+
|
|
79
|
+
Milvus is a Vector Database multi-layered.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
host (str): Milvus host.
|
|
83
|
+
port (int): Milvus port.
|
|
84
|
+
url (str): Milvus URL.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
def __init__(
|
|
88
|
+
self,
|
|
89
|
+
embedding_model: Union[dict, str] = None,
|
|
90
|
+
embedding: Union[dict, Callable] = None,
|
|
91
|
+
**kwargs
|
|
92
|
+
):
|
|
93
|
+
self.host = kwargs.pop("host", MILVUS_HOST)
|
|
94
|
+
self.port = kwargs.pop("port", MILVUS_PORT)
|
|
95
|
+
self.protocol = kwargs.pop("protocol", MILVUS_PROTOCOL)
|
|
96
|
+
self.consistency_level: str = kwargs.pop('consistency_level', 'Session')
|
|
97
|
+
self.create_database: bool = kwargs.pop('create_database', True)
|
|
98
|
+
self.url = kwargs.pop("url", MILVUS_URL)
|
|
99
|
+
self._client_id = kwargs.pop('client_id', 'default')
|
|
100
|
+
super().__init__(embedding_model, embedding, **kwargs)
|
|
101
|
+
if not self.url:
|
|
102
|
+
self.url = f"{self.protocol}://{self.host}:{self.port}"
|
|
103
|
+
else:
|
|
104
|
+
# Extract host and port from URL
|
|
105
|
+
if not self.host:
|
|
106
|
+
self.host = self.url.split("://")[-1].split(":")[0]
|
|
107
|
+
if not self.port:
|
|
108
|
+
self.port = int(self.url.split(":")[-1])
|
|
109
|
+
self.token = kwargs.pop("token", MILVUS_TOKEN)
|
|
110
|
+
# user and password (if required)
|
|
111
|
+
self.user = kwargs.pop(
|
|
112
|
+
"user", MILVUS_USER
|
|
113
|
+
)
|
|
114
|
+
self.password = kwargs.pop(
|
|
115
|
+
"password", MILVUS_PASSWORD
|
|
116
|
+
)
|
|
117
|
+
# SSL/TLS
|
|
118
|
+
self._secure: bool = kwargs.pop('secure', MILVUS_SECURE)
|
|
119
|
+
self._server_name: str = kwargs.pop('server_name', MILVUS_SERVER_NAME)
|
|
120
|
+
self._cert: str = kwargs.pop('server_pem_path', MILVUS_SERVER_CERT)
|
|
121
|
+
self._ca_cert: str = kwargs.pop('ca_pem_path', MILVUS_CA_CERT)
|
|
122
|
+
self._cert_key: str = kwargs.pop('client_key_path', MILVUS_SERVER_KEY)
|
|
123
|
+
# Any other argument will be passed to the Milvus client
|
|
124
|
+
self.credentials = {
|
|
125
|
+
"uri": self.url,
|
|
126
|
+
"host": self.host,
|
|
127
|
+
"port": self.port,
|
|
128
|
+
**kwargs
|
|
129
|
+
}
|
|
130
|
+
if self.token:
|
|
131
|
+
self.credentials['token'] = self.token
|
|
132
|
+
if self.user:
|
|
133
|
+
self.credentials['token'] = f"{self.user}:{self.password}"
|
|
134
|
+
# SSL Security:
|
|
135
|
+
if self._secure is True:
|
|
136
|
+
args = {
|
|
137
|
+
"secure": self._secure,
|
|
138
|
+
"server_name": self._server_name
|
|
139
|
+
}
|
|
140
|
+
if self._cert:
|
|
141
|
+
if MILVUS_USE_TLSv2 is True:
|
|
142
|
+
args['client_pem_path'] = self._cert
|
|
143
|
+
args['client_key_path'] = self._cert_key
|
|
144
|
+
else:
|
|
145
|
+
args["server_pem_path"] = self._cert
|
|
146
|
+
if self._ca_cert:
|
|
147
|
+
args['ca_pem_path'] = self._ca_cert
|
|
148
|
+
self.credentials = {**self.credentials, **args}
|
|
149
|
+
if self.database:
|
|
150
|
+
self.credentials['db_name'] = self.database
|
|
151
|
+
|
|
152
|
+
async def connection(self, alias: str = None) -> "MilvusStore":
|
|
153
|
+
"""Connects to the Milvus database."""
|
|
154
|
+
self._client_id = alias or uuid4().hex
|
|
155
|
+
_ = connections.connect(
|
|
156
|
+
alias=self._client_id,
|
|
157
|
+
**self.credentials
|
|
158
|
+
)
|
|
159
|
+
try:
|
|
160
|
+
if self.database:
|
|
161
|
+
self.use_database(
|
|
162
|
+
self.database,
|
|
163
|
+
alias=self._client_id,
|
|
164
|
+
create=self.create_database
|
|
165
|
+
)
|
|
166
|
+
except Exception as e:
|
|
167
|
+
self.logger.error(
|
|
168
|
+
f"Cannot create Database {self.database} for alias {self._client_id}: {e}"
|
|
169
|
+
)
|
|
170
|
+
self._connection = MilvusClient(
|
|
171
|
+
**self.credentials
|
|
172
|
+
)
|
|
173
|
+
self._connected = True
|
|
174
|
+
print('Connected to database', self._connection)
|
|
175
|
+
return self
|
|
176
|
+
|
|
177
|
+
async def disconnect(self, alias: str = None):
|
|
178
|
+
try:
|
|
179
|
+
a = alias or self._client_id
|
|
180
|
+
connections.disconnect(alias=a)
|
|
181
|
+
self._connection.close()
|
|
182
|
+
except AttributeError:
|
|
183
|
+
pass
|
|
184
|
+
finally:
|
|
185
|
+
self._connection = None
|
|
186
|
+
self.client = None
|
|
187
|
+
self._client_id = None
|
|
188
|
+
self._connected = False
|
|
189
|
+
|
|
190
|
+
def use_database(
|
|
191
|
+
self,
|
|
192
|
+
db_name: str,
|
|
193
|
+
alias: str = 'default',
|
|
194
|
+
create: bool = False
|
|
195
|
+
) -> None:
|
|
196
|
+
try:
|
|
197
|
+
conn = connections.connect(alias, **self.credentials)
|
|
198
|
+
except MilvusException as exc:
|
|
199
|
+
if "database not found" in exc.message:
|
|
200
|
+
self.logger.error(
|
|
201
|
+
f"Database {db_name} does not exist."
|
|
202
|
+
)
|
|
203
|
+
args = self.credentials.copy()
|
|
204
|
+
del args['db_name']
|
|
205
|
+
db.create_database(db_name, alias=alias, **args)
|
|
206
|
+
# re-connect:
|
|
207
|
+
try:
|
|
208
|
+
_ = connections.connect(alias, **self.credentials)
|
|
209
|
+
if db_name not in db.list_database(using=alias):
|
|
210
|
+
if self.create_database is True or create is True:
|
|
211
|
+
try:
|
|
212
|
+
db.create_database(db_name, using=alias, timeout=10)
|
|
213
|
+
self.logger.notice(
|
|
214
|
+
f"Database {db_name} created successfully."
|
|
215
|
+
)
|
|
216
|
+
except Exception as e:
|
|
217
|
+
raise ValueError(
|
|
218
|
+
f"Error creating database: {e}"
|
|
219
|
+
)
|
|
220
|
+
else:
|
|
221
|
+
raise ValueError(
|
|
222
|
+
f"Database {db_name} does not exist."
|
|
223
|
+
)
|
|
224
|
+
finally:
|
|
225
|
+
connections.disconnect(alias=alias)
|
|
226
|
+
|
|
227
|
+
def setup_vector(self):
|
|
228
|
+
self.vector = Milvus(
|
|
229
|
+
self._embed_,
|
|
230
|
+
consistency_level='Bounded',
|
|
231
|
+
connection_args={**self.credentials},
|
|
232
|
+
collection_name=self.collection_name,
|
|
233
|
+
)
|
|
234
|
+
return self.vector
|
|
235
|
+
|
|
236
|
+
def get_vectorstore(self):
|
|
237
|
+
return self.get_vector()
|
|
238
|
+
|
|
239
|
+
async def collection_exists(self, collection_name: str) -> bool:
|
|
240
|
+
async with self.connection():
|
|
241
|
+
if collection_name in self._connection.list_collections():
|
|
242
|
+
return True
|
|
243
|
+
return False
|
|
244
|
+
|
|
245
|
+
def check_state(self, collection_name: str) -> dict:
|
|
246
|
+
return self._connection.get_load_state(
|
|
247
|
+
collection_name=collection_name
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
def get_vector(
|
|
251
|
+
self,
|
|
252
|
+
collection: Union[str, None] = None,
|
|
253
|
+
metric_type: str = None,
|
|
254
|
+
index_type: str = None,
|
|
255
|
+
nprobe: int = 32,
|
|
256
|
+
metadata_field: str = None,
|
|
257
|
+
consistency_level: str = 'session'
|
|
258
|
+
) -> Milvus:
|
|
259
|
+
if not metric_type:
|
|
260
|
+
metric_type = self._metric_type
|
|
261
|
+
if not collection:
|
|
262
|
+
collection = self.collection_name
|
|
263
|
+
if not metric_type:
|
|
264
|
+
metric_type = self._metric_type or 'COSINE'
|
|
265
|
+
_idx = index_type or self._index_type
|
|
266
|
+
_search = {
|
|
267
|
+
"search_params": {
|
|
268
|
+
"metric_type": metric_type,
|
|
269
|
+
"index_type": _idx,
|
|
270
|
+
"params": {"nprobe": nprobe, "nlist": 1024},
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if metadata_field:
|
|
274
|
+
# document_meta
|
|
275
|
+
_search['metadata_field'] = metadata_field
|
|
276
|
+
if self._embed_ is None:
|
|
277
|
+
self._embed_ = self.create_embedding(
|
|
278
|
+
embedding_model=self.embedding_model
|
|
279
|
+
)
|
|
280
|
+
return Milvus(
|
|
281
|
+
embedding_function=self._embed_.embedding,
|
|
282
|
+
collection_name=collection,
|
|
283
|
+
consistency_level=consistency_level,
|
|
284
|
+
connection_args={
|
|
285
|
+
**self.credentials
|
|
286
|
+
},
|
|
287
|
+
primary_field='pk',
|
|
288
|
+
text_field='text',
|
|
289
|
+
vector_field='vector',
|
|
290
|
+
**_search
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
def search(
|
|
294
|
+
self,
|
|
295
|
+
payload: Union[dict, list],
|
|
296
|
+
collection: Union[str, None] = None,
|
|
297
|
+
limit: Optional[int] = None
|
|
298
|
+
) -> list:
|
|
299
|
+
args = {}
|
|
300
|
+
if collection is None:
|
|
301
|
+
collection = self.collection_name
|
|
302
|
+
if limit is not None:
|
|
303
|
+
args = {"limit": limit}
|
|
304
|
+
if isinstance(payload, dict):
|
|
305
|
+
payload = [payload]
|
|
306
|
+
result = self._connection.search(
|
|
307
|
+
collection_name=collection,
|
|
308
|
+
data=payload,
|
|
309
|
+
**args
|
|
310
|
+
)
|
|
311
|
+
return result
|
|
312
|
+
|
|
313
|
+
def memory_retriever(self, documents: List[Document], num_results: int = 5) -> VectorStoreRetrieverMemory:
|
|
314
|
+
vectordb = Milvus.from_documents(
|
|
315
|
+
documents or [],
|
|
316
|
+
self._embed_,
|
|
317
|
+
connection_args={**self.credentials}
|
|
318
|
+
)
|
|
319
|
+
retriever = Milvus.as_retriever(
|
|
320
|
+
vectordb,
|
|
321
|
+
search_kwargs=dict(k=num_results)
|
|
322
|
+
)
|
|
323
|
+
return VectorStoreRetrieverMemory(retriever=retriever)
|
|
324
|
+
|
|
325
|
+
def save_context(self, memory: VectorStoreRetrieverMemory, context: list) -> None:
|
|
326
|
+
for val in context:
|
|
327
|
+
memory.save_context(val)
|
|
328
|
+
|
|
329
|
+
async def similarity_search(
|
|
330
|
+
self,
|
|
331
|
+
query: str,
|
|
332
|
+
collection: Union[str, None] = None,
|
|
333
|
+
limit: int = 2,
|
|
334
|
+
consistency_level: str = 'Bounded'
|
|
335
|
+
) -> list:
|
|
336
|
+
if collection is None:
|
|
337
|
+
collection = self.collection_name
|
|
338
|
+
if self._embed_ is None:
|
|
339
|
+
_embed_ = self.create_embedding(
|
|
340
|
+
embedding_model=self.embedding_model
|
|
341
|
+
)
|
|
342
|
+
else:
|
|
343
|
+
_embed_ = self._embed_
|
|
344
|
+
vector_db = Milvus(
|
|
345
|
+
embedding_function=_embed_,
|
|
346
|
+
collection_name=collection,
|
|
347
|
+
consistency_level=consistency_level,
|
|
348
|
+
connection_args={
|
|
349
|
+
**self.credentials
|
|
350
|
+
},
|
|
351
|
+
primary_field='pk',
|
|
352
|
+
text_field='text',
|
|
353
|
+
vector_field='vector'
|
|
354
|
+
)
|
|
355
|
+
return await vector_db.asimilarity_search(query, k=limit)
|
|
356
|
+
|
|
357
|
+
async def insert(self, collection: str, embeddings: list) -> dict:
|
|
358
|
+
if not collection:
|
|
359
|
+
collection = self.collection_name
|
|
360
|
+
async with self:
|
|
361
|
+
# create the collection object from milvus
|
|
362
|
+
if self._connection.has_collection(collection):
|
|
363
|
+
schema = self._connection.describe_collection(collection)
|
|
364
|
+
if schema.params['dimension']!= embeddings[0].shape[0]:
|
|
365
|
+
raise ValueError(
|
|
366
|
+
f"Invalid dimension: expected {schema.params['dimension']}, got {embeddings[0].shape[0]}"
|
|
367
|
+
)
|
|
368
|
+
self._connection.upsert(collection, embeddings)
|
|
369
|
+
else:
|
|
370
|
+
raise RuntimeError(
|
|
371
|
+
f"Collection {collection} does not exist."
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
async def from_documents(self, documents: list[Document], collection: str = None, **kwargs):
|
|
375
|
+
"""
|
|
376
|
+
Save Documents as Vectors in Milvus.
|
|
377
|
+
"""
|
|
378
|
+
if not collection:
|
|
379
|
+
collection = self.collection_name
|
|
380
|
+
vectordb = await Milvus.afrom_documents(
|
|
381
|
+
documents=documents,
|
|
382
|
+
embedding=self._embed_,
|
|
383
|
+
connection_args={**self.credentials},
|
|
384
|
+
collection_name=collection
|
|
385
|
+
)
|
|
386
|
+
return vectordb
|
|
387
|
+
|
|
388
|
+
async def add_documents(self, documents: list[Document], collection: str = None, **kwargs):
|
|
389
|
+
"""
|
|
390
|
+
Add Documents as Vectors in Milvus.
|
|
391
|
+
"""
|
|
392
|
+
if not collection:
|
|
393
|
+
collection = self.collection_name
|
|
394
|
+
async with self:
|
|
395
|
+
# create the collection object from milvus
|
|
396
|
+
vectordb = self.get_vector(collection=collection, **kwargs)
|
|
397
|
+
await vectordb.aadd_documents(documents)
|