API reference
DIClient
DIClient
The DIClient
class serves as a client interface for interacting with the Data Intelligence (DI) solution.
It provides methods to retrieve and interact with various data entities such as collections, pipelines, schemas,
and embedding models. Additionally, it supports performing similarity searches within collections.
This class is designed for general-purpose usage and is intended for scenarios where non-administrative
operations are required. For administrative operations, such as managing users, permissions, or system-level
configurations, the DIAdminClient
class should be used instead.
Purpose:
The DIClient
class simplifies the interaction with the DI solution by abstracting the underlying API calls
and providing a Pythonic interface for common operations. It is particularly useful for developers and data
scientists who need to work with DI collections, pipelines, schemas, and embedding models in their workflows.
Key Features:
- Retrieve specific or all collections, pipelines.
- Perform similarity searches within a specified collection.
- Provides a session object for managing API interactions.
Usage:
- Use this class for non-administrative tasks such as querying collections, retrieving pipelines, or performing similarity searches.
- Avoid using this class for administrative tasks. For such operations, use the
DIAdminClient
class.
Source code in pydi_client/di_client.py
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 |
|
session
property
Property to get the session object.
Returns:
Name | Type | Description |
---|---|---|
Session |
Session
|
The session object used for making API requests. This session is initialized with the provided URI. |
get_collection(*, name)
Retrieve a collection by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the collection to retrieve. This is a required keyword-only argument. |
required |
Returns:
Name | Type | Description |
---|---|---|
V1CollectionResponse |
V1CollectionResponse
|
The collection object corresponding to the |
V1CollectionResponse
|
specified name. |
Example usage
client = DIClient(uri="https://example.com")
collection = client.get_collection(name="example_collection")
print(collection)
# Output: V1CollectionResponse(
# name="example_collection",
# buckets=["bucket-1", "bucket-2"],
# pipeline="rag-pipeline"
# )
Source code in pydi_client/di_client.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
get_all_collections()
Retrieves all collections available in the system.
Returns:
Name | Type | Description |
---|---|---|
V1ListCollectionsResponse |
ListCollection
|
A response object containing a list of |
ListCollection
|
collections available in the system. |
Example usage
client = DIClient(uri="https://example.com")
collections = client.get_all_collections()
for collection in collections:
print(collection.name)
# Output:
ListCollection(
root=[
ListCollectionItem(id="1", name="collection1"),
ListCollectionItem(id="2", name="collection2")
]
)
Source code in pydi_client/di_client.py
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 |
|
get_pipeline(*, name)
Retrieve a pipeline by its name. This method fetches a pipeline object from the PipelineAPI using the provided name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the pipeline to retrieve. This is a required keyword-only argument. |
required |
Returns:
Name | Type | Description |
---|---|---|
DescribePipelineRecordResponse |
V1PipelineResponse
|
The response object containing details about the pipeline. |
Example usage
client = DIClient(uri="https://example.com")
pipeline = client.get_pipeline(name="example_pipeline")
print(pipeline)
# Output: V1PipelineResponse(
# name="example_pipeline",
# type="rag",
# model="example_model",
# customFunction="custom_processing_function",
# eventFilter={"objectSuffix": ["*.txt", "*.pdf"],
# "maxObjectSize": 10485760},
# schema="example_schema"
# )
Source code in pydi_client/di_client.py
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 |
|
get_all_pipelines()
Retrieves all pipelines available in the system.
Returns:
Name | Type | Description |
---|---|---|
ListPipelineRecordsResponse |
ListPipelines
|
A response object containing a list of |
ListPipelines
|
pipelines available in the system. |
Example usage
client = DIClient(uri="https://example.com")
pipelines = client.get_all_pipelines()
for pipeline in pipelines.pipelines:
print(pipeline.name)
# Output:
ListPipelines(
root=[
ListPipeline(id="1", name="pipeline1"),
ListPipeline(id="2", name="pipeline2")
]
)
Source code in pydi_client/di_client.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
similarity_search(*, access_key, secret_key, collection_name, query, top_k, search_parameters=None)
Perform a similarity search on a specified collection using the provided query.
This method interacts with the SimilaritySearchAPI to retrieve the most relevant
results from a collection based on the given query. The results are ranked by
similarity, and the top k
results are returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query string used to find similar items in the collection. |
required |
collection_name
|
str
|
The name of the collection to search within. |
required |
top_k
|
int
|
The number of top similar results to retrieve. |
required |
access_key
|
str
|
The access key for authentication with the API. |
required |
secret_key
|
str
|
The secret key for authentication with the API. |
required |
search_parameters
|
Optional[Union[Any, Dict[str, Any]]]
|
Additional search parameters that can be passed to the API for fine-tuning the search behavior. |
None
|
Returns:
Type | Description |
---|---|
Union[Any, List[Dict[str, Any]]]
|
Union[Any, List[Dict[str, Any]]]: A list of dictionaries containing the top |
Example usage
client = DIClient(session)
results = client.similarity_search(
query="machine learning",
collection_name="research_papers",
top_k=5,
access_key="your_access_key",
secret_key="your_secret_key",
search_parameters={"metric": "cosine", "ef_search": "100"}
)
print(results)
[
{
"dataChunk": "chunk1",
"score": 0.9,
"chunkMetadata": {
"objectKey": "value",
"startCharIndex": 1,
"endCharIndex": 2,
"bucketName": "string",
"pageLabel": "string",
"versionId": "string",
}
}
]
Source code in pydi_client/di_client.py
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 |
|
DIAdminClient
Bases: DIClient
DIAdminClient
The DIAdminClient
class is an extension of the DIClient
class, designed specifically for administrative operations
within the Data Intelligence (DI) platform. This class provides methods to manage collections, pipelines, schemas,
and their associated resources. It is intended for use cases where administrative privileges are required to perform
operations such as creating, deleting, or modifying collections, pipelines, and schemas.
Purpose:
The DIAdminClient
is tailored for scenarios where administrative-level API interactions are necessary.
It provides a higher level of control over the DI platform's resources, enabling administrators to configure
and manage the system effectively.
When to Use:
-
Use this class when you need to perform administrative tasks such as:
-
Creating or deleting collections.
-
Assigning or unassigning buckets to/from collections.
-
Creating or deleting pipelines.
-
Creating or deleting schemas.
-
-
This class is specifically designed for admin APIs. For non-admin APIs, use the
DIClient
class instead.
Initialization:
The DIAdminClient
requires authentication credentials (username and password) to establish an authenticated session
with the DI platform. Upon initialization, it creates an authenticated session that is used for all subsequent API calls.
Source code in pydi_client/di_client.py
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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|
authenticated_session
property
Property to get the authenticated session object.
Returns: AuthenticatedSession: The authenticated session object used for making API requests.This session is initialized with the provided URI, username, password, and token.
create_collection(*, name, pipeline, buckets=None)
Creates a new collection using the specified pipeline. If buckets are provided, they will be associated with the collection and inline embedding generation will be triggered. If buckets are not provided, the collection will be created but embedding generation will be deferred until buckets are assigned to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the collection to be created. This should be unique. |
required |
pipeline
|
str
|
The name of the pipeline to be associated with the collection. |
required |
buckets
|
Optional[List[str]]
|
A list of bucket names. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
V1CollectionResponse |
V1CollectionResponse
|
The created collection object. |
Example usage
# Example usage of create_collection
client = DIAdminClient(uri="https://example.com", username="admin", password="password")
collection = client.create_collection(
name="example_collection",
pipeline="data_ingestion_pipeline",
buckets=["bucket1", "bucket2"]
)
print(collection)
# Sample Output:
# V1CollectionResponse(
# name="example_collection",
# pipeline="data_ingestion_pipeline",
# buckets=["bucket1", "bucket2"]
# )
Source code in pydi_client/di_client.py
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 |
|
delete_collection(*, name)
Deletes a collection by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the collection to be deleted. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
V1DeleteCollectionResponse
|
This method does not return any value. |
Example Usage:
client = DIAdminClient(uri="https://example.com", username="admin", password="password")
resp = client.delete_collection(name="example_collection")
print(resp)
# Output:
# V1DeleteCollectionResponse(
# success=True,
# message="Collection 'example_collection' has been deleted."
# )
Source code in pydi_client/di_client.py
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 |
|
assign_buckets_to_collection(*, collection_name, buckets)
Assigns a list of buckets to a specified collection. This enables inline embedding generation for the specified buckets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection to which the buckets will be assigned. |
required |
buckets
|
List[str]
|
A list of bucket names to be assigned to the specified collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
BucketUpdateResponse |
BucketUpdateResponse
|
The response object containing details about the |
BucketUpdateResponse
|
updated collection and assigned buckets. |
Example Usage
# Initialize the DIAdminClient
client = DIAdminClient(uri="http://example.com", username="admin", password="password")
# Define the collection name and buckets
collection_name = "my_collection"
buckets = ["bucket1", "bucket2", "bucket3"]
# Assign buckets to the collection
response = client.assign_buckets_to_collection(
collection_name=collection_name,
buckets=buckets
)
print(response)
# Output:
# BucketUpdateResponse(
# sucess=true,
# message="Buckets assigned successfully to collection 'my_collection'."
# )
Notes: - This method is typically used for enabling the user buckets for intelligence using an existing collection.
Source code in pydi_client/di_client.py
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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
unassign_buckets_from_collection(*, collection_name, buckets)
Unassigns one or more buckets from a specified collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection from which the buckets will be unassigned. |
required |
buckets
|
List[str]
|
A list of bucket names to be unassigned. |
required |
Returns:
Name | Type | Description |
---|---|---|
BucketUpdateResponse |
BucketUpdateResponse
|
The response object containing details about the updated collection |
BucketUpdateResponse
|
after the buckets have been unassigned. |
Example usage
# Example usage of unassign_buckets_from_collection
client = DIAdminClient(uri="http://example.com", username="admin", password="password")
# Unassign multiple buckets
response = client.unassign_buckets_from_collection(
collection_name="example_collection",
buckets=["bucket_1", "bucket_2", "bucket_3"]
)
print(response)
# Output:
# BucketUpdateResponse(
# success=true,
# message="Buckets unassigned successfully from collection 'example_collection'."
# )
Source code in pydi_client/di_client.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
create_pipeline(*, name, pipeline_type, event_filter_object_suffix, event_filter_max_object_size=None, schema=None, model=None, custom_func=None)
Creates a new pipeline with the specified configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the pipeline to be created. |
required |
pipeline_type
|
str
|
The type of the pipeline (e.g., "rag", "metadata"). |
required |
model
|
Optional (str
|
The model associated with the pipeline. |
None
|
custom_func
|
Optional (str
|
The custom function to be used in the pipeline. |
None
|
event_filter_object_suffix
|
List[str]
|
A list of file suffixes to filter events. Ex - [".txt", ".pdf"] |
required |
event_filter_max_object_size
|
int
|
The maximum object size for event filtering. Ex - 10485760 |
None
|
schema
|
Optional (str
|
The schema definition for the pipeline. |
None
|
Returns:
Name | Type | Description |
---|---|---|
V1CreatePipelineResponse |
V1CreatePipelineResponse
|
The response object containing details of the created pipeline. |
Example usage
client = DIAdminClient(
uri="http://example.com",
username="admin",
password="password"
)
pipeline_data = client.create_pipeline(
name="example_pipeline",
pipeline_type="rag",
model="example_model",
custom_func="custom_processing_function",
event_filter_object_suffix=["*.txt", "*.pdf"],
event_filter_max_object_size=10485760,
schema="example_schema"
)
print(pipeline_data)
# Output: V1CreatePipelineResponse(
# success=true,
# message="Pipeline 'example_pipeline' created successfully."
# )
Source code in pydi_client/di_client.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
|
delete_pipeline(*, name)
Deletes a pipeline with the specified name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the pipeline to be deleted. |
required |
Returns:
Name | Type | Description |
---|---|---|
V1DeletePipelineResponse |
V1DeletePipelineResponse
|
The response object containing details about the deleted pipeline. |
Example usage
# Initialize the DIAdminClient
client = DIAdminClient(uri="http://example.com", username="admin", password="password")
# Delete a pipeline by name
response = client.delete_pipeline(name="example_pipeline")
print(response)
# Output:
# V1DeletePipelineResponse(
# message="Pipeline successfully deleted"
# success=True,
# )
Source code in pydi_client/di_client.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
get_schema(*, name)
Retrieve a schema by its name. This method fetches a schema object from the SchemaAPI using the provided name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the schema to retrieve. This is a required keyword-only argument. |
required |
Returns:
Name | Type | Description |
---|---|---|
V1SchemaResponse |
V1SchemasResponse
|
The response object containing details about the schema. |
Example usage
```python client = DIAdminClient(uri="https://example.com", username="admin", password="password") schema = client.get_schema(name="example_schema") print(schema) # Output: V1SchemaResponse( # name="example_schema", # type="...", # schema=[SchemaItem] # )
Source code in pydi_client/di_client.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
get_all_schemas()
Retrieves all schemas available in the system.
Returns:
Name | Type | Description |
---|---|---|
V1ListSchemasResponse |
V1ListSchemasResponse
|
A response object containing a list of |
V1ListSchemasResponse
|
schemas available in the system. |
Example usage
client = DIAdminClient(uri="https://example.com", username="admin", password="password")
schemas = client.get_all_schemas()
print(schemas)
# Output: V1ListSchemasResponse(
# schemas=[SchemaRecordSummary]
# )
Source code in pydi_client/di_client.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
get_embedding_model(*, name)
Retrieve an embedding model by its name. This method fetches an embedding model object from the EmbeddingModelAPI using the provided name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the embedding model to retrieve. This is a required keyword-only argument. |
required |
Returns:
Name | Type | Description |
---|---|---|
V1ModelsResponse |
V1ModelsResponse
|
The response object containing details about the embedding model. |
Example usage
client = DIAdminClient(uri="https://example.com", username="admin", password="password")
model = client.get_embedding_model(name="example_model")
print(model)
# Output: V1ModelsResponse(
# name="example_model",
# modelName="...",
# capabilities="...",
# dimension=..., # e.g., 768
# maximumTokens=..., # e.g., 512
# version="..."
# )
Source code in pydi_client/di_client.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
|
get_all_embedding_models()
Retrieves all embedding models available in the system.
Returns:
Name | Type | Description |
---|---|---|
V1ListModelsResponse |
V1ListModelsResponse
|
A response object containing a list of |
V1ListModelsResponse
|
embedding models available in the system. |
Example usage
client = DIAdminClient(uri="https://example.com", username="admin", password="password")
models = client.get_all_embedding_models()
print(models[0])
# Output: V1ModelsResponse(
# models=[ModelRecordSummary],
# )
Source code in pydi_client/di_client.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|