Relta API Reference
Client
Source code in src/relta/client.py
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 |
|
create_chat(datasource)
Creates a chat with the given DataSource
Source code in src/relta/client.py
create_datasource(connection_uri, name=None, dtypes=None)
Creates a new datasource object and connects it to Relta
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection_uri |
str
|
The connection_uri for the datasource |
required |
name |
str
|
The datasource name. If none is provided Relta will assign a name |
None
|
dtypes |
dict
|
Map of column names to datatypes, overrides a column's auto-detected type. The datatypes should be DuckDB datatypes. Only for CSVs. |
None
|
Raises:
Type | Description |
---|---|
CatalogException
|
Raised if a datasource with given name already exists |
BinderException
|
Raised if Relta cannot connect to the given database. |
Returns:
Name | Type | Description |
---|---|---|
DataSource |
DataSource
|
The newly created Datasource object |
Source code in src/relta/client.py
delete_datasource(name)
Deletes DataSource and all associated Chat objects from Relta. Cannot be reversed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the datasource name |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If DataSource does not exist |
Source code in src/relta/client.py
get_datasource(name)
Returns a datasource object with given name or id
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the datasource. Must be passed in. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataSource |
DataSource
|
The Datasource object or None if it does not exist |
Source code in src/relta/client.py
get_or_create_datasource(name, connection_uri)
If a datasource with the same name and same connection_uri exist we return it. Otherwise create a new one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the datasource to get or create |
required |
connection_uri |
str
|
the connection_uri to the datasource to get or create |
required |
Returns:
Name | Type | Description |
---|---|---|
DataSource |
DataSource
|
The existng datasource or the new one |
Source code in src/relta/client.py
get_sources()
Method to get all connected datasource objects
Returns:
Type | Description |
---|---|
list[DataSource]
|
list[DataSource]: A list containing DataSource objects for all connected sources |
Source code in src/relta/client.py
list_chats(datasource)
List all Chat objects for a given DataSource
Source code in src/relta/client.py
show_sources()
Prints a table of all connected datasources to the console
Source code in src/relta/client.py
Configuration
Bases: BaseSettings
Configuration class for Relta
Any attributes ending with _dir_path
will be created when a Client
object is initialized.
Source code in src/relta/config.py
DataSource
Bases: SQLModel
Source code in src/relta/datasource/datasource.py
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 423 424 425 426 427 428 |
|
decrypted_uri: str
property
Access the decrypted connection URI
semantic_layer
property
The semantic layer of the DataSource
. Populated by Client
connect(dtypes=None)
Creates a connection to the given data source. This allows Relta to query the underlying data (e.g. read schema) but does not copy data into Relta.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtypes |
dict
|
Map of column names to datatypes, overrides a column's auto-detected type. Only for CSVs. The datatypes should be DuckDB datatypes. |
None
|
Raises:
Type | Description |
---|---|
CatalogException
|
If a table with the same name is already connected to Relta |
Source code in src/relta/datasource/datasource.py
create_semantic_layer()
Returns the semantic model of the data source
Source code in src/relta/datasource/datasource.py
deploy(statistics=True)
Deploys the semantic layer to the data source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statistics |
bool
|
Calculate statistics (i.e. low cardinality columns) for each metric. Defaults to True. |
True
|
Source code in src/relta/datasource/datasource.py
load()
Updates the data in Relta from the underlying data source
Source code in src/relta/datasource/datasource.py
set_encryption_key(key)
classmethod
Chat
Bases: SQLModel
A Thread of conversation.
Contains metadata around a thread and exposes simple calls to the agent.
Source code in src/relta/chat/chat.py
prompt(s, debug=False, mode='complete', **kwargs)
Ask a question on the thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
question |
required |
debug |
bool
|
If True, runs the graph in debug mode. If None, uses the default value set in the config. Defaults to None. |
False
|
mode |
Literal['complete', 'data_only', 'sql_only']
|
The mode in which to run the agent. Defaults to 'complete'. |
'complete'
|
**kwargs |
additional keyword arguments to pass to the agent. See |
{}
|
Raises: ValueError: if the Chat has no id (it has not been persisted)
Returns:
Name | Type | Description |
---|---|---|
Response |
Response
|
the response from the agent |
Source code in src/relta/chat/chat.py
AgentMode
Bases: str
, Enum
Mode in which the agent operates.
Source code in src/relta/agents/sql_agent.py
SQLAgent
Default SQL Generation Agent.
Supports persisting threads. Directly generates SQL from DDL. Used internally for relta.chat.Chat
Source code in src/relta/agents/sql_agent.py
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 |
|
invoke(prompt, datasource, thread_id=None, debug=None, mode=AgentMode.COMPLETE, fuzz=False, n_retries=1)
Ask the agent a question.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
Question |
required |
datasource |
DataSource
|
datasource to use for the question |
required |
thread_id |
int
|
ID of the thread/chat to use for persistence. If None, runs the graph on a non-persisted thread. Defaults to None. |
None
|
debug |
bool
|
If True, runs the graph in debug mode. If None, uses the default value set in the config. Defaults to None. |
None
|
only_sql |
bool
|
If True, skips the response node and only returns the generated SQL. Defaults to False. |
required |
fuzz |
bool
|
Use an LLM to generate fake query results instead of executing the SQL. Defaults to False. |
False
|
n_retries |
int
|
Number of times to attempt to repair the SQL if the SQL execution fails. Defaults to 1. |
1
|
Returns: State: full state of the agent after the invocation
Source code in src/relta/agents/sql_agent.py
mask_metrics(metrics)
staticmethod
Note: this is not a node!
Source code in src/relta/agents/sql_agent.py
SemanticLayer
Source code in src/relta/semantic/semantic_layer.py
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 |
|
copy(source, dump=True)
Copy the semantic layer from another DataSource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
DataSource
|
|
required |
# |
from_path (Optional[Union[str, Path]]
|
Path to load the semantic layer from, ignoring |
required |
dump |
bool
|
Whether to dump the semantic layer to it's path. Defaults to True. |
True
|
Source code in src/relta/semantic/semantic_layer.py
dump(clear=True, path=None)
Dumps the semantic layer, accepting any updates made to the semantic layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clear |
bool
|
Delete all JSON/YAML files in the path for this layer. Defaults to True. See |
True
|
path |
Optional[Union[str, Path]]
|
Path to dump the semantic layer. If None, uses |
None
|
Source code in src/relta/semantic/semantic_layer.py
dumps(mode='yaml', **kwargs)
Dumps the metrics and examples to a JSON or YAML string. JSON is typically used for feeding into an agent and YAML for display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Keyword arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
JSON representation of the semantic layer (metrics and examples). |
Source code in src/relta/semantic/semantic_layer.py
load(path=None, json=True, metrics_to_load=None)
Load semantic layer.
Changes to the metrics are not persisted on disk. Use .dump()
to persist them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Optional[Union[str, Path]]
|
Path to load the semantic layer. If None, uses |
None
|
json |
bool
|
Whether to additionally load the semantic layer from deprecated JSON files.
If a metric exists in both JSON and YAML files by |
True
|
metrics_to_load |
Optional[list[str]]
|
List of metric names to load. If None, loads all metrics. Defaults to None. |
None
|
Source code in src/relta/semantic/semantic_layer.py
propose(queries, context=None)
Proposes a new semantic layer for the given datasource and natural language queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
queries |
list[str]
|
A list of natural language queries that the semantic layer should answer. |
required |
context |
Optional[str]
|
Extra information about the datasource. Defaults to None. |
None
|
Source code in src/relta/semantic/semantic_layer.py
refine(pr=False)
Refines the semantic layer based on the feedback and creates a PR with the changes. By default, sets the refined metrics, but does not persist on disk -- see dump()
to persist.
If pr=True
, attempts to create a PR on the configured GitHub repo (see Configuration
) after setting the updating the metrics in the in-memory semantic layer.
If it is successful, returns the URL of the PR. Else, returns None
.
Source code in src/relta/semantic/semantic_layer.py
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 |
|
Dimension
Bases: BaseModel
A dimension for a metric.
This is similar to a dimension in LookML -- it can be used to group or filter data in a metric. For example, a dimension could be a column in a table or a calculation based on columns in a table.
Source code in src/relta/semantic/base.py
ExampleCollection
Measure
Bases: BaseModel
A measure for a metric.
This is similar to a measure in LookML -- it is an aggregate operation on some dimensions. For example, a measure could be the sum of a column or the average of columnA * columnB.