Skip to content

API Reference parrot.knowledge.ontology.mixin

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.ontology.mixin

View source

OntologyRAGMixin — agent mixin for ontological graph RAG.

Agents opt-in to ontology-enriched RAG by inheriting this mixin. The mixin hooks into the agent's ask() flow, intercepting queries before standard RAG processing to enrich context with structural graph data.

Usage::

class MyAgent(OntologyRAGMixin, BasicAgent):
    pass

Return Type

ontology_process now returns a ContextEnvelope wrapping an optional EnrichedContext. Callers must read result.context instead of accessing EnrichedContext fields directly. The full state set is:

  • "ok" — happy path; result.context is populated.
  • "ambiguous" — entity resolver found multiple candidates; result.clarification carries rule, mention, and candidates for the chat layer to ask the user.
  • "entity_not_found" — resolver found no match for a required rule.
  • "denied" — AuthorizationChecker denied the request; result.denial_reason describes why.
  • "auth_required" — ToolCallDispatcher raised AuthorizationRequired; result.auth_prompt contains auth_url, provider, and scopes.
  • "render_error" — Jinja2 template rendering failed; result.error has the diagnostic message.
  • "vector_only" — returned as an ok-ish fallback when graph processing is skipped (no pattern match, graph unavailable, etc.).
  • "disabled" — ontology RAG is globally disabled.
  • "not_configured" — tenant_manager was not provided to the mixin.

AQL Bind-Key Convention

When entity extraction resolves a rule named target_employee, the resolved _id is injected into intent.params under the key target_employee_id (rule name + "_id" suffix). Pattern authors must declare their AQL @target_employee_id bind parameter accordingly.

4-Level Degradation Chain (FEAT-159)

For the authoritative_doc_for_topic pattern the traversal section runs a 4-level degradation chain. For all other patterns only levels 3-4 (vector fallback) are added on top of the existing single-traversal logic.

context.source values produced by the chain:

  • "graph:primary" — primary-authority graph traversal succeeded.
  • "graph:secondary" — secondary-authority graph traversal succeeded.
  • "vector:filtered" — similarity_search with doc_type filter succeeded.
  • "vector:plain" — unfiltered similarity_search succeeded.
  • "ontology" — normal (non-authority) graph traversal succeeded.
  • "vector_only" — all graph paths were empty/unavailable; falls back to vector store without graph context.

Alias AuthorizationChecker

Re-exported from parrot.knowledge.ontology.authorization.AuthorizationChecker.

Alias AuthorizationRequired

Re-exported from parrot.auth.exceptions.AuthorizationRequired.

Alias ContextEnvelope

Re-exported from parrot.knowledge.ontology.schema.ContextEnvelope.

Alias DynamicQuery

Re-exported from parrot.knowledge.ontology.contracts.DynamicQuery.

Alias EnrichedContext

Re-exported from parrot.knowledge.ontology.schema.EnrichedContext.

Alias EntityAmbiguityError

Re-exported from parrot.knowledge.ontology.entity_resolver.EntityAmbiguityError.

Alias EntityNotFoundError

Re-exported from parrot.knowledge.ontology.entity_resolver.EntityNotFoundError.

Alias EntityResolver

Re-exported from parrot.knowledge.ontology.entity_resolver.EntityResolver.

Alias OntologyCache

Re-exported from parrot.knowledge.ontology.cache.OntologyCache.

Alias OntologyIntentResolver

Re-exported from parrot.knowledge.ontology.intent.OntologyIntentResolver.

Class OntologyRAGMixin

Mixin that adds Ontological Graph RAG capabilities to any agent.

Class-level constants

FILTERED_VECTOR_DOC_TYPES: doc_type values used in Level-3 degradation (filtered vector RAG). Coupled to the ontology's authority document taxonomy — change here when the knowledge.ontology.yaml adds new authority doc_type values.

The mixin orchestrates the full ontology pipeline:

1. Resolve tenant → merged ontology.
2. Resolve intent (fast path or LLM path).
3. **[NEW]** Extract + resolve named entities from the query.
4. **[NEW]** Evaluate declarative authorization rules.
5. Execute graph traversal if needed (existing).
6. Apply post-action (vector_search, tool_call, or none).
7. Cache the result.

Graceful degradation: if ArangoDB is unavailable, logs a warning and returns ContextEnvelope(state="ok", context=EnrichedContext(source="vector_only")) without raising.

Parameter Type Default Description
tenant_manager TenantOntologyManager | None None TenantOntologyManager instance.
graph_store OntologyTraversalStore | None None OntologyTraversalStore instance.
vector_store Any None Existing PgVector store for post-action vector search.
cache OntologyCache | None None OntologyCache instance (Redis-backed).
llm_client Any None LLM client for intent resolver's LLM path.
tool_manager Any None ToolManager instance for ToolCallDispatcher resolution.
**kwargs Any {}

Attributes:

Attribute Type Description
FILTERED_VECTOR_DOC_TYPES tuple[str, ...]

Method OntologyRAGMixin.ontology_process

Process a query through the ontology pipeline.

Merges user_context with _get_permission_context() so that agent subclasses can inject extra session data without modifying the call site.

ontology_process(query: str, user_context: dict[str, Any], tenant_id: str, domain: str | None = None) -> ContextEnvelope

Parameter Type Default Description
query str The user's natural language query.
user_context dict[str, Any] Session data (user_id, channel, roles, …).
tenant_id str Tenant identifier.
domain str | None None Optional domain for ontology resolution.

Returns: ContextEnvelope — ContextEnvelope describing the pipeline outcome. Always one of: "ok", "ambiguous", "entity_not_found", "denied", "auth_required", "render_error", "vector_only", "disabled", or "not_configured".

Alias OntologyTraversalStore

Re-exported from parrot.knowledge.ontology.contracts.OntologyTraversalStore.

Alias RenderError

Re-exported from parrot.knowledge.ontology.tool_dispatcher.RenderError.

Alias ResolvedIntent

Re-exported from parrot.knowledge.ontology.schema.ResolvedIntent.

Alias TenantOntologyManager

Re-exported from parrot.knowledge.ontology.tenant.TenantOntologyManager.

Alias ToolCallDispatcher

Re-exported from parrot.knowledge.ontology.tool_dispatcher.ToolCallDispatcher.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally