Configuration
This section contains auto-generated documentation for configuration modules.
Config Module
Pydantic models for service configuration.
- class routir.config.config.ServiceConfig(*, name, engine, config, processor='BatchQueryProcessor', cache=-1, batch_size=32, cache_ttl=600, max_wait_time=0.05, cache_key_fields=<factory>, cache_redis_url=None, cache_redis_kwargs=<factory>, scoring_disabled=False)[source]
Bases:
BaseModelConfiguration for a single search or ranking service.
One
ServiceConfigentry in the"services"list corresponds to one loaded engine, one search processor, and optionally one scoring processor registered inProcessorRegistry.Example JSON:
{ "name": "my-retriever", "engine": "Qwen3", "config": { "index_path": "/data/qwen3-index", "embedding_model_name": "Qwen/Qwen3-Embedding-8B" }, "cache": 4096, "cache_ttl": 600, "batch_size": 16, "max_wait_time": 0.05 }
- name
Service identifier used in API requests (the
"service"field) and as the key inProcessorRegistry.- Type:
- engine
Class name of the
Enginesubclass to instantiate. Must be importable at startup — either a built-in engine or one loaded viafile_imports.- Type:
- config
Engine-specific parameters passed as
config=to the engine constructor. Content varies by engine; see the engine’s__init__for accepted keys. The special key"index_path"with thehfds:<repo>prefix triggers automatic download from Hugging Face Datasets.- Type:
- processor
Class name of the
BatchProcessorsubclass for the search role. Default"BatchQueryProcessor"works for most engines. Override only if you need custom batching or request logic.- Type:
- cache
In-memory LRU cache size for search results (number of entries).
-1(default) disables the cache entirely. Ignored whencache_redis_urlis set.- Type:
- cache_ttl
Cache entry time-to-live in seconds (default 600). Applies to both LRU and Redis caches.
- Type:
- batch_size
Maximum requests accumulated into one batch before the engine processes them (default 32).
- Type:
- max_wait_time
Maximum seconds to wait for a batch to fill before processing a partial batch (default 0.05 s). Lower values reduce latency; higher values improve GPU utilisation.
- Type:
- cache_key_fields
Request fields included in the cache key. Default
["query", "limit"]. Add extra fields (e.g."subset") whenever they affect the results.
- cache_redis_url
Redis connection URL for distributed caching (e.g.
"redis://localhost:6379"). When set, Redis replaces the in-memory LRU cache.- Type:
str, optional
- cache_redis_kwargs
Additional keyword arguments forwarded to the Redis client (e.g.
{"password": "…", "db": 1}).- Type:
dict, optional
- scoring_disabled
When
True, the scoring/reranking processor for this service is not registered even if the engine implementsscore_batch. Useful when you want search-only access to an engine that also supports reranking.- Type:
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class routir.config.config.CollectionConfig(*, name, doc_path=None, processor='ContentProcessor', offset_source='offsetfile', id_field='id', content_field='text', id_to_lang_mapping=None, cache_path=None, force_load_all_documents=False)[source]
Bases:
BaseModelConfiguration for a document collection.
Collections expose the
/contentendpoint and are used by reranking pipeline stages to fetch document text by ID.Note
The class name has a historical typo (three
ls). It is kept as-is to avoid breaking existing imports.Example JSON:
{ "name": "my-corpus", "doc_path": "/data/corpus.jsonl", "id_field": "docid", "content_field": "text" }
- name
Collection identifier used in API requests (the
"collection"field) and as the key inProcessorRegistry.- Type:
- doc_path
Path to the JSONL (or gzip-compressed) document file. Each line must be a JSON object. May be a local path or an
hfds:<repo>URL for Hugging Face Datasets.- Type:
str, optional
- processor
Class name of the content-processor to use. Default
"ContentProcessor"provides offset-based random access. Use"IRDSProcessor"to load from anir_datasetsdataset ID.- Type:
- offset_source
Strategy for random document access:
"offsetfile"(default) — builds a byte-offset map (.offsetmapsidecar file) for fast O(1) lookup in a JSONL file."msmarco_seg"— reads from sharded gzipped files in the MSMARCO v2.1 segmented document format, using embedded byte offsets from the document ID.
- Type:
- content_field
JSON key(s) whose values are concatenated (space-joined) to form the document text returned by
/content. Accepts a single string or a list for multi-field concatenation (e.g.["title", "body"]). Always stored as a list internally after validation.
- id_to_lang_mapping
Path to a pickle file mapping document IDs to language codes. Used by processors that serve multilingual corpora.
- Type:
str, optional
- cache_path
Directory for the
.offsetmapcache file. Defaults to the same directory asdoc_path.- Type:
str, optional
- force_load_all_documents
When
True, all documents are loaded into memory at startup for maximum throughput. Only suitable for small corpora; defaultFalseuses on-demand offset-based access.- Type:
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class routir.config.config.Config(*, services=<factory>, collections=<factory>, server_imports=<factory>, file_imports=<factory>, dynamic_pipeline=True, pipeline_aliases=<factory>)[source]
Bases:
BaseModelTop-level configuration for the RoutIR service.
Passed as a JSON file (or JSON string) to
routir <config.json>. Parsed byload_config(), which initialises all collections and services and registers them withProcessorRegistry.Example JSON skeleton:
{ "file_imports": ["./my_engine.py"], "collections": [ { "name": "my-corpus", "doc_path": "/data/corpus.jsonl" } ], "services": [ { "name": "my-retriever", "engine": "MyEngine", "config": {"index_path": "/data/index"} } ], "server_imports": ["http://other-host:5000"] }
- services
Search/ranking services to load and register. Each entry loads one engine and creates its processors.
- Type:
- collections
Document collections to register as content services. Required for reranking pipeline stages.
- Type:
- server_imports
URLs of remote RoutIR servers whose services are proxied locally via
Relay. Discovered automatically from each server’s/availendpoint at startup.
- file_imports
Paths to Python files loaded before any service is initialised. Use this to register custom
Enginesubclasses.
- dynamic_pipeline
When
True(default), the/pipelineendpoint accepts arbitrary pipeline DSL strings at request time. Set toFalseto restrict the server to pre-defined services only.- Type:
- pipeline_aliases
Named shortcuts for pipeline DSL fragments. An alias is a single identifier that expands to a (possibly multi-stage) pipeline at request time. Aliases may reference other aliases; cycles raise an error at startup. Each alias name must not collide with any service or collection name.
Example:
{ "ragtime2": "{zho%100, rus%100, spa%100, eng%100}ScoreFusion", "ragtime2-rr": "ragtime2%100 >> nemotron%20" }
With these aliases,
ragtime2%20expands to{zho%100, rus%100, spa%100, eng%100}ScoreFusion%20(the call-site limit is applied to the last stage of the alias body).
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- services: List[ServiceConfig]
- collections: List[CollectionConfig]
Config Loader
- async routir.config.load.auto_add_relay_services(servers)[source]
Discover and register services from remote RoutIR servers as local proxies.
Queries each server’s
/availendpoint to list its available services, then createsRelay-backed processors for every service not already registered locally. This lets the local server transparently forward requests to the remote server.Only
"search"and"score"service types are proxied. Services already registered locally take precedence (remote services with the same name are skipped).
- routir.config.load.load_index_from_hfds(repo_id)[source]
Download an index from HuggingFace Datasets.
- Parameters:
repo_id (str) – Repository ID (with optional ‘hfds:’ prefix)
- Returns:
Path to the downloaded index directory
- async routir.config.load.load_config(config)[source]
Parse the service configuration and register all collections and services.
This is the main initialization entry point called by the server at startup. It performs the following steps in order:
Parse the JSON config (file path or raw string) into a
Configmodel.Load any Python files listed in
file_imports(custom engine classes).For each collection, create and register a content processor.
For each service, instantiate the engine and register search (and optionally score) processors. Index paths with the
hfds:prefix are downloaded from Hugging Face Datasets first.Discover and proxy services from remote servers listed in
server_imports.
- Parameters:
config (str) – Either a file path to a JSON config file or a raw JSON string. File paths are read and parsed automatically.
Note
This function modifies the global
ProcessorRegistrysingleton in place. It is not safe to call concurrently.