Models

The Graphora client library uses Pydantic models for type-safe data handling. This page provides a reference for all the data models used in the library.

Core Models

DocumentType

An enumeration of supported document types.

class DocumentType(str, Enum):
    """Document types supported by Graphora."""
    TXT = "txt"
    PDF = "pdf"
    DOCX = "docx"
    CSV = "csv"
    JSON = "json"
    YAML = "yaml"
    XML = "xml"

DocumentMetadata

Metadata for a document.

class DocumentMetadata(BaseModel):
    """Metadata for a document."""
    source: str
    document_type: DocumentType
    tags: List[str] = Field(default_factory=list)
    custom_metadata: Dict[str, Any] = Field(default_factory=dict)

Fields

FieldTypeDescriptionDefault
sourcestrSource identifier for the documentRequired
document_typeDocumentTypeType of the documentRequired
tagsList[str]Tags for categorizing the document[]
custom_metadataDict[str, Any]Custom metadata as key-value pairs{}

DocumentInfo

Information about a document.

class DocumentInfo(BaseModel):
    """Information about a document."""
    filename: str
    size: int
    document_type: DocumentType
    metadata: Optional[DocumentMetadata] = None

Fields

FieldTypeDescriptionDefault
filenamestrName of the document fileRequired
sizeintSize of the document in bytesRequired
document_typeDocumentTypeType of the documentRequired
metadataOptional[DocumentMetadata]Metadata for the documentNone

Ontology Models

OntologyResponse

Response from ontology validation.

class OntologyResponse(BaseModel):
    """Response from ontology validation."""
    id: str

Fields

FieldTypeDescriptionDefault
idstrUnique ID for the validated ontologyRequired

Transformation Models

TransformationStage

Stages of the transformation process.

class TransformationStage(str, Enum):
    """Stages of the transformation process."""
    UPLOAD = "upload"
    PARSING = "parsing"
    EXTRACTION = "extraction"
    VALIDATION = "validation"
    INDEXING = "indexing"
    COMPLETED = "completed"

ResourceMetrics

Resource usage metrics for a transformation.

class ResourceMetrics(BaseModel):
    """Resource usage metrics for a transformation."""
    cpu_percent: float = 0.0
    memory_mb: float = 0.0
    duration_seconds: float = 0.0

Fields

FieldTypeDescriptionDefault
cpu_percentfloatCPU usage percentage0.0
memory_mbfloatMemory usage in megabytes0.0
duration_secondsfloatDuration in seconds0.0

StageProgress

Progress information for a transformation stage.

class StageProgress(BaseModel):
    """Progress information for a transformation stage."""
    stage: TransformationStage
    progress: float = 0.0  # 0.0 to 1.0
    started_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None
    metrics: Optional[ResourceMetrics] = None
    message: Optional[str] = None

Fields

FieldTypeDescriptionDefault
stageTransformationStageThe stage of transformationRequired
progressfloatProgress as a value between 0.0 and 1.00.0
started_atOptional[datetime]When the stage startedNone
completed_atOptional[datetime]When the stage completedNone
metricsOptional[ResourceMetrics]Resource usage metricsNone
messageOptional[str]Status messageNone

TransformStatus

Status of a transformation.

class TransformStatus(BaseModel):
    """Status of a transformation."""
    transform_id: str
    status: str
    progress: float = 0.0  # 0.0 to 1.0
    stage_progress: List[StageProgress] = Field(default_factory=list)
    started_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None
    error: Optional[str] = None
    resource_metrics: Optional[ResourceMetrics] = None

Fields

FieldTypeDescriptionDefault
transform_idstrID of the transformationRequired
statusstrCurrent status (e.g., “PENDING”, “RUNNING”, “COMPLETED”, “FAILED”)Required
progressfloatOverall progress as a value between 0.0 and 1.00.0
stage_progressList[StageProgress]Progress for each stage[]
started_atOptional[datetime]When the transformation startedNone
completed_atOptional[datetime]When the transformation completedNone
errorOptional[str]Error message if the transformation failedNone
resource_metricsOptional[ResourceMetrics]Resource usage metricsNone

TransformResponse

Response from document upload.

class TransformResponse(BaseModel):
    """Response from document upload."""
    id: str
    upload_timestamp: datetime
    status: str
    document_info: DocumentInfo

Fields

FieldTypeDescriptionDefault
idstrID for the transformationRequired
upload_timestampdatetimeWhen the documents were uploadedRequired
statusstrInitial status of the transformationRequired
document_infoDocumentInfoInformation about the uploaded documentsRequired

Merge Models

MergeStatus

Status of a merge process.

class MergeStatus(BaseModel):
    """Status of a merge process."""
    merge_id: str
    status: str
    progress: float = 0.0  # 0.0 to 1.0
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    error: Optional[str] = None
    conflicts_count: int = 0
    resolved_count: int = 0

Fields

FieldTypeDescriptionDefault
merge_idstrID of the merge processRequired
statusstrCurrent status (e.g., “STARTED”, “RUNNING”, “COMPLETED”, “FAILED”)Required
progressfloatProgress as a value between 0.0 and 1.00.0
start_timeOptional[datetime]When the merge startedNone
end_timeOptional[datetime]When the merge completedNone
errorOptional[str]Error message if the merge failedNone
conflicts_countintNumber of conflicts detected0
resolved_countintNumber of conflicts resolved0

