Codex
The central orchestrator for managing entries, relationships, and metadata policies within the Lexicon ecosystem.
Constructor
Codex(repository: Lexicon, policy: CodexPolicy = CodexPolicy())
Initializes the Codex engine with a specific persistence repository and a set of validation policies.
Core Methods
create_entry(...)
Creates, validates, and persists a new Entry. Titles, tags, and categories are automatically sanitized according to the active CodexPolicy.
| Parameter | Type | Description |
|---|---|---|
| title | str | The unique title of the entry. |
| content | str | Main body text. |
| tags | List[str] | Optional list of identifiers. |
edit_entry(entry_id, **changes)
Updates an existing entry. Protects immutable fields (id, created_at) and only triggers an update if data actually changes.
delete_entry(entry_id)
Safely removes an entry from the repository. Returns True if the operation was successful.
Relationship Management
Handles the connections between different entries in the graph.
create_relation(from_id, to_id, connection_type, **kwargs)
Establishes a link between two entries. Validates existence of both points and prevents duplicate relations.
disconnect_entries(from_id, to_id, connection_type)
Breaks the link between two entries. Returns a boolean indicating success.
Grouping & Retrieval
groupBy_relations(entry_id)
Retrieves all connected entries (both incoming and outgoing) as a flat list, treating the relationship as bidirectional and removing duplicates.
groupBy_tags(tag)
Filters the repository for all entries containing the specified tag. The tag is normalized before searching.
groupBy_categories(category)
Filters entries by category name, applying capitalization and whitespace rules before the query.
Internal Validation Rules
Codex enforces several data integrity rules based on the CodexPolicy:
- Title Uniqueness: Controlled via
_rules_title, ensures no two entries share the same name. - Immutability: Fields like
idandcreated_atare blocked during edits. - Normalization: Tags can be forced to lowercase, and categories can be auto-capitalized.
- Reference Breaking: When editing mutable types (lists/dicts), Codex creates copies to ensure no side effects.