Skip to content

The Base DataModels

We provide different backend-dependent DataModels to use.

These data models provide I/O for chatbots, agents, rags, knowledge graphs etc.

The user can build new data models by inheriting from these base models.

The check functions works for every type of data models (by checking the schema) e.g. SymbolicDataModel, JsonDataModel, DataModel or Variable.

ChatMessage

Bases: DataModel

A chat message

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatMessage",
        "synalinks.ChatMessage",
    ]
)
class ChatMessage(DataModel):
    """A chat message"""

    role: ChatRole
    content: str

ChatMessages

Bases: DataModel

A list of chat messages

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatMessages",
        "synalinks.ChatMessages",
    ]
)
class ChatMessages(DataModel):
    """A list of chat messages"""

    messages: List[ChatMessage] = Field(
        description="The list of chat messages",
        default=[],
    )

ChatRole

Bases: str, Enum

The chat message roles

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatRole",
        "synalinks.ChatRole",
    ]
)
class ChatRole(str, Enum):
    """The chat message roles"""

    SYSTEM = "system"
    USER = "user"
    ASSISTANT = "assistant"

Embedding

Bases: DataModel

An embedding vector

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Embedding",
    ]
)
class Embedding(DataModel):
    """An embedding vector"""

    embedding: List[float] = Field(
        description="The embedding vector",
        default=[],
    )

Embeddings

Bases: DataModel

A list of embeddings

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Embeddings",
        "synalinks.Embeddings",
    ]
)
class Embeddings(DataModel):
    """A list of embeddings"""

    embeddings: List[List[float]] = Field(
        description="The list of embedding vectors",
        default=[],
    )

Entity

Bases: DataModel

An entity data model

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Entity",
        "synalinks.Entity",
    ]
)
class Entity(DataModel):
    """An entity data model"""

    label: str = Field(
        description="The entity label",
    )

GenericIO

Bases: DataModel

A pair of generic inputs/outputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericIO",
        "synalinks.GenericIO",
    ]
)
class GenericIO(DataModel):
    """A pair of generic inputs/outputs"""

    inputs: Dict[str, Any] = Field(
        description="The inputs",
    )
    outputs: Dict[str, Any] = Field(
        description="The outputs",
    )

GenericInputs

Bases: DataModel

A generic inputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericInputs",
        "synalinks.GenericInputs",
    ]
)
class GenericInputs(DataModel):
    """A generic inputs"""

    inputs: Dict[str, Any] = Field(
        description="The inputs",
    )

GenericOutputs

Bases: DataModel

A generic outputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericOutputs",
        "synalinks.GenericOutputs",
    ]
)
class GenericOutputs(DataModel):
    """A generic outputs"""

    outputs: Dict[str, Any] = Field(
        description="The outputs",
    )

GenericResult

Bases: DataModel

A generic result

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericResult",
        "synalinks.GenericResult",
    ]
)
class GenericResult(DataModel):
    """A generic result"""

    result: List[Any] = Field(
        description="The result",
    )

Instructions

Bases: Entity

The generator's instructions

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Instructions",
        "synalinks.Instructions",
    ]
)
class Instructions(Entity):
    """The generator's instructions"""

    label: Literal["Instructions"] = "Instructions"
    instructions: List[str] = Field(
        description="The list of instructions",
    )
    reward: Optional[float] = Field(
        description="The instruction's reward",
        default=None,
    )

Prediction

Bases: Entity, GenericIO

The generator's prediction

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Prediction",
        "synalinks.Prediction",
    ]
)
class Prediction(Entity, GenericIO):
    """The generator's prediction"""

    label: Literal["Prediction"] = "Prediction"
    reward: Optional[float] = Field(
        description="The prediction's reward",
        default=None,
    )

Relation

Bases: DataModel

