Documentation for Collection
lexy_py.collection.models.Collection
Bases: CollectionModel
Collection model
Source code in sdk-python/lexy_py/collection/models.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
add_documents(docs, *, batch_size=100)
Synchronously add documents to the collection in batches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Document | dict | list[Document | dict]
|
The documents to add. |
required |
batch_size |
int
|
The number of documents to add in each batch. Defaults to 100. |
100
|
Returns:
Name | Type | Description |
---|---|---|
Documents |
list[Document]
|
A list of created documents. |
Source code in sdk-python/lexy_py/collection/models.py
list_documents(*, limit=100, offset=0)
Synchronously get a list of documents in the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit |
int
|
The maximum number of documents to return. Defaults to 100. Maximum allowed is 1000. |
100
|
offset |
int
|
The offset to start from. Defaults to 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
Documents |
list[Document]
|
A list of documents in the collection. |
Source code in sdk-python/lexy_py/collection/models.py
upload_documents(files, filenames=None, *, batch_size=5)
Synchronously upload files to the collection in batches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
files |
str | Image | list[str | Image]
|
The files to upload.
Can be a single instance or a list of a string containing the path to
a file or an |
required |
filenames |
str | list[str]
|
The filenames of the files to upload. Defaults to None. |
None
|
batch_size |
int
|
The number of files to upload in each batch. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
Documents |
list[Document]
|
A list of created documents. |
Raises:
Type | Description |
---|---|
TypeError
|
If an input file type is invalid. |
ValueError
|
If the length of the filenames list does not match the length of the files list. |
Examples:
>>> from lexy_py import LexyClient
>>> lx = LexyClient()
>>> collection = lx.create_collection(collection_name='my_file_collection')
>>> collection.upload_documents(
... files=[
... 'lexy/sample_data/images/lexy-dalle.jpeg',
... 'lexy/sample_data/images/lexy.png',
... 'dais2023-233180.pdf',
... 'gwdemo30.mp4',
... 'kindle2.html',
... ]
... )
Source code in sdk-python/lexy_py/collection/models.py
lexy_py.collection.models.CollectionModel
Bases: BaseModel
Collection model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection. Must be unique across collections. |
required |
description |
str | None
|
|
None
|
config |
dict[str, Any] | None
|
|
{}
|
created_at |
datetime | None
|
|
None
|
updated_at |
datetime | None
|
|
None
|
collection_id |
str | None
|
|
None
|
Source code in sdk-python/lexy_py/collection/models.py
lexy_py.collection.client.CollectionClient
This class is used to interact with the Lexy Collection API.
Attributes:
Name | Type | Description |
---|---|---|
aclient |
AsyncClient
|
Asynchronous API client. |
client |
Client
|
Synchronous API client. |
Source code in sdk-python/lexy_py/collection/client.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
create_collection(collection_name, *, description=None, config=None)
Synchronously create a new collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to create. Collection names must be unique. |
required |
description |
str
|
The description of the collection. Defaults to None. |
None
|
config |
dict
|
The config of the collection. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The created collection. |
Examples:
>>> from lexy_py import LexyClient
>>> lx = LexyClient()
>>> lx.create_collection("test_collection", description="My Test Collection")
<Collection('test_collection', id='70b8ce75', description='My Test Collection')>
>>> lx.create_collection(collection_name="no_files",
... description="Collection without files",
... config={"store_files": False})
<Collection('no_files', id='925d40ac', description='Collection without files')>
Source code in sdk-python/lexy_py/collection/client.py
delete_collection(*, collection_name=None, collection_id=None, delete_documents=False)
Synchronously delete a collection by name or ID.
If both collection_name
and collection_id
are provided, collection_id
will be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to delete. |
None
|
collection_id |
str
|
The ID of the collection to delete. If provided,
|
None
|
delete_documents |
bool
|
Whether to delete the documents in the collection. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Examples:
>>> from lexy_py import LexyClient
>>> lx = LexyClient()
>>> lx.delete_collection(collection_name="test_collection", delete_documents=True)
{"msg": "Collection deleted", "collection_id": "70b8ce75", "documents_deleted": 3}
Source code in sdk-python/lexy_py/collection/client.py
get_collection(*, collection_name=None, collection_id=None)
Synchronously get a collection by name or ID.
If both collection_name
and collection_id
are provided, collection_id
will be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to get. |
None
|
collection_id |
str
|
The ID of the collection to get. If provided,
|
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The collection. |
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Examples:
>>> from lexy_py import LexyClient
>>> lx = LexyClient()
>>> lx.get_collection(collection_id="70b8ce75")
<Collection('test_collection', id='70b8ce75', description='My Test Collection')>
>>> lx.get_collection(collection_name="test_collection")
<Collection('test_collection', id='70b8ce75', description='My Test Collection')>
Source code in sdk-python/lexy_py/collection/client.py
list_collections()
Synchronously get a list of all collections.
Returns:
Type | Description |
---|---|
list[Collection]
|
list[Collection]: A list of all collections. |
Source code in sdk-python/lexy_py/collection/client.py
update_collection(*, collection_id, collection_name=None, description=None, config=None)
Synchronously update a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_id |
str
|
The ID of the collection to update. |
required |
collection_name |
str
|
The updated name of the collection. Defaults to None. |
None
|
description |
str
|
The updated description of the collection. Defaults to None. |
None
|
config |
Optional[dict]
|
(dict, optional): The updated config of the collection. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The updated collection. |
Source code in sdk-python/lexy_py/collection/client.py
acreate_collection(collection_name, *, description=None, config=None)
async
Asynchronously create a new collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to create. Collection names must be unique. |
required |
description |
str
|
The description of the collection. Defaults to None. |
None
|
config |
dict
|
The config of the collection. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The created collection. |
Source code in sdk-python/lexy_py/collection/client.py
adelete_collection(*, collection_name=None, collection_id=None, delete_documents=False)
async
Asynchronously delete a collection by name or ID.
If both collection_name
and collection_id
are provided, collection_id
will be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to delete. |
None
|
collection_id |
str
|
The ID of the collection to delete. If provided,
|
None
|
delete_documents |
bool
|
Whether to delete the documents in the collection. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Source code in sdk-python/lexy_py/collection/client.py
aget_collection(*, collection_name=None, collection_id=None)
async
Asynchronously get a collection by name or ID.
If both collection_name
and collection_id
are provided, collection_id
will be used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
The name of the collection to get. |
None
|
collection_id |
str
|
The ID of the collection to get. If provided,
|
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The collection. |
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Source code in sdk-python/lexy_py/collection/client.py
alist_collections()
async
Asynchronously get a list of all collections.
Returns:
Type | Description |
---|---|
list[Collection]
|
list[Collection]: A list of all collections. |
Source code in sdk-python/lexy_py/collection/client.py
aupdate_collection(*, collection_id, collection_name=None, description=None, config=None)
async
Asynchronously update a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_id |
str
|
The ID of the collection to update. |
required |
collection_name |
str
|
The updated name of the collection. Defaults to None. |
None
|
description |
str
|
The updated description of the collection. Defaults to None. |
None
|
config |
Optional[dict]
|
(dict, optional): The updated config of the collection. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Collection |
Collection
|
The updated collection. |