Types, schemas, config, formatting¶
Dependency-free utility modules safe to import from a base install:
autorag.types—TypedDictshapes for transcripts and topic trees (WordSpan,TopicDict,TopicTree,TranscriptionResult).autorag.schemas— Pydantic request/response models used by the HTTP API.autorag.config— Settings viapydantic-settings.autorag.blocks— Time-bucketed, speaker-grouped transcript formatter (stdlib only).
Types (autorag.types)¶
Public typed-dict shapes for the audio→topics pipeline.
Kept dependency-free so SDK consumers can reference these types without forcing the optional [audio] / [diarize] extras (langchain, whisper, pyannote) to be importable.
- class autorag.types.WordSpan[source]¶
Bases:
TypedDictOne word emitted by the transcription pipeline.
Keys:
w(word),s/e(start/end seconds),segment_id(Whisper segment id), andspeaker(string id assigned by diarization;"0"when diarization is disabled).
- class autorag.types.TopicTree[source]¶
Bases:
TypedDictContainer returned by
autorag.core.AutoRAG.generate_topics().
Schemas (autorag.schemas)¶
Pydantic request/response and entity models for the RAG pipeline.
These models double as the on-the-wire schema for the HTTP API
(autorag.api) and as the in-process value types passed between
the embedder, store, retriever, and generator.
- class autorag.schemas.Document(**data)[source]¶
Bases:
BaseModelOne ingested source document, before chunking.
- class autorag.schemas.Chunk(**data)[source]¶
Bases:
BaseModelA retrieval-sized piece of a
Document.embeddingis filled in byEmbedderand remainsNoneuntil the chunk has been embedded.- Parameters:
- class autorag.schemas.Retrieved(**data)[source]¶
Bases:
BaseModelA chunk plus its similarity score from a vector-store search.
- class autorag.schemas.QueryResponse(**data)[source]¶
Bases:
BaseModelResponse body for
POST /query: generated answer plus its sources.
- class autorag.schemas.IngestRequest(**data)[source]¶
Bases:
BaseModelRequest body for
POST /ingest: filesystem paths to ingest.
Config (autorag.config)¶
Process-wide settings loaded from environment variables and .env.
Every field is prefixed with AUTORAG_ in the environment — e.g.
AUTORAG_TOP_K=8 overrides Settings.top_k. Unrecognized
variables are ignored so callers can share an environment with other
tools.
- class autorag.config.Settings(_case_sensitive=None, _nested_model_default_partial_update=None, _env_prefix=None, _env_prefix_target=None, _env_file=PosixPath('.'), _env_file_encoding=None, _env_ignore_empty=None, _env_nested_delimiter=None, _env_nested_max_split=None, _env_parse_none_str=None, _env_parse_enums=None, _cli_prog_name=None, _cli_parse_args=None, _cli_settings_source=None, _cli_parse_none_str=None, _cli_hide_none_type=None, _cli_avoid_json=None, _cli_enforce_required=None, _cli_use_class_docs_for_groups=None, _cli_exit_on_error=None, _cli_prefix=None, _cli_flag_prefix_char=None, _cli_implicit_flags=None, _cli_ignore_unknown_args=None, _cli_kebab_case=None, _cli_shortcuts=None, _secrets_dir=None, _build_sources=None, **values)[source]¶
Bases:
BaseSettingsDefault knobs for the RAG pipeline.
- Parameters:
_env_prefix_target (
Optional[Literal['variable','alias','all']])_cli_implicit_flags (
Union[bool,Literal['dual','toggle'],None])_cli_kebab_case (
Union[bool,Literal['all','no_enums'],None])_build_sources (
tuple[tuple[PydanticBaseSettingsSource,...],dict[str,Any]] |None)values (
Any)chunk_size (int)
chunk_overlap (int)
top_k (int)
model (str)
db_path (Path)
broker_url (str)
otel_enabled (bool)
otel_service_name (str)
otel_exporter_endpoint (str)
otel_metric_export_interval_ms (int)
otel_environment (str)
otel_resource_attributes (str)
- model_config: ClassVar[SettingsConfigDict] = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_flag_prefix_char': '-', 'cli_hide_none_type': False, 'cli_ignore_unknown_args': False, 'cli_implicit_flags': False, 'cli_kebab_case': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_shortcuts': None, 'cli_use_class_docs_for_groups': False, 'enable_decoding': True, 'env_file': '.env', 'env_file_encoding': None, 'env_ignore_empty': False, 'env_nested_delimiter': None, 'env_nested_max_split': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': 'AUTORAG_', 'env_prefix_target': 'variable', 'extra': 'ignore', 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'secrets_dir': None, 'toml_file': None, 'validate_default': True, 'yaml_config_section': None, 'yaml_file': None, 'yaml_file_encoding': None}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- broker_url: str¶
RabbitMQ URL for the async pipeline (
autorag.services).Only consulted by the
[broker]async path (workers +/jobs/*endpoints); every synchronous endpoint and CLI command ignores it.
- otel_enabled: bool¶
Master switch for OpenTelemetry traces + metrics. When
False(the default),autorag.otel.initialize_otel()is a no-op and noopentelemetry.*modules are imported.
- otel_service_name: str¶
Base
service.nameresource attribute. Each long-running process (autorag-api/autorag-gpu-worker/autorag-io-worker/autorag-cli) overrides it via the explicitinitialize_otelargument, so this only matters if a caller drops that argument.
- otel_exporter_endpoint: str¶
OTLP/gRPC endpoint for the span + metric exporters. Defaults to the host-side collector port; the compose workers override it to
http://otel-collector:4317overautorag-net.
Block formatter (autorag.blocks)¶
Pure-stdlib transcript-formatting helpers.
Kept dependency-free so a base install (no [audio] / [rag]) can call
format_blocks() on any autorag.types.WordSpan list it already
has — e.g. one loaded straight from the SQLite cache or built externally.
- autorag.blocks.format_blocks(transcription, seconds)[source]¶
Render transcription as N-second time blocks with per-turn speaker lines.
Buckets each
WordSpaninto[floor(s/N)*N, floor(s/N)*N + N). Within each non-empty bucket, groups consecutive same-speaker spans into turns viagroup_by_speaker()and emits one line per turn:MM:SS-MM:SS Speaker K: <words>where K isint(speaker) + 1(1-indexed display; non-numeric labels pass through verbatim). Skips empty buckets; separates non-empty buckets by one blank line. No trailing newline.A turn whose words span multiple buckets produces one line per bucket — each line covers only that bucket’s portion of the turn.
- Raises:
ValueError – if
seconds <= 0.- Parameters:
- Return type: