API Reference
Protocols
Section titled “Protocols”ChunkerProtocol
Section titled “ChunkerProtocol”Protocol for document chunking strategies.
Implementations split document text into smaller, overlapping or non-overlapping chunks suitable for embedding and retrieval.
Split text into chunks.
| Parameter | Type | Description |
|---|---|---|
| `text` | str | The document text to chunk. |
| `metadata` | dict[str, Any] | None | Optional metadata to attach to each chunk. |
| Type | Description |
|---|---|
| list[Any] | List of Chunk objects. |
Classes
Section titled “Classes”A chunk of text with metadata.
Attributes: text: The chunk text content source: Source document identifier start_index: Starting character position in original document end_index: Ending character position in original document chunk_index: Sequential index of this chunk metadata: Optional metadata dictionary
ChunkingConfig
Section titled “ChunkingConfig”Configuration for chunking.
Example
config = ChunkingConfig(strategy=ChunkingStrategy.FIXED_SIZE,chunk_size=1000,overlap=200)Context
Section titled “Context”Retrieved context for RAG generation.
Example
context = Context(query="What is Oridecon?",documents=[doc1, doc2],metadata={"retrieval_time": 0.123})IngestionConfig
Section titled “IngestionConfig”Configuration for document ingestion stage.
PipelineBuilder
Section titled “PipelineBuilder”Builder for constructing RAG pipelines with fluent API.
The builder provides a convenient way to configure and build pipelines programmatically or from configuration files. Fluent configuration methods live in PipelineConfigWiring; this class owns pipeline assembly.
Initialize the pipeline builder.
Build the RAG pipeline.
| Type | Description |
|---|---|
| RAGPipeline | Configured RAG pipeline |
| Exception | Description |
|---|---|
| ValueError | If configuration is invalid |
PipelineConfig
Section titled “PipelineConfig”Complete pipeline configuration.
RAGAnswerSynthesizedHook
Section titled “RAGAnswerSynthesizedHook”Payload fired after the synthesis stage produces a final answer.
Attributes: pipeline_name: Name or identifier of the pipeline that synthesised the answer.
RAGConfig
Section titled “RAGConfig”Configuration for RAG (Retrieval Augmented Generation) pipeline.
Example
config = RAGConfig(vector_store_type="chroma",collection_name="pet_knowledge",top_k=5,enable_citations=True)Return a copy of this config with a different collection_name.
Usage
tenant_config = base_config.with_collection("canon_t_tenant42")tenant_config = base_config.with_collection("canon_t_tenant42")RAGDocumentsRetrievedHook
Section titled “RAGDocumentsRetrievedHook”Payload fired after the retrieval stage returns candidate chunks.
Attributes: chunk_count: Number of chunks returned by the retrieval step.
RAGModule
Section titled “RAGModule”Retrieval-Augmented Generation (RAG) pipeline integration.
Call configure to register the RAG pipeline, strategy registries, and supporting services (knowledge graph, HyDE, compression, reasoning) for injection.
Usage
from oridecon.ai.rag.config import RAGConfig
@module( imports=[ RAGModule.configure(RAGConfig(chunk_size=512)) ])class AppModule(Module): passfrom oridecon.ai.rag.config import RAGConfig
@module( imports=[ RAGModule.configure(RAGConfig(chunk_size=512)) ])class AppModule(Module): passError Handling
RAG pipeline failures surface as typed exceptions that can be caughtdirectly or handled via the Result pattern::
from oridecon.ai.rag.exceptions import ( RAGError, # base — catch-all PreprocessingError, # document preprocessing failure RetrievalError, # retrieval / vector-store failure SynthesisError, # response synthesis failure ChunkingError, # document chunking failure )RAG pipeline failures surface as typed exceptions that can be caughtdirectly or handled via the Result patternfrom oridecon.ai.rag.exceptions import ( RAGError, # base — catch-all PreprocessingError, # document preprocessing failure RetrievalError, # retrieval / vector-store failure SynthesisError, # response synthesis failure ChunkingError, # document chunking failure) from oridecon.ai.rag.exceptions import ( RAGError, # base — catch-all PreprocessingError, # document preprocessing failure RetrievalError, # retrieval / vector-store failure SynthesisError, # response synthesis failure ChunkingError, # document chunking failure )Exports: RAGPipelineProtocol, RetrievalStrategyProtocol, RAGError, PreprocessingError, RetrievalError, SynthesisError, ChunkingError
Create a RAGModule with explicit configuration.
| Parameter | Type | Description |
|---|---|---|
| `config` | RAGConfig | None | RAGConfig or ``None`` to use defaults (reads from environment variables). |
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule descriptor. |
Create a RAGModule suitable for unit and integration testing.
Uses in-memory or no-op implementations with minimal side effects.
| Parameter | Type | Description |
|---|---|---|
| `config` | RAGConfig | None | Optional config override. Uses safe test defaults when None. |
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule descriptor. |
RAGPipeline
Section titled “RAGPipeline”Main RAG pipeline that orchestrates all stages.
This class provides a simple interface for executing the complete RAG pipeline with configurable stages and error handling.
Initialize the RAG pipeline.
| Parameter | Type | Description |
|---|---|---|
| `config` | PipelineConfig | Pipeline configuration |
| `stages` | list[PipelineStageProtocol] | List of pipeline stages |
| `evaluator` | RAGEvaluatorProtocol | None | Optional evaluator implementing RAGEvaluatorProtocol for automatic per-request quality evaluation. Evaluation frequency is controlled by auto_evaluate_every_n. |
| `working_memory` | WorkingMemoryProtocol | None | Optional working memory for context enrichment. |
Execute the RAG pipeline.
| Parameter | Type | Description |
|---|---|---|
| `query` | str | User query |
| `documents` | list[str] | None | Optional list of document content strings |
| `document_paths` | list[str] | None | Optional list of document file paths |
| `metadata` | dict[str, Any] | None | Optional custom metadata |
| Type | Description |
|---|---|
| PipelineContext | Pipeline context with results |
Execute the RAG pipeline per the contract protocol.
| Parameter | Type | Description |
|---|---|---|
| `context` | RAGContext | Pipeline context with query and optional config/filters. |
| Type | Description |
|---|---|
| Result[RAGResponse, RAGError] | Ok(RAGResponse) on success, Err(RAGError) on failure. |
Execute pipeline stages in parallel.
| Parameter | Type | Description |
|---|---|---|
| `query` | str | User query |
| `stages` | list[PipelineStageProtocol] | None | Stages to execute in parallel (default: all stages) **kwargs: Additional context parameters |
| Type | Description |
|---|---|
| PipelineContext | Pipeline context with results |
RAGPipelineStartedHook
Section titled “RAGPipelineStartedHook”Payload fired when a RAG pipeline begins processing a query.
Attributes: pipeline_name: Name or identifier of the pipeline that started.
RAGProvider
Section titled “RAGProvider”Registers RAG pipeline services and strategy registries with the DI container.
Boot RAG provider — wire optional integrations.
Check RAG provider health — verifies embedding service and vector store.
| Type | Description |
|---|---|
| HealthCheckResult | HealthCheckResult with status ``healthy`` when all configured dependencies are reachable, or ``degraded``/``unhealthy`` otherwise. |
RAGTenancyConfig
Section titled “RAGTenancyConfig”Optional tenant-aware RAG pipeline configuration.
When enabled, the RAG provider wraps the RAGPipelineProtocol binding
in a TenantScopedRAGPipeline that resolves the collection_name
from the current tenant context at request time, with per-tenant
pipeline instance caching.
Note
Requires oridecon-tenancy in the module graph when enabled
is True — the provider resolves Context at boot.
RerankResult
Section titled “RerankResult”Result of a reranking operation.
Attributes: documents: Reranked documents (most relevant first). scores: Relevance scores (parallel to documents). original_count: Number of documents passed to reranker. reranked_count: Number of documents returned (may be < original if top_k applied). model_name: Name of the reranking model used. metadata: Additional reranking metadata.
RerankingStrategyRegistry
Section titled “RerankingStrategyRegistry”Registry of reranking strategy handlers.
Reranking strategies reorder documents after initial retrieval using cross-encoders, LLM-based scoring, or fusion techniques.
Uses a handler-based dispatch pattern where handlers implement can_handle(strategy: str) and create_and_rerank() methods.
Usage
registry = RerankingStrategyRegistry()registry.register(FlashRankStrategyHandler())handler = registry.get("flashrank")result = await handler.create_and_rerank(strategy="flashrank", ...)registry = RerankingStrategyRegistry()registry.register(FlashRankStrategyHandler())handler = registry.get("flashrank")result = await handler.create_and_rerank(strategy="flashrank", ...)Initialize an empty handler registry.
Register a handler instance.
| Parameter | Type | Description |
|---|---|---|
| `handler` | object | A handler instance with can_handle(strategy) method. |
Get a handler that can handle the given strategy.
| Parameter | Type | Description |
|---|---|---|
| `strategy` | str | Strategy name to look up. |
| Type | Description |
|---|---|
| object | None | First handler where can_handle(strategy) is True, or None. |
RetrievalCompletedEvent
Section titled “RetrievalCompletedEvent”Emitted when the retrieval stage of a RAG pipeline completes.
Consumed by: quality metrics, retrieval analytics, feedback loops.
RetrievalConfig
Section titled “RetrievalConfig”Configuration for retrieval stage.
RetrievalStrategyRegistry
Section titled “RetrievalStrategyRegistry”Registry of retrieval strategy implementations.
Strategies take a query and a set of candidate documents and return an ordered subset ranked by relevance.
Usage
registry = RetrievalStrategyRegistry.with_defaults()strategy = registry.instantiate("mmr", lambda_param=0.7)results = await strategy.retrieve(query, candidates, top_k=5)registry = RetrievalStrategyRegistry.with_defaults()strategy = registry.instantiate("mmr", lambda_param=0.7)results = await strategy.retrieve(query, candidates, top_k=5)Declare the built-in retrieval strategies.
| Type | Description |
|---|---|
| dict[str, type] | Mapping of strategy key → class: ``"vector"`` and ``"mmr"``. |
SynthesisCompletedEvent
Section titled “SynthesisCompletedEvent”Emitted when the synthesis stage of a RAG pipeline completes.
Consumed by: quality metrics, answer analytics, audit.
SynthesisConfig
Section titled “SynthesisConfig”Configuration for response synthesis.
Attributes: strategy: Synthesis strategy to use max_context_length: Maximum context length in tokens max_response_length: Maximum response length in tokens include_citations: Whether to include citations output_format: Desired output format quality_check: Whether to run quality checks min_confidence: Minimum confidence threshold metadata: Additional configuration metadata
TenantScopedRAGPipeline
Section titled “TenantScopedRAGPipeline”Resolves per-tenant RAG pipelines at request time.
Caches pipeline instances per tenant with LRU eviction. When no tenant context is available, delegates to a default pipeline built from the base config.
The factory callable receives a tenant-scoped RAGConfig (with
collection_name already resolved) and should return a fully
constructed RAGPipelineProtocol.
Example usage
factory = TenantScopedRAGPipeline( base_config=RAGConfig(collection_name="canon"), resolver=TemplatedTenantCollectionResolver(), ctx=context, pipeline_factory=build_rag_pipeline,)result = await factory.execute(RAGContext(query="..."))factory = TenantScopedRAGPipeline( base_config=RAGConfig(collection_name="canon"), resolver=TemplatedTenantCollectionResolver(), ctx=context, pipeline_factory=build_rag_pipeline,)result = await factory.execute(RAGContext(query="..."))Execute the RAG pipeline with tenant-aware collection resolution.
When a tenant ID is present in the current Context, the
collection_name from base_config is resolved via the
TenantCollectionResolver before delegating to the tenant’s
cached pipeline instance.
| Parameter | Type | Description |
|---|---|---|
| `context` | RAGContext | The RAG execution context. |
| Type | Description |
|---|---|
| Result[RAGResponse, RAGError] | The pipeline result or an error. |
Convenience: execute a query string and return the response.
Builds a RAGContext from question and extra keyword
arguments, then delegates to execute. Raises on error.
| Parameter | Type | Description |
|---|---|---|
| `question` | str | The user query. **kwargs: Additional ``RAGContext`` fields. |
| Type | Description |
|---|---|
| RAGResponse | The RAG response. |
| Exception | Description |
|---|---|
| RAGError | If the pipeline execution fails. |
Functions
Section titled “Functions”create_chunker
Section titled “create_chunker”Create a chunker instance for the given strategy.
Convenience wrapper around ChunkingStrategyRegistry.
| Parameter | Type | Description |
|---|---|---|
| `strategy` | ChunkingStrategy | Which chunking strategy to use. |
| `config` | ChunkingConfig | None | Optional chunking configuration. **kwargs: Additional keyword arguments forwarded to the chunker constructor (override config defaults). |
| Type | Description |
|---|---|
| AbstractChunker | A configured Chunker instance. |
| Exception | Description |
|---|---|
| ValueError | If no chunker is registered for the given *strategy*. |
Exceptions
Section titled “Exceptions”RAGError
Section titled “RAGError”Base exception for RAG errors.