Skip to content

graflo.architecture.graph_types.index_config

Index and weight configuration models.

Classes

ABCFields

Bases: ConfigBaseModel

Base model for entities that have fields.

Attributes:

Name Type Description
name str | None

Optional name of the entity

fields list[str]

List of field names

Source code in graflo/architecture/graph_types/index_config.py
class ABCFields(ConfigBaseModel):
    """Base model for entities that have fields.

    Attributes:
        name: Optional name of the entity
        fields: List of field names
    """

    name: str | None = Field(
        default=None,
        description="Optional name of the entity (e.g. vertex name for composite field prefix).",
    )
    fields: list[str] = Field(
        default_factory=list,
        description="List of field names for this entity.",
    )
    keep_vertex_name: bool = Field(
        default=True,
        description="If True, composite field names use entity@field format; otherwise use field only.",
    )

    def cfield(self, x: str) -> str:
        """Creates a composite field name by combining the entity name with a field name.

        Args:
            x: Field name to combine with entity name

        Returns:
            Composite field name in format "entity@field"
        """
        return f"{self.name}@{x}" if self.keep_vertex_name else x

Attributes

fields = Field(default_factory=list, description='List of field names for this entity.') class-attribute instance-attribute
keep_vertex_name = Field(default=True, description='If True, composite field names use entity@field format; otherwise use field only.') class-attribute instance-attribute
name = Field(default=None, description='Optional name of the entity (e.g. vertex name for composite field prefix).') class-attribute instance-attribute

Methods:

cfield(x)

Creates a composite field name by combining the entity name with a field name.

Parameters:

Name Type Description Default
x str

Field name to combine with entity name

required

Returns:

Type Description
str

Composite field name in format "entity@field"

Source code in graflo/architecture/graph_types/index_config.py
def cfield(self, x: str) -> str:
    """Creates a composite field name by combining the entity name with a field name.

    Args:
        x: Field name to combine with entity name

    Returns:
        Composite field name in format "entity@field"
    """
    return f"{self.name}@{x}" if self.keep_vertex_name else x

Index

Bases: ConfigBaseModel

Configuration for database indexes.

Attributes:

Name Type Description
name str | None

Optional name of the index

fields list[str]

List of fields to index

unique bool

Whether the index enforces uniqueness; off unless declared

type IndexType

Type of index to create

deduplicate bool

ArangoDB only: whether to deduplicate array index entries

sparse bool

ArangoDB only: whether to leave out documents missing a field

exclude_edge_endpoints bool

Has no effect

Source code in graflo/architecture/graph_types/index_config.py
class Index(ConfigBaseModel):
    """Configuration for database indexes.

    Attributes:
        name: Optional name of the index
        fields: List of fields to index
        unique: Whether the index enforces uniqueness; off unless declared
        type: Type of index to create
        deduplicate: ArangoDB only: whether to deduplicate array index entries
        sparse: ArangoDB only: whether to leave out documents missing a field
        exclude_edge_endpoints: Has no effect
    """

    name: str | None = Field(
        default=None,
        description="Optional index name. For edges, can reference a vertex name for composite fields.",
    )
    fields: list[str] = Field(
        default_factory=list,
        description="List of field names included in this index.",
    )
    unique: bool = Field(
        default=False,
        description=(
            "If True, the index is a uniqueness constraint on the field "
            "combination, and a write repeating a value is rejected."
        ),
    )
    type: IndexType = Field(
        default=IndexType.PERSISTENT,
        description="Index type (PERSISTENT, HASH, SKIPLIST, FULLTEXT).",
    )
    deduplicate: bool = Field(
        default=True,
        description="ArangoDB only: whether to deduplicate array index entries.",
    )
    sparse: bool = Field(
        default=False,
        description="ArangoDB only: if True, leave out documents missing an indexed field.",
    )
    exclude_edge_endpoints: bool = Field(
        default=False,
        description="Has no effect: no backend adds endpoint fields to a declared index.",
    )

    def __iter__(self):
        """Iterate over the indexed fields."""
        return iter(self.fields)

    def db_form(self, db_type: DBType) -> dict:
        """Convert index configuration to database-specific format.

        Args:
            db_type: Type of database (ARANGO or NEO4J)

        Returns:
            Dictionary of index configuration in database-specific format

        Raises:
            ValueError: If db_type is not supported
        """
        r = dict(self.to_dict())
        if db_type == DBType.ARANGO:
            r.pop("name", None)
            r.pop("exclude_edge_endpoints", None)
        return r

Attributes

deduplicate = Field(default=True, description='ArangoDB only: whether to deduplicate array index entries.') class-attribute instance-attribute
exclude_edge_endpoints = Field(default=False, description='Has no effect: no backend adds endpoint fields to a declared index.') class-attribute instance-attribute
fields = Field(default_factory=list, description='List of field names included in this index.') class-attribute instance-attribute
name = Field(default=None, description='Optional index name. For edges, can reference a vertex name for composite fields.') class-attribute instance-attribute
sparse = Field(default=False, description='ArangoDB only: if True, leave out documents missing an indexed field.') class-attribute instance-attribute
type = Field(default=IndexType.PERSISTENT, description='Index type (PERSISTENT, HASH, SKIPLIST, FULLTEXT).') class-attribute instance-attribute
unique = Field(default=False, description='If True, the index is a uniqueness constraint on the field combination, and a write repeating a value is rejected.') class-attribute instance-attribute

Methods:

__iter__()

Iterate over the indexed fields.

Source code in graflo/architecture/graph_types/index_config.py
def __iter__(self):
    """Iterate over the indexed fields."""
    return iter(self.fields)
db_form(db_type)

Convert index configuration to database-specific format.

Parameters:

Name Type Description Default
db_type DBType

Type of database (ARANGO or NEO4J)

required

Returns:

Type Description
dict

Dictionary of index configuration in database-specific format

Raises:

Type Description
ValueError

If db_type is not supported

Source code in graflo/architecture/graph_types/index_config.py
def db_form(self, db_type: DBType) -> dict:
    """Convert index configuration to database-specific format.

    Args:
        db_type: Type of database (ARANGO or NEO4J)

    Returns:
        Dictionary of index configuration in database-specific format

    Raises:
        ValueError: If db_type is not supported
    """
    r = dict(self.to_dict())
    if db_type == DBType.ARANGO:
        r.pop("name", None)
        r.pop("exclude_edge_endpoints", None)
    return r

Weight

Bases: ABCFields

Defines weight configuration for edges.

Attributes:

Name Type Description
map dict

Dictionary mapping field values to weights

filter dict

Dictionary of filter conditions for weights

Source code in graflo/architecture/graph_types/index_config.py
class Weight(ABCFields):
    """Defines weight configuration for edges.

    Attributes:
        map: Dictionary mapping field values to weights
        filter: Dictionary of filter conditions for weights
    """

    map: dict = Field(
        default_factory=dict,
        description="Mapping of field values to weight values for vertex-based edge attributes.",
    )
    filter: dict = Field(
        default_factory=dict,
        description="Filter conditions applied when resolving vertex-based weights.",
    )

Attributes

filter = Field(default_factory=dict, description='Filter conditions applied when resolving vertex-based weights.') class-attribute instance-attribute
map = Field(default_factory=dict, description='Mapping of field values to weight values for vertex-based edge attributes.') class-attribute instance-attribute