Skip to content

Models

pgraf.models

Edge

Bases: _GraphModel

An edge represents the relationship between two nodes

Source code in pgraf/models.py
class Edge(_GraphModel):
    """An edge represents the relationship between two nodes"""

    source: uuid.UUID
    target: uuid.UUID

Embedding

Bases: BaseModel

An embedding is a fixed-length vector of floating-point numbers that represents the semantic meaning of a document chunk in a high-dimensional space, enabling similarity search operations for retrieving contextually relevant information in RAG systems.

Source code in pgraf/models.py
class Embedding(pydantic.BaseModel):
    """An embedding is a fixed-length vector of floating-point numbers that
    represents the semantic meaning of a document chunk in a high-dimensional
    space, enabling similarity search operations for retrieving contextually
    relevant information in RAG systems."""

    node: uuid.UUID
    chunk: int
    value: list[float]

    @pydantic.field_validator('value')
    @classmethod
    def validate_value_length(cls, value: list[float]) -> list[float]:
        """Validate that the embedding value has exactly 384 dimensions."""
        if len(value) != 384:
            raise ValueError(
                f'Value must have exactly 384 dimensions, got {len(value)}'
            )
        return value

validate_value_length(value) classmethod

Validate that the embedding value has exactly 384 dimensions.

Source code in pgraf/models.py
@pydantic.field_validator('value')
@classmethod
def validate_value_length(cls, value: list[float]) -> list[float]:
    """Validate that the embedding value has exactly 384 dimensions."""
    if len(value) != 384:
        raise ValueError(
            f'Value must have exactly 384 dimensions, got {len(value)}'
        )
    return value

Node

Bases: _GraphModel

A node represents an entity or object within the graph model.

Source code in pgraf/models.py
class Node(_GraphModel):
    """A node represents an entity or object within the graph model."""

    id: uuid.UUID = pydantic.Field(default_factory=utils.uuidv7)
    mimetype: str | None = None
    content: str | None = None

SearchResult

Bases: Node

Used for the return results of a search

Source code in pgraf/models.py
class SearchResult(Node):
    """Used for the return results of a search"""

    similarity: float