Skip to content

Reference

Complete API reference and architecture overview for Integradio.

SemanticBlocks is the main entry point. It extends gr.Blocks with a component registry and embedding pipeline.

from integradio import SemanticBlocks
with SemanticBlocks(
db_path=None, # SQLite path (None = in-memory)
cache_dir=None, # Embedding cache directory
ollama_url="http://localhost:11434", # Ollama server URL
embed_model="nomic-embed-text", # Embedding model name
) as demo:
...
MethodReturnsDescription
search(query, k=10)list[SearchResult]Semantic search across all registered components
find(query)SearchResultGet the single most relevant component
trace(component)TraceResultGet upstream/downstream dependency chain
map()dictExport graph as D3.js-compatible JSON
describe(component)dictFull metadata dump for a component
summary()strText report of all registered components
add_api_routes(app)NoneMount FastAPI routes on a FastAPI/Starlette app
@dataclass
class SearchResult:
id: str # Component ID
label: str # Gradio label
type: str # Component type name (e.g., "Textbox")
intent: str # Semantic intent string
score: float # Cosine similarity (0.0 to 1.0)
tags: list[str] # Metadata tags
metadata: dict # Additional metadata from specialized wrappers
@dataclass
class TraceResult:
component: SearchResult # The traced component
upstream: list[SearchResult] # Components that feed into this one
downstream: list[SearchResult] # Components that this one feeds into
events: list[EventInfo] # Event connections (click, change, etc.)

Integradio consists of four core subsystems:

┌─────────────────────────────────────────┐
│ SemanticBlocks │
│ (extends gr.Blocks with registry) │
├──────────┬──────────┬───────────────────┤
│ Embedder │ Registry │ Event Introspect │
│ (Ollama) │ (HNSW) │ (dataflow graph) │
└──────────┴──────────┴───────────────────┘

The embedder communicates with Ollama to generate vector representations of intent strings.

  • Model: nomic-embed-text (768 dimensions, default)
  • Protocol: HTTP POST to http://localhost:11434/api/embeddings
  • Caching: Optional on-disk cache to avoid re-embedding identical strings
  • Resilience: Circuit breaker protects against Ollama downtime
# The embedder is created automatically by SemanticBlocks
# You rarely need to interact with it directly
from integradio.embedder import OllamaEmbedder
embedder = OllamaEmbedder(
url="http://localhost:11434",
model="nomic-embed-text",
cache_dir="./cache",
)
vector = embedder.embed("user enters search terms")
# Returns: numpy array of shape (768,)

The registry stores component metadata and their vector embeddings. It uses HNSW (Hierarchical Navigable Small World) for approximate nearest-neighbor search.

  • Vector index: HNSW via hnswlib (in-process, no external service)
  • Metadata store: SQLite (in-memory by default, optionally persisted to disk)
  • Search: Cosine similarity with configurable k parameter
from integradio.registry import ComponentRegistry
registry = ComponentRegistry(db_path="components.db")
# Register a component
registry.add(
id="comp_001",
label="Search Query",
component_type="Textbox",
intent="user enters search terms",
vector=embedder.embed("user enters search terms"),
tags=["input", "text"],
)
# Search
results = registry.search(query_vector, k=10)

The circuit breaker protects against Ollama failures (server down, model not loaded, timeout).

States:
CLOSED → Normal operation. Requests pass through.
OPEN → Ollama is down. Requests fail immediately (no waiting).
HALF → Testing recovery. One request allowed through.

Thresholds:

ParameterDefaultDescription
failure_threshold5Failures before opening circuit
recovery_timeout30sTime before trying again (OPEN → HALF)
success_threshold2Successes in HALF before closing

When the circuit is open, semantic() calls still work — the component is registered without an embedding and will be embedded when the circuit closes.

Integradio inspects Gradio event listeners to build a dataflow graph:

# When you write:
search_btn.click(fn=search, inputs=query, outputs=results)
# Integradio records:
# Edge: query → search_btn (input to click handler)
# Edge: search_btn → results (click handler output)

This graph powers demo.trace(), demo.map(), and all visualization exports.

For real-time applications, Integradio provides an event system with WebSocket support:

from integradio.events import EventMesh
mesh = EventMesh(secret="your-hmac-secret")
# Subscribe to component changes
@mesh.on("component.updated")
async def handle_update(event):
print(f"Component {event.component_id} updated")
# Events are HMAC-signed for integrity
mesh.emit("component.updated", {
"component_id": "comp_001",
"new_intent": "user types a search query",
})

Event types:

EventTrigger
component.registeredNew component added to registry
component.updatedComponent metadata changed
component.searchedSearch query executed
graph.changedEvent listener added/removed
circuit.openedCircuit breaker tripped
circuit.closedCircuit breaker recovered

Integradio is a local-first library. It does not phone home, collect telemetry, or send data to external services.

AspectScope
NetworkLocal Ollama only (localhost:11434)
StorageIn-memory HNSW + optional SQLite file
File systemOptional embedding cache directory
TelemetryNone
Cloud APIsNone
SecretsHMAC secret for event signing (optional, user-provided)

For the full security policy, see SECURITY.md in the repository.