A relation model

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Relation",
        "synalinks.Relation",
    ]
)
class Relation(DataModel):
    """A relation model"""

    obj: Entity = Field(
        description="The object entity",
    )
    label: str = Field(
        description="The relation label",
    )
    subj: Entity = Field(
        description="The subject entity",
    )

is_chat_message(x)

Checks if the given data model is a chat message

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_chat_message",
        "synalinks.is_chat_message",
    ]
)
def is_chat_message(x):
    """Checks if the given data model is a chat message

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), ChatMessage.get_schema()):
        return True
    return False

is_chat_messages(x)

Checks if the given data model are chat messages

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_chat_messages",
        "synalinks.is_chat_messages",
    ]
)
def is_chat_messages(x):
    """Checks if the given data model are chat messages

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), ChatMessages.get_schema()):
        return True
    return False

is_embedded_entity(x)

Checks if the given data model is an embedded entity

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embedded_entity",
        "synalinks.is_embedded_entity",
    ]
)
def is_embedded_entity(x):
    """Checks if the given data model is an embedded entity

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("label", None) and properties.get("embedding", None):
            return True
    return False

is_embedding(x)

Checks if the given data model is an embedding

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embedding",
        "synalinks.is_embedding",
    ]
)
def is_embedding(x):
    """Checks if the given data model is an embedding

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Embedding.get_schema()):
        return True
    return False

is_embeddings(x)

Checks if the given data model are embeddings

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embeddings",
        "synalinks.is_embeddings",
    ]
)
def is_embeddings(x):
    """Checks if the given data model are embeddings

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Embeddings.get_schema()):
        return True
    return False

is_entities(x)

Checks if is an entities model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_entities",
        "synalinks.is_entities",
    ]
)
def is_entities(x):
    """Checks if is an entities model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("entities", None):
            return True
    return False

is_entity(x)

Checks if the given data model is an entity

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_entity",
        "synalinks.is_entity",
    ]
)
def is_entity(x):
    """Checks if the given data model is an entity

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("label", None):
            return True
    return False

is_instructions(x)

Checks if the given data model is an instructions data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_instructions",
        "synalinks.is_instructions",
    ]
)
def is_instructions(x):
    """Checks if the given data model is an instructions data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Instructions.get_schema()):
        return True
    return False

is_knowledge_graph(x)

Checks if is a knowledge graph model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_knowledge_graph",
        "synalinks.is_knowledge_graph",
    ]
)
def is_knowledge_graph(x):
    """Checks if is a knowledge graph model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("entities", None) and properties.get("relations", None):
            return True
    return False

is_prediction(x)

Checks if the given data model is a prediction

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_prediction",
        "synalinks.is_prediction",
    ]
)
def is_prediction(x):
    """Checks if the given data model is a prediction

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Prediction.get_schema()):
        return True
    return False

is_relation(x)

Checks if is a relation model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_relation",
        "synalinks.is_relation",
    ]
)
def is_relation(x):
    """Checks if is a relation model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if (
            properties.get("subj", None)
            and properties.get("label", None)
            and properties.get("obj", None)
        ):
            return True
    return False

is_relations(x)

Checks if is an relations model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_relations",
        "synalinks.is_relations",
    ]
)
def is_relations(x):
    """Checks if is an relations model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("relations", None):
            return True
    return False

Checks if is a similarity search data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_similarity_search",
        "synalinks.is_similarity_search",
    ]
)
def is_similarity_search(x):
    """Checks if is a similarity search data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("entity_label", None) and properties.get(
            "similarity_search", None
        ):
            return True
    return False

Checks if is a triplet seach data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_triplet_search",
        "synalinks.is_triplet_search",
    ]
)
def is_triplet_search(x):
    """Checks if is a triplet seach data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if (
            properties.get("subject_label", None)
            and properties.get("subject_similarity_search", None)
            and properties.get("where_not", None)
            and properties.get("relation_label", None)
            and properties.get("object_label", None)
            and properties.get("object_similarity_search", None)
            and properties.get("returns", None)
        ):
            return True
    return False