API Reference¶
This section provides detailed API reference documentation for the Kura package, automatically generated from the source code using mkdocstrings.
How to Use This Reference¶
The API reference is organized by module, with each module containing related classes and functions. For each class, you'll find:
- Constructor parameters and their descriptions
- Instance methods with parameter details and return types
- Properties and attributes
To use these classes in your code, import them from their respective modules:
from kura import Kura
from kura.embedding import OpenAIEmbeddingModel
from kura.summarisation import SummaryModel
# And so on...
Core Classes¶
Procedural API¶
The procedural API provides a functional approach to conversation analysis with composable pipeline functions.
Pipeline Functions¶
kura.summarise_conversations(conversations: List[Conversation], *, model: BaseSummaryModel, checkpoint_manager: Optional[CheckpointManager] = None) -> List[ConversationSummary]
async
¶
Generate summaries for a list of conversations.
This is a pure function that takes conversations and a summary model, and returns conversation summaries. Optionally uses checkpointing.
The function works with any model that implements BaseSummaryModel, supporting heterogeneous backends (OpenAI, vLLM, Hugging Face, etc.) through polymorphism.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conversations | List[Conversation] | List of conversations to summarize | required |
model | BaseSummaryModel | Model to use for summarization (OpenAI, vLLM, local, etc.) | required |
checkpoint_manager | Optional[CheckpointManager] | Optional checkpoint manager for caching | None |
Returns:
Type | Description |
---|---|
List[ConversationSummary] | List of conversation summaries |
Example
openai_model = OpenAISummaryModel(api_key="sk-...") checkpoint_mgr = CheckpointManager("./checkpoints") summaries = await summarise_conversations( ... conversations=my_conversations, ... model=openai_model, ... checkpoint_manager=checkpoint_mgr ... )
Source code in kura/v1/kura.py
kura.generate_base_clusters_from_conversation_summaries(summaries: List[ConversationSummary], *, model: BaseClusterModel, checkpoint_manager: Optional[CheckpointManager] = None) -> List[Cluster]
async
¶
Generate base clusters from conversation summaries.
This function groups similar summaries into initial clusters using the provided clustering model. Supports different clustering algorithms through the model interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
summaries | List[ConversationSummary] | List of conversation summaries to cluster | required |
model | BaseClusterModel | Model to use for clustering (HDBSCAN, KMeans, etc.) | required |
checkpoint_manager | Optional[CheckpointManager] | Optional checkpoint manager for caching | None |
Returns:
Type | Description |
---|---|
List[Cluster] | List of base clusters |
Example
cluster_model = ClusterModel(algorithm="hdbscan") clusters = await generate_base_clusters( ... summaries=conversation_summaries, ... model=cluster_model, ... checkpoint_manager=checkpoint_mgr ... )
Source code in kura/v1/kura.py
kura.reduce_clusters_from_base_clusters(clusters: List[Cluster], *, model: BaseMetaClusterModel, checkpoint_manager: Optional[CheckpointManager] = None) -> List[Cluster]
async
¶
Reduce clusters into a hierarchical structure.
Iteratively combines similar clusters until the number of root clusters is less than or equal to the model's max_clusters setting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clusters | List[Cluster] | List of initial clusters to reduce | required |
model | BaseMetaClusterModel | Meta-clustering model to use for reduction | required |
checkpoint_manager | Optional[CheckpointManager] | Optional checkpoint manager for caching | None |
Returns:
Type | Description |
---|---|
List[Cluster] | List of clusters with hierarchical structure |
Example
meta_model = MetaClusterModel(max_clusters=5) reduced = await reduce_clusters( ... clusters=base_clusters, ... model=meta_model, ... checkpoint_manager=checkpoint_mgr ... )
Source code in kura/v1/kura.py
kura.reduce_dimensionality_from_clusters(clusters: List[Cluster], *, model: BaseDimensionalityReduction, checkpoint_manager: Optional[CheckpointManager] = None) -> List[ProjectedCluster]
async
¶
Reduce dimensions of clusters for visualization.
Projects clusters to 2D space using the provided dimensionality reduction model. Supports different algorithms (UMAP, t-SNE, PCA, etc.) through the model interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clusters | List[Cluster] | List of clusters to project | required |
model | BaseDimensionalityReduction | Dimensionality reduction model to use (UMAP, t-SNE, etc.) | required |
checkpoint_manager | Optional[CheckpointManager] | Optional checkpoint manager for caching | None |
Returns:
Type | Description |
---|---|
List[ProjectedCluster] | List of projected clusters with 2D coordinates |
Example
dim_model = HDBUMAP(n_components=2) projected = await reduce_dimensionality( ... clusters=hierarchical_clusters, ... model=dim_model, ... checkpoint_manager=checkpoint_mgr ... )
Source code in kura/v1/kura.py
Checkpoint Management¶
kura.CheckpointManager
¶
Handles checkpoint loading and saving for pipeline steps.
Source code in kura/v1/kura.py
checkpoint_dir = checkpoint_dir
instance-attribute
¶
enabled = enabled
instance-attribute
¶
__init__(checkpoint_dir: str, *, enabled: bool = True)
¶
Initialize checkpoint manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkpoint_dir | str | Directory for saving checkpoints | required |
enabled | bool | Whether checkpointing is enabled | True |
Source code in kura/v1/kura.py
get_checkpoint_path(filename: str) -> str
¶
load_checkpoint(filename: str, model_class: type[T]) -> Optional[List[T]]
¶
Load data from a checkpoint file if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename | str | Name of the checkpoint file | required |
model_class | type[T] | Pydantic model class for deserializing the data | required |
Returns:
Type | Description |
---|---|
Optional[List[T]] | List of model instances if checkpoint exists, None otherwise |
Source code in kura/v1/kura.py
save_checkpoint(filename: str, data: List[T]) -> None
¶
Save data to a checkpoint file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename | str | Name of the checkpoint file | required |
data | List[T] | List of model instances to save | required |
Source code in kura/v1/kura.py
setup_checkpoint_dir() -> None
¶
Create checkpoint directory if it doesn't exist.
Implementation Classes¶
Embedding Models¶
kura.embedding
¶
logger = logging.getLogger(__name__)
module-attribute
¶
OpenAIEmbeddingModel
¶
Bases: BaseEmbeddingModel
Source code in kura/embedding.py
client = AsyncOpenAI()
instance-attribute
¶
model_name = model_name
instance-attribute
¶
__init__(model_name: str = 'text-embedding-3-small', model_batch_size: int = 50, n_concurrent_jobs: int = 5)
¶
Source code in kura/embedding.py
embed(texts: list[str]) -> list[list[float]]
async
¶
Source code in kura/embedding.py
SentenceTransformerEmbeddingModel
¶
Bases: BaseEmbeddingModel
Source code in kura/embedding.py
model = SentenceTransformer(model_name)
instance-attribute
¶
__init__(model_name: str = 'all-MiniLM-L6-v2', model_batch_size: int = 128)
¶
Source code in kura/embedding.py
embed(texts: list[str]) -> list[list[float]]
async
¶
Source code in kura/embedding.py
Summarization¶
kura.summarisation
¶
logger = logging.getLogger(__name__)
module-attribute
¶
SummaryModel
¶
Bases: BaseSummaryModel
Source code in kura/summarisation.py
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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
checkpoint_filename: str
property
¶
The filename to use for checkpointing this model's output.
console = console
instance-attribute
¶
extractors = extractors
instance-attribute
¶
max_concurrent_requests = max_concurrent_requests
instance-attribute
¶
model = model
instance-attribute
¶
sems = None
instance-attribute
¶
__init__(model: str = 'openai/gpt-4o-mini', max_concurrent_requests: int = 50, extractors: list[Callable[[Conversation, Semaphore], Union[ExtractedProperty, list[ExtractedProperty]]]] = [], console: Optional[Console] = None, **kwargs)
¶
Source code in kura/summarisation.py
apply_hooks(conversation: Conversation) -> dict[str, Union[str, int, float, bool, list[str], list[int], list[float]]]
async
¶
Source code in kura/summarisation.py
summarise(conversations: list[Conversation]) -> list[ConversationSummary]
async
¶
Source code in kura/summarisation.py
summarise_conversation(conversation: Conversation) -> ConversationSummary
async
¶
This summarisation model is designed to extract key information from a conversation between an AI assistant and a user. It is designed to be used in a pipeline to summarise conversations and extract metadata.
It is based on the Clio paper
It is designed to be used in a pipeline to summarise conversations and extract metadata.
Source code in kura/summarisation.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 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 |
|
Clustering¶
kura.cluster
¶
logger = logging.getLogger(__name__)
module-attribute
¶
ClusterModel
¶
Bases: BaseClusterModel
Source code in kura/cluster.py
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 |
|
checkpoint_filename: str
property
¶
The filename to use for checkpointing this model's output.
client = instructor.from_provider(model, async_client=True)
instance-attribute
¶
clustering_method = clustering_method
instance-attribute
¶
console = console
instance-attribute
¶
embedding_model = embedding_model
instance-attribute
¶
max_concurrent_requests = max_concurrent_requests
instance-attribute
¶
sem = Semaphore(max_concurrent_requests)
instance-attribute
¶
__init__(clustering_method: BaseClusteringMethod = KmeansClusteringMethod(), embedding_model: BaseEmbeddingModel = OpenAIEmbeddingModel(), max_concurrent_requests: int = 50, model: str = 'openai/gpt-4o-mini', console: Optional[Console] = None, **kwargs)
¶
Source code in kura/cluster.py
cluster_summaries(summaries: list[ConversationSummary]) -> list[Cluster]
async
¶
Source code in kura/cluster.py
generate_cluster(summaries: list[ConversationSummary], contrastive_examples: list[ConversationSummary]) -> Cluster
async
¶
Source code in kura/cluster.py
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 |
|
get_contrastive_examples(cluster_id: int, cluster_id_to_summaries: dict[int, list[ConversationSummary]], limit: int = 10) -> list[ConversationSummary]
¶
Get contrastive examples from other clusters to help distinguish this cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cluster_id | int | The id of the cluster to get contrastive examples for | required |
cluster_id_to_summaries | dict[int, list[ConversationSummary]] | A dictionary of cluster ids to their summaries | required |
limit | int | The number of contrastive examples to return. Defaults to 10. | 10 |
Returns:
Type | Description |
---|---|
list[ConversationSummary] | list[ConversationSummary]: A list of contrastive examples from other clusters |
Source code in kura/cluster.py
Meta-Clustering¶
kura.meta_cluster
¶
logger = logging.getLogger(__name__)
module-attribute
¶
CandidateClusters
¶
Bases: BaseModel
Source code in kura/meta_cluster.py
candidate_cluster_names: list[str]
instance-attribute
¶
validate_candidate_cluster_names(v: list[str]) -> list[str]
¶
Source code in kura/meta_cluster.py
ClusterLabel
¶
Bases: BaseModel
Source code in kura/meta_cluster.py
higher_level_cluster: str
instance-attribute
¶
validate_higher_level_cluster(v: str, info: ValidationInfo) -> str
¶
Source code in kura/meta_cluster.py
MetaClusterModel
¶
Bases: BaseMetaClusterModel
Source code in kura/meta_cluster.py
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 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 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
|
checkpoint_filename: str
property
¶
The filename to use for checkpointing this model's output.
client = instructor.from_provider(model, async_client=True)
instance-attribute
¶
clustering_model = clustering_model
instance-attribute
¶
console = console
instance-attribute
¶
embedding_model = embedding_model
instance-attribute
¶
max_clusters = max_clusters
instance-attribute
¶
max_concurrent_requests = max_concurrent_requests
instance-attribute
¶
model = model
instance-attribute
¶
sem = Semaphore(max_concurrent_requests)
instance-attribute
¶
__init__(max_concurrent_requests: int = 50, model: str = 'openai/gpt-4o-mini', embedding_model: BaseEmbeddingModel = OpenAIEmbeddingModel(), clustering_model: Union[BaseClusteringMethod, None] = None, max_clusters: int = 10, console: Optional['Console'] = None, **kwargs)
¶
Source code in kura/meta_cluster.py
generate_candidate_clusters(clusters: list[Cluster], sem: Semaphore) -> list[str]
async
¶
Source code in kura/meta_cluster.py
generate_meta_clusters(clusters: list[Cluster], show_preview: bool = True) -> list[Cluster]
async
¶
Source code in kura/meta_cluster.py
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 |
|
label_cluster(cluster: Cluster, candidate_clusters: list[str])
async
¶
Source code in kura/meta_cluster.py
reduce_clusters(clusters: list[Cluster]) -> list[Cluster]
async
¶
This takes in a list of existing clusters and generates a few higher order clusters that are more general. This represents a single iteration of the meta clustering process.
In the event that we have a single cluster, we will just return a new higher level cluster which has the same name as the original cluster. ( This is an edge case which we should definitely handle better )
Source code in kura/meta_cluster.py
rename_cluster_group(clusters: list[Cluster]) -> list[Cluster]
async
¶
Source code in kura/meta_cluster.py
Dimensionality Reduction¶
kura.dimensionality
¶
logger = logging.getLogger(__name__)
module-attribute
¶
HDBUMAP
¶
Bases: BaseDimensionalityReduction
Source code in kura/dimensionality.py
checkpoint_filename: str
property
¶
The filename to use for checkpointing this model's output.