dataenginex.ml
ML training, model registry, drift detection, serving, scheduling, metrics, vectorstore & LLM.
Public API::
from dataenginex.ml import (
BaseTrainer, SklearnTrainer, TrainingResult,
ModelRegistry, ModelArtifact, ModelStage,
MLflowModelRegistry, MLflowRegistryError,
DriftDetector, DriftReport,
DriftScheduler, DriftMonitorConfig, DriftCheckResult,
ModelServer, PredictionRequest, PredictionResponse,
model_prediction_total, model_prediction_latency_seconds,
model_drift_psi, model_drift_alerts_total,
# Vector store (Issue #94)
VectorStoreBackend, InMemoryBackend, ChromaDBBackend,
Document, SearchResult, RAGPipeline,
# LLM (Issue #95)
LLMProvider, OllamaProvider, OpenAICompatibleProvider, MockProvider,
LLMConfig, LLMResponse, ChatMessage,
get_llm_provider,
llm_request_latency_seconds, llm_tokens_total,
)
DriftDetector
Detect distribution drift between a reference and current dataset.
PSI thresholds (industry standard): < 0.10 — no significant drift 0.10-0.25 — moderate drift > 0.25 — significant drift
Parameters
psi_threshold: PSI value above which drift is flagged (default 0.20). n_bins: Number of histogram bins for PSI calculation (default 10).
Source code in src/dataenginex/ml/drift.py
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 | |
check_feature(feature_name, reference, current)
Check drift for a single numeric feature.
Source code in src/dataenginex/ml/drift.py
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 | |
check_dataset(reference, current)
Check drift across all shared features in two datasets.
Parameters
reference:
Mapping of feature_name → values for the reference period.
current:
Mapping of feature_name → values for the current period.
Source code in src/dataenginex/ml/drift.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
DriftReport
dataclass
Outcome of a drift check for a single feature.
Attributes:
| Name | Type | Description |
|---|---|---|
feature_name |
str
|
Name of the feature that was checked. |
psi |
float
|
Population Stability Index value. |
drift_detected |
bool
|
Whether drift exceeds the configured threshold. |
severity |
str
|
Drift severity — |
reference_mean |
float | None
|
Mean of the reference distribution. |
current_mean |
float | None
|
Mean of the current distribution. |
reference_std |
float | None
|
Standard deviation of reference distribution. |
current_std |
float | None
|
Standard deviation of current distribution. |
details |
dict[str, Any]
|
Extra context (bins, threshold, etc.). |
checked_at |
datetime
|
Timestamp of the drift check. |
Source code in src/dataenginex/ml/drift.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 | |
to_dict()
Serialize the drift report to a plain dictionary.
Source code in src/dataenginex/ml/drift.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
ChatMessage
dataclass
Single chat message.
Source code in src/dataenginex/ml/llm.py
67 68 69 70 71 72 | |
LLMConfig
dataclass
Configuration for an LLM provider.
Source code in src/dataenginex/ml/llm.py
75 76 77 78 79 80 81 82 83 84 | |
LLMProvider
Bases: ABC
Abstract LLM provider interface.
Source code in src/dataenginex/ml/llm.py
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 | |
generate(prompt)
abstractmethod
Generate text from a single prompt string.
Source code in src/dataenginex/ml/llm.py
111 112 113 | |
chat(messages)
abstractmethod
Generate a response from a chat conversation.
Source code in src/dataenginex/ml/llm.py
115 116 117 | |
is_available()
abstractmethod
Check whether the provider is reachable.
Source code in src/dataenginex/ml/llm.py
119 120 121 | |
generate_with_context(question, context, system_prompt=None)
RAG-style generation: inject context before the question.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
User question. |
required |
context
|
str
|
Retrieved context documents. |
required |
system_prompt
|
str | None
|
Optional override for the system prompt. |
None
|
Returns:
| Type | Description |
|---|---|
LLMResponse
|
LLM response with augmented generation. |
Source code in src/dataenginex/ml/llm.py
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 | |
LLMResponse
dataclass
Response from an LLM generation call.
Source code in src/dataenginex/ml/llm.py
87 88 89 90 91 92 93 94 95 96 97 | |
MockProvider
Bases: LLMProvider
Deterministic mock LLM provider for testing.
Returns canned responses that include the prompt in the output for assertion convenience.
Source code in src/dataenginex/ml/llm.py
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 | |
OllamaProvider
Bases: LLMProvider
Ollama local LLM provider.
Talks to a local Ollama server via its REST API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Ollama model name (e.g. |
'llama3.1:8b'
|
base_url
|
str
|
Ollama server URL. |
'http://localhost:11434'
|
config
|
LLMConfig | None
|
LLM configuration overrides. |
None
|
Source code in src/dataenginex/ml/llm.py
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 | |
generate(prompt)
Generate text via Ollama /api/generate.
Source code in src/dataenginex/ml/llm.py
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 | |
chat(messages)
Generate via Ollama /api/chat.
Source code in src/dataenginex/ml/llm.py
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 | |
is_available()
Check if Ollama server is running and the model is loaded.
Source code in src/dataenginex/ml/llm.py
296 297 298 299 300 301 302 303 304 305 306 307 308 | |
list_models()
List models available on the Ollama server.
Source code in src/dataenginex/ml/llm.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
OpenAICompatibleProvider
Bases: LLMProvider
OpenAI-compatible API provider (supports OpenAI, Groq, Together, etc.).
Uses the /v1/chat/completions endpoint with httpx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
API key for authentication. Never logged. |
required |
base_url
|
str
|
API base URL (default: OpenAI). |
'https://api.openai.com'
|
model
|
str
|
Model name. |
'gpt-4o-mini'
|
config
|
LLMConfig | None
|
LLM configuration overrides. |
None
|
Source code in src/dataenginex/ml/llm.py
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 | |
generate(prompt)
Generate text via a single-turn chat completion.
Source code in src/dataenginex/ml/llm.py
410 411 412 413 414 415 416 | |
chat(messages)
Generate a response via /v1/chat/completions.
Source code in src/dataenginex/ml/llm.py
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 | |
is_available()
Check if the API is reachable (HEAD request to base URL).
Source code in src/dataenginex/ml/llm.py
473 474 475 476 477 478 479 480 481 482 483 484 485 | |
MLflowModelRegistry
MLflow-backed model registry compatible with ModelRegistry.
Parameters
tracking_uri:
MLflow tracking server URI. Defaults to MLFLOW_TRACKING_URI
env var or http://localhost:5000.
Source code in src/dataenginex/ml/mlflow_registry.py
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 | |
register(artifact)
Register a model version in MLflow and log its run metadata.
Source code in src/dataenginex/ml/mlflow_registry.py
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 | |
get(name, version)
Fetch a model version from MLflow.
Source code in src/dataenginex/ml/mlflow_registry.py
117 118 119 120 121 122 123 124 | |
get_latest(name)
Return the highest version number for name regardless of stage.
Source code in src/dataenginex/ml/mlflow_registry.py
126 127 128 129 130 131 132 133 134 135 136 137 | |
get_production(name)
Return the model currently aliased as production.
Source code in src/dataenginex/ml/mlflow_registry.py
139 140 141 142 143 144 145 146 | |
list_models()
Return all registered model names.
Source code in src/dataenginex/ml/mlflow_registry.py
148 149 150 151 152 153 154 | |
list_versions(name)
Return all version strings for name.
Source code in src/dataenginex/ml/mlflow_registry.py
156 157 158 159 160 161 162 | |
promote(name, version, target_stage)
Transition a model version to the target stage via MLflow aliases.
Source code in src/dataenginex/ml/mlflow_registry.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
MLflowRegistryError
Bases: RuntimeError
Raised when the MLflow server is unreachable or returns an error.
Source code in src/dataenginex/ml/mlflow_registry.py
45 46 | |
ModelArtifact
dataclass
Registry entry for a model version.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Model name (e.g. |
version |
str
|
Semantic version string. |
stage |
ModelStage
|
Current lifecycle stage. |
artifact_path |
str
|
File path to the serialised model. |
metrics |
dict[str, float]
|
Training/evaluation metrics. |
parameters |
dict[str, Any]
|
Hyper-parameters used for training. |
description |
str
|
Free-text description. |
created_at |
datetime
|
When the artifact was registered. |
promoted_at |
datetime | None
|
When the artifact was last promoted. |
tags |
list[str]
|
Arbitrary labels for filtering. |
Source code in src/dataenginex/ml/registry.py
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 | |
to_dict()
Serialize the model artifact metadata to a plain dictionary.
Source code in src/dataenginex/ml/registry.py
65 66 67 68 69 70 71 | |
ModelRegistry
JSON-file-backed model registry.
Parameters
persist_path: Path to a JSON file for persistence (optional).
Source code in src/dataenginex/ml/registry.py
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 | |
register(artifact)
Register a new model version.
Source code in src/dataenginex/ml/registry.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
get(name, version)
Return the artifact for name at version, or None.
Source code in src/dataenginex/ml/registry.py
113 114 115 | |
get_latest(name)
Return the most recently registered version of name.
Source code in src/dataenginex/ml/registry.py
117 118 119 120 121 122 | |
get_production(name)
Return the model currently in production stage.
Source code in src/dataenginex/ml/registry.py
124 125 126 127 128 129 | |
list_models()
Return all registered model names.
Source code in src/dataenginex/ml/registry.py
131 132 133 | |
list_versions(name)
Return all version strings registered for name.
Source code in src/dataenginex/ml/registry.py
135 136 137 | |
promote(name, version, target_stage)
Promote a model version to a new stage.
If promoting to production, any existing production model is
automatically archived.
Source code in src/dataenginex/ml/registry.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
ModelStage
Bases: StrEnum
Model lifecycle stages.
Source code in src/dataenginex/ml/registry.py
28 29 30 31 32 33 34 | |
DriftCheckResult
dataclass
Aggregated result of a drift check across all features of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model checked. |
reports |
list[DriftReport]
|
Per-feature drift reports. |
drift_detected |
bool
|
|
max_psi |
float
|
Highest PSI score across all features. |
checked_at |
datetime
|
Timestamp of the check. |
Source code in src/dataenginex/ml/scheduler.py
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 | |
to_dict()
Serialize to a plain dictionary.
Source code in src/dataenginex/ml/scheduler.py
96 97 98 99 100 101 102 103 104 | |
DriftMonitorConfig
dataclass
Configuration for monitoring a single model's data drift.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model being monitored. |
reference_data |
dict[str, list[float]]
|
Mapping of feature_name → reference distribution values. |
psi_threshold |
float
|
PSI value above which drift is flagged (default 0.20). |
check_interval_seconds |
float
|
Seconds between consecutive checks (default 300). |
n_bins |
int
|
Number of histogram bins for PSI calculation (default 10). |
Source code in src/dataenginex/ml/scheduler.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
DriftScheduler
Background scheduler for periodic model drift checks.
Runs a daemon thread that iterates registered monitors and
invokes DriftDetector when each monitor's interval has elapsed.
Results are published to Prometheus gauges and counters.
Parameters
tick_seconds:
How often the scheduler loop wakes up to check deadlines
(default 5.0). Lower values give more precise timing
at the cost of CPU.
Source code in src/dataenginex/ml/scheduler.py
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 | |
is_running
property
Whether the scheduler thread is alive.
registered_models
property
Names of all registered models.
register(config, data_fn)
Register a model for periodic drift monitoring.
Parameters
config:
Monitor configuration (thresholds, interval, reference data).
data_fn:
Callable returning current feature data as
dict[str, list[float]].
Raises
ValueError:
If config.reference_data is empty.
Source code in src/dataenginex/ml/scheduler.py
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 | |
unregister(model_name)
Remove a model from drift monitoring.
Parameters
model_name: Name of the model to unregister.
Raises
KeyError: If the model is not registered.
Source code in src/dataenginex/ml/scheduler.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
start()
Start the background monitoring thread.
Raises
RuntimeError: If the scheduler is already running.
Source code in src/dataenginex/ml/scheduler.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
stop(timeout=10.0)
Stop the background monitoring thread.
Parameters
timeout:
Seconds to wait for the thread to join (default 10.0).
Source code in src/dataenginex/ml/scheduler.py
211 212 213 214 215 216 217 218 219 220 221 222 223 | |
get_last_result(model_name)
Return the most recent drift check result for a model.
Source code in src/dataenginex/ml/scheduler.py
236 237 238 | |
run_check(model_name)
Manually trigger a drift check for one model.
Parameters
model_name: Name of a registered model to check.
Raises
KeyError: If the model is not registered.
Returns
DriftCheckResult: Aggregated result with per-feature reports.
Source code in src/dataenginex/ml/scheduler.py
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 | |
ModelServer
Registry-aware model server.
Loads a model from the ModelRegistry and serves predictions via
the predict method.
Parameters
registry:
A ModelRegistry instance (from dataenginex.ml.registry).
Source code in src/dataenginex/ml/serving.py
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 | |
load_model(name, version, model)
Register a model object for serving.
Parameters
name:
Model name matching registry entries.
version:
Model version.
model:
Any object with a predict(X) method.
Source code in src/dataenginex/ml/serving.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
predict(request)
Run inference for request.
Source code in src/dataenginex/ml/serving.py
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 | |
list_loaded()
Return keys of all loaded models.
Source code in src/dataenginex/ml/serving.py
139 140 141 | |
PredictionRequest
dataclass
Input to the serving layer.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model to invoke. |
version |
str | None
|
Model version ( |
features |
list[dict[str, Any]]
|
List of feature dicts — each dict is one sample. |
request_id |
str
|
Caller-provided request ID for tracing. |
Source code in src/dataenginex/ml/serving.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
PredictionResponse
dataclass
Output from the serving layer.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the model that produced predictions. |
version |
str
|
Version of the model used. |
predictions |
list[Any]
|
List of prediction values. |
latency_ms |
float
|
Inference latency in milliseconds. |
request_id |
str
|
Echoed request ID for tracing. |
served_at |
datetime
|
Timestamp of the prediction. |
Source code in src/dataenginex/ml/serving.py
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 | |
to_dict()
Serialize the prediction response to a plain dictionary.
Source code in src/dataenginex/ml/serving.py
62 63 64 65 66 67 68 69 70 71 | |
BaseTrainer
Bases: ABC
Abstract base class for model trainers.
Source code in src/dataenginex/ml/training.py
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 | |
train(X_train, y_train, **params)
abstractmethod
Train the model and return metrics.
Source code in src/dataenginex/ml/training.py
131 132 133 134 135 136 137 138 139 | |
evaluate(X_test, y_test)
abstractmethod
Evaluate the model on test data.
Source code in src/dataenginex/ml/training.py
141 142 143 144 | |
predict(X)
abstractmethod
Generate predictions.
Source code in src/dataenginex/ml/training.py
146 147 148 149 | |
save(path)
abstractmethod
Persist the model to path and return the artifact path.
Source code in src/dataenginex/ml/training.py
151 152 153 154 | |
load(path, *, extra_modules=None)
abstractmethod
Load a previously saved model from path.
Source code in src/dataenginex/ml/training.py
156 157 158 159 160 161 162 163 164 | |
SklearnTrainer
Bases: BaseTrainer
scikit-learn model trainer.
Works with any sklearn estimator (or pipeline) that implements
fit, predict, and score.
Parameters
model_name:
Name used in model registry.
version:
Semantic version string.
estimator:
An sklearn estimator instance (e.g. RandomForestClassifier()).
Source code in src/dataenginex/ml/training.py
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 | |
train(X_train, y_train, **params)
Fit the estimator on X_train/y_train and return metrics.
Source code in src/dataenginex/ml/training.py
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 | |
evaluate(X_test, y_test)
Score the fitted model on X_test/y_test and return metrics.
Source code in src/dataenginex/ml/training.py
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 | |
predict(X)
Generate predictions for X using the fitted estimator.
Source code in src/dataenginex/ml/training.py
290 291 292 293 294 | |
save(path)
Pickle the fitted model, write an HMAC signature, and metadata.
Source code in src/dataenginex/ml/training.py
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 | |
load(path, *, extra_modules=None)
Load a pickled model with HMAC verification and safe unpickling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Filesystem path to the |
required |
extra_modules
|
frozenset[str] | None
|
Additional top-level module names to allow
during unpickling (e.g. |
None
|
Source code in src/dataenginex/ml/training.py
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 | |
TrainingResult
dataclass
Outcome of a model training run.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
Name of the trained model. |
version |
str
|
Semantic version of this training run. |
metrics |
dict[str, float]
|
Training metrics (e.g. |
parameters |
dict[str, Any]
|
Hyper-parameters used for training. |
duration_seconds |
float
|
Wall-clock training time. |
artifact_path |
str | None
|
Path where the model artifact is saved. |
trained_at |
datetime
|
Timestamp of training completion. |
Source code in src/dataenginex/ml/training.py
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 | |
to_dict()
Serialize the training result to a plain dictionary.
Source code in src/dataenginex/ml/training.py
111 112 113 114 115 116 117 118 119 120 121 | |
ChromaDBBackend
Bases: VectorStoreBackend
ChromaDB-backed vector store (optional dependency).
Falls back to :class:InMemoryBackend if chromadb is not
installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
ChromaDB collection name. |
'dex_documents'
|
persist_directory
|
str | None
|
Path for local persistence ( |
None
|
dimension
|
int
|
Embedding dimension hint. |
384
|
Source code in src/dataenginex/ml/vectorstore.py
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 | |
Document
dataclass
A text document with optional metadata and embedding.
Source code in src/dataenginex/ml/vectorstore.py
54 55 56 57 58 59 60 61 | |
InMemoryBackend
Bases: VectorStoreBackend
Brute-force in-memory vector store (testing & prototyping).
Stores all documents in a dict. Queries iterate over all stored vectors and compute cosine similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension
|
int
|
Expected embedding dimension (for validation). |
384
|
Source code in src/dataenginex/ml/vectorstore.py
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 | |
upsert(documents)
Insert or update documents.
Source code in src/dataenginex/ml/vectorstore.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
query(embedding, top_k=10, filter_metadata=None)
Return top-k nearest documents by cosine similarity.
Source code in src/dataenginex/ml/vectorstore.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
RAGPipeline
Retrieve-Augment-Generate pipeline orchestrator.
Combines a vector-store backend with an embedding provider to
support document ingestion and semantic retrieval. When an LLM
adapter is attached, the generate method augments the prompt
with retrieved context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
VectorStoreBackend | None
|
Vector-store backend to use. |
None
|
embed_fn
|
Any | None
|
Callable that maps text → embedding vector.
If |
None
|
dimension
|
int
|
Embedding dimension. |
384
|
Source code in src/dataenginex/ml/vectorstore.py
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 | |
ingest(texts, metadata=None, ids=None)
Embed and store a batch of texts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
Raw text documents. |
required |
metadata
|
list[dict[str, Any]] | None
|
Optional per-document metadata. |
None
|
ids
|
list[str] | None
|
Optional document IDs (auto-generated if omitted). |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of documents stored. |
Source code in src/dataenginex/ml/vectorstore.py
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 | |
query(question, top_k=5, filter_metadata=None)
Retrieve top-k relevant documents for question.
Source code in src/dataenginex/ml/vectorstore.py
433 434 435 436 437 438 439 440 441 442 443 | |
build_context(question, top_k=5, max_context_chars=4000)
Build an LLM context string from retrieved documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
User question. |
required |
top_k
|
int
|
Number of documents to retrieve. |
5
|
max_context_chars
|
int
|
Maximum context length in characters. |
4000
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted context string for LLM prompting. |
Source code in src/dataenginex/ml/vectorstore.py
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 | |
answer(question, llm, top_k=5, max_context_chars=4000, system_prompt=None)
Full RAG loop: retrieve → augment → generate.
Combines :meth:build_context with
:meth:~dataenginex.ml.llm.LLMProvider.generate_with_context
into a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
str
|
User question. |
required |
llm
|
LLMProvider
|
Any :class: |
required |
top_k
|
int
|
Documents to retrieve. |
5
|
max_context_chars
|
int
|
Context length cap in characters. |
4000
|
system_prompt
|
str | None
|
Optional system-prompt override for the LLM. |
None
|
Returns:
| Type | Description |
|---|---|
LLMResponse
|
class: |
Source code in src/dataenginex/ml/vectorstore.py
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 | |
SearchResult
dataclass
Single search hit from a vector store query.
Source code in src/dataenginex/ml/vectorstore.py
64 65 66 67 68 69 | |
VectorStoreBackend
Bases: ABC
Abstract vector-store backend.
All backends store fixed-dimension vectors keyed by string ID and support nearest-neighbour queries by cosine similarity.
Source code in src/dataenginex/ml/vectorstore.py
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 | |
upsert(documents)
abstractmethod
Insert or update documents. Returns count upserted.
Source code in src/dataenginex/ml/vectorstore.py
84 85 86 | |
query(embedding, top_k=10, filter_metadata=None)
abstractmethod
Return top-k nearest documents by cosine similarity.
Source code in src/dataenginex/ml/vectorstore.py
88 89 90 91 92 93 94 95 | |
delete(ids)
abstractmethod
Delete documents by id. Returns count deleted.
Source code in src/dataenginex/ml/vectorstore.py
97 98 99 | |
count()
abstractmethod
Number of documents in the store.
Source code in src/dataenginex/ml/vectorstore.py
101 102 103 | |
clear()
abstractmethod
Delete all documents.
Source code in src/dataenginex/ml/vectorstore.py
105 106 107 | |
get(doc_id)
abstractmethod
Retrieve a single document by ID.
Source code in src/dataenginex/ml/vectorstore.py
109 110 111 | |
get_llm_provider(provider, **kwargs)
Create an LLM provider by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
One of |
required |
**kwargs
|
Any
|
Passed directly to the provider constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
LLMProvider
|
LLMProvider instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provider name is unknown. |
Example::
llm = get_llm_provider("ollama", model="llama3.1:8b")
llm = get_llm_provider("openai", api_key="sk-...", model="gpt-4o")
llm = get_llm_provider("mock")
Source code in src/dataenginex/ml/llm.py
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 | |