Schema
Modules concerning the schemas used throughout the Gen AI applications.
Chunk
Bases: BaseModel
Represents a chunk of content retrieved from a vector store.
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
A unique identifier for the chunk. Defaults to a random UUID. |
content |
str | bytes
|
The content of the chunk, either text or binary. |
metadata |
dict[str, Any]
|
Additional metadata associated with the chunk. Defaults to an empty dictionary. |
score |
float | None
|
Similarity score of the chunk (if available). Defaults to None. |
__repr__()
Return a string representation of the Chunk.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the Chunk. |
is_binary()
Check if the content is binary.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the content is binary, False otherwise. |
is_text()
Check if the content is text.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the content is text, False otherwise. |
validate_content(value)
classmethod
Validate the content of the Chunk.
This is a class method required by Pydantic validators. As such, it follows its signature and conventions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str | bytes
|
The content to validate. |
required |
Returns:
Type | Description |
---|---|
str | bytes
|
str | bytes: The validated content. |
Raises:
Type | Description |
---|---|
ValueError
|
If the content is empty or not a string or bytes. |
Component
Bases: ABC
An abstract base class for all components used throughout the Gen AI applications.
Every instance of Component has access to class-level _default_log_level
and _logger
, as detailed below.
For components that require high observability, it is recommended to set _default_log_level
to logging.INFO
or higher.
Example:
class MyComponent(Component):
_default_log_level = logging.INFO
def _run(self, **kwargs: Any) -> Any:
return "Hello, World!"
Attributes:
Name | Type | Description |
---|---|---|
run_profile |
RunProfile
|
The profile of the Do not override this property in your subclass. You also do not need to write this attribute in your component's docstring. |
_default_log_level |
int
|
The default log level for the component. Defaults to DEBUG. |
_logger |
Logger
|
The logger instance for the component. |
run_profile: RunProfile
property
Analyzes the _run
method and retrieves its profile.
This property method analyzes the _run
method of the class to generate a RunProfile
object.
It also updates the method signatures for methods that fully utilize the arguments.
Returns:
Name | Type | Description |
---|---|---|
RunProfile |
RunProfile
|
The profile of the |
run(**kwargs)
async
Runs the operations defined for the component.
This method emits the provided input arguments using an EventEmitter instance if available, executes a process
defined in the _run
method, and emits the resulting output if the EventEmitter is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Any
|
A dictionary of arguments to be processed. May include an |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the |
Event
Bases: BaseModel
A data class to store an event attributes.
Attributes:
Name | Type | Description |
---|---|---|
value |
str
|
The value of the event. |
level |
EventLevel
|
The severity level of the event. Defined through the EventLevel constants. |
type |
EventType
|
The type of the event. Defined through the EventType constants. |
timestamp |
datetime
|
The timestamp of the event. If not provided, the current timestamp is used. |
serialize_level(level)
Serializes an EventLevel object into its string representation.
This method serializes the given EventLevel object by returning its name as a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level |
EventLevel
|
The EventLevel object to be serialized. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the EventLevel object. |