MergeResponse

Response from starting a merge process.

class MergeResponse(BaseModel):
    """Response from starting a merge process."""
    merge_id: str
    status: str
    start_time: datetime

Fields

FieldTypeDescriptionDefault
merge_idstrID of the merge processRequired
statusstrInitial status of the mergeRequired
start_timedatetimeWhen the merge startedRequired

ResolutionStrategy

Strategies for resolving conflicts.

class ResolutionStrategy(str, Enum):
    """Strategies for resolving conflicts."""
    ACCEPT = "accept"
    REJECT = "reject"
    MODIFY = "modify"
    MERGE = "merge"

ConflictResolution

Information about a conflict requiring resolution.

class ConflictResolution(BaseModel):
    """Information about a conflict requiring resolution."""
    id: str
    entity_id: str
    entity_type: str
    properties: Dict[str, Any]
    conflict_type: str
    source: Optional[str] = None
    target: Optional[str] = None
    suggested_resolution: Optional[ResolutionStrategy] = None
    confidence: Optional[float] = None

Fields

FieldTypeDescriptionDefault
idstrID of the conflictRequired
entity_idstrID of the entity with the conflictRequired
entity_typestrType of the entityRequired
propertiesDict[str, Any]Properties of the entityRequired
conflict_typestrType of conflictRequired
sourceOptional[str]Source of the conflictNone
targetOptional[str]Target of the conflictNone
suggested_resolutionOptional[ResolutionStrategy]Suggested resolution strategyNone
confidenceOptional[float]Confidence in the suggested resolutionNone

Graph Models

Node

A node in the graph.

class Node(BaseModel):
    """A node in the graph."""
    id: str
    labels: List[str]
    properties: Dict[str, Any]

Fields

FieldTypeDescriptionDefault
idstrUnique ID for the nodeRequired
labelsList[str]Labels (entity types) for the nodeRequired
propertiesDict[str, Any]Properties of the node as key-value pairsRequired

Edge

An edge in the graph.

class Edge(BaseModel):
    """An edge in the graph."""
    id: str
    type: str
    source: str
    target: str
    properties: Dict[str, Any] = Field(default_factory=dict)

Fields

FieldTypeDescriptionDefault
idstrUnique ID for the edgeRequired
typestrType of the edge (relationship type)Required
sourcestrID of the source nodeRequired
targetstrID of the target nodeRequired
propertiesDict[str, Any]Properties of the edge as key-value pairs{}

GraphResponse

Response containing graph data.

class GraphResponse(BaseModel):
    """Response containing graph data."""
    nodes: List[Node] = Field(default_factory=list)
    edges: List[Edge] = Field(default_factory=list)
    total_nodes: Optional[int] = None
    total_edges: Optional[int] = None

Fields

FieldTypeDescriptionDefault
nodesList[Node]List of nodes in the graph[]
edgesList[Edge]List of edges in the graph[]
total_nodesOptional[int]Total number of nodes (for pagination)None
total_edgesOptional[int]Total number of edges (for pagination)None

NodeChange

A change to a node in the graph.

class NodeChange(BaseModel):
    """A change to a node in the graph."""
    id: Optional[str] = None  # None for new nodes
    labels: List[str]
    properties: Dict[str, Any]
    is_deleted: bool = False

Fields

FieldTypeDescriptionDefault
idOptional[str]ID of the node to change (None for new nodes)None
labelsList[str]Labels for the nodeRequired
propertiesDict[str, Any]Properties of the nodeRequired
is_deletedboolWhether the node should be deletedFalse

EdgeChange

A change to an edge in the graph.

class EdgeChange(BaseModel):
    """A change to an edge in the graph."""
    id: Optional[str] = None  # None for new edges
    type: str
    source: str
    target: str
    properties: Dict[str, Any] = Field(default_factory=dict)
    is_deleted: bool = False

Fields

FieldTypeDescriptionDefault
idOptional[str]ID of the edge to change (None for new edges)None
typestrType of the edgeRequired
sourcestrID of the source nodeRequired
targetstrID of the target nodeRequired
propertiesDict[str, Any]Properties of the edge{}
is_deletedboolWhether the edge should be deletedFalse

SaveGraphRequest

Request to save changes to the graph.

class SaveGraphRequest(BaseModel):
    """Request to save changes to the graph."""
    nodes: List[NodeChange] = Field(default_factory=list)
    edges: List[EdgeChange] = Field(default_factory=list)
    version: Optional[int] = None  # For optimistic concurrency control

Fields

FieldTypeDescriptionDefault
nodesList[NodeChange]List of node changes[]
edgesList[EdgeChange]List of edge changes[]
versionOptional[int]Version for optimistic concurrency controlNone

SaveGraphResponse

Response from saving changes to the graph.

class SaveGraphResponse(BaseModel):
    """Response from saving changes to the graph."""
    data: GraphResponse
    messages: Optional[List[str]] = None

Fields

FieldTypeDescriptionDefault
dataGraphResponseUpdated graph dataRequired
messagesOptional[List[str]]Messages from the serverNone

Next Steps