Files
semantica/docs/reference/utils.md
T
KaifAhmad1andClaude Sonnet 4.6 946a1089c8 docs: premium redesign — Mintlify v4, dark/cream theme, full module coverage
- Migrate from mint.json to docs.json (Mintlify v4)
- Theme: maple, emerald green + near-black dark / cream light palette
  (#059669 primary, #0A0A0A dark bg, #FAF7F0 light bg)
- Typography: Lexend headings, Inter body
- 5-tab navigation: Documentation, Quick Start, API Reference, Cookbook, FAQ
- Homepage: removed badge stickers, redundant h2, added blockquote tagline,
  full 27-module reference table with semantica.mcp_server added
- quickstart.md: CodeGroup per pipeline step, pattern vs LLM options,
  AccordionGroup for patterns and troubleshooting
- faq.md: full AccordionGroup structure across 5 sections
- reference/explorer.md: NEW — FastAPI explorer, Ontology Hub, Distance
  Intelligence, CLI reference, REST API endpoints
- reference/mcp_server.md: NEW — MCP stdio server, 12 tools with I/O
  examples, 3 resources, Claude Desktop/VS Code/Windsurf/Cline config
- docs.json: explorer added to Output group, mcp_server to Utilities group
- Chat, feedback (thumbs/suggest/raise), OG/Twitter metadata, search topbar
- All reference pages reformatted with Mintlify JSX components

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 21:52:50 +05:30

132 lines
3.2 KiB
Markdown

---
title: "Utils Module"
description: "Shared utilities for logging, validation, error handling, progress tracking, and common operations."
icon: "wrench"
---
> Internal utilities used across all Semantica modules — logging, validation, error handling, and helpers.
---
## Overview
The Utils module provides shared infrastructure used throughout Semantica. You typically won't call it directly, but its APIs are available when you need fine-grained control.
<CardGroup cols={3}>
<Card title="Logging" icon="terminal">
Structured logging with performance decorators and quality tracking.
</Card>
<Card title="Error Handling" icon="circle-exclamation">
Custom exception hierarchy and standardized error formatting.
</Card>
<Card title="Validation" icon="circle-check">
Data validation for entities, relationships, and configuration.
</Card>
<Card title="Progress Tracking" icon="clock">
Track long-running operations in console, Jupyter, or file output.
</Card>
<Card title="Helpers" icon="toolbox">
Text cleaning, hashing, and safe file operations.
</Card>
<Card title="Type Definitions" icon="code">
Shared TypedDicts and Enums for type safety across modules.
</Card>
</CardGroup>
---
## Logging
```python
from semantica.utils import setup_logging, get_logger, log_performance
setup_logging(level="INFO") # "DEBUG" | "INFO" | "WARNING" | "ERROR"
logger = get_logger(__name__)
@log_performance
def process_data(data):
logger.info(f"Processing {len(data)} items")
```
```bash
export SEMANTICA_LOG_LEVEL=DEBUG
export SEMANTICA_LOG_FORMAT=json # "json" | "text"
export SEMANTICA_PROGRESS_BAR=true
```
---
## Validation
```python
from semantica.utils import validate_entity, validate_config, ValidationError
try:
validate_entity({"id": "1", "type": "PERSON", "text": "Alice"})
except ValidationError as e:
print(f"Invalid entity: {e}")
```
| Function | Description |
|----------|-------------|
| `validate_entity(data)` | Check entity structure |
| `validate_config(cfg)` | Check configuration dict |
---
## Progress Tracking
```python
from semantica.utils import track_progress
for item in track_progress(items, desc="Processing documents"):
process(item)
```
Supports console (tqdm), Jupyter notebooks, and file logging automatically.
---
## Helper Functions
```python
from semantica.utils import clean_text, hash_data, safe_filename
clean = clean_text(" Hello World ") # "Hello World"
uid = hash_data({"key": "value"}) # SHA-256 hex digest
fname = safe_filename("My File?.txt") # "My_File_.txt"
```
---
## Exception Hierarchy
```python
from semantica.utils import SemanticaError, ValidationError, ProcessingError
try:
...
except ValidationError as e:
# Input data did not pass validation
...
except ProcessingError as e:
# Failure during extraction or graph construction
...
except SemanticaError as e:
# Catch-all for all framework errors
...
```
---
## See Also
<CardGroup cols={2}>
<Card title="Core" icon="gear" href="core">
Framework orchestration that uses Utils internally.
</Card>
<Card title="Pipeline" icon="arrows-turn-to-dots" href="pipeline">
Uses ProgressTracker for step-level tracking.
</Card>
</CardGroup>