
LlamaIndex to production RAG pipelines: 2026 workflow
Build a LlamaIndex FastRouter integration for production RAG. Separate retrieval from routing, configure the compatible client, and test failover before release.

Instead of maintaining separate provider clients inside a RAG application, a LlamaIndex FastRouter integration can send answer-generation requests through one OpenAI-compatible gateway. Document ingestion, embeddings, and retrieval stay separate so generation routing can change without rebuilding the index.
TL;DR
- A LlamaIndex FastRouter integration connects RAG answer generation to an OpenAI-compatible gateway while keeping retrieval independently configured.
- FastRouter is best for enterprise teams needing multi-model routing, automatic failover, and usage governance.
- An explicitly configured LlamaIndex client should be used; the gateway base URL and model identifier should be verified before indexing documents.
- Retrieval quality and fallback answers should be evaluated separately before releasing the production RAG pipeline.
Why this matters
A production RAG pipeline has two distinct responsibilities: retrieve useful evidence and generate an answer from that evidence. Changing the generation provider should not require changing how documents are split, how embeddings are created, or how the index is searched.
FastRouter provides a unified, OpenAI-compatible API gateway with automatic failover, cost optimization, and usage governance. Those capabilities belong on the generation path in this workflow; the embedding model and index remain separately configured.
FastRouter is best for enterprise RAG teams that need governed access to multiple generation models through one gateway. The trade-off is an additional routing dependency that needs its own authentication, observability, and failure testing.
For a 2026 deployment, success should mean grounded answers under normal operation and controlled failure when dependencies break — not merely a successful API call.
Before starting
- Gateway access: An authorized API key, the documented OpenAI-compatible API base URL, and an exact generation model identifier permitted for the account are needed. The endpoint path should be confirmed rather than constructed from the website domain.
- Application materials: A Python environment, approved source documents, a writable index directory, and an embedding model authorized for download and deployment should be prepared. Credentials belong in the deployment's secret store.
- The embedding gotcha: The same embedding model and configuration should be used when indexing and querying. Changing the generation model does not require re-embedding; changing the embedding model requires rebuilding the affected index.
The gateway routing policy should also be confirmed to allow every fallback destination to receive the retrieved document content. Provider substitution is a data-governance decision, not just a reliability setting.
Configure the application environment
- Install the LlamaIndex core package, its OpenAI-compatible LLM adapter, and its Hugging Face embedding adapter:
1python -m pip install llama-index-core llama-index-llms-openai-like llama-index-embeddings-huggingface
- Compatible package versions should be resolved in a clean environment, then pinned in the application dependency file. An unpinned installation command should not become the release process.
- Configure these environment variables using real account and deployment values:
Variable | Purpose |
|---|---|
| Gateway authentication secret |
| Documented OpenAI-compatible API base URL |
| Authorized generation model identifier |
| Chosen Hugging Face embedding model identifier |
| Directory containing approved source documents |
| Writable directory for the persisted index |
- Access should be validated from the same environment that will run the application. Outbound connectivity, secret injection, document permissions, and embedding-model download requirements should be checked.
Expected result: The application can resolve every required setting without hard-coded credentials. No request has been sent, and no document has been indexed yet.
The environment-variable names above are application conventions for this guide, not claimed gateway dashboard fields. For a reproducible 2026 release, resolved dependency versions and the embedding-model revision should be recorded alongside the deployment configuration.
Configure retrieval and index persistence
The retrieval path should be built before generation is added. The sequence is Documents, Chunks, Embeddings, then Index; each stage has a different failure surface.

Keep the retrieval index independent of generation routing.
- Create an ingestion script that loads approved documents, explicitly sets the embedding model, and persists the index:
1# ingest.py2import os34from llama_index.core import SimpleDirectoryReader, VectorStoreIndex5from llama_index.core.node_parser import SentenceSplitter6from llama_index.embeddings.huggingface import HuggingFaceEmbedding78embed_model = HuggingFaceEmbedding(9 model_name=os.environ["EMBEDDING_MODEL_NAME"]10)1112documents = SimpleDirectoryReader(13 input_dir=os.environ["DOCUMENT_DIRECTORY"]14).load_data()1516if not documents:17 raise RuntimeError("No source documents were loaded")1819splitter = SentenceSplitter(chunk_size=800, chunk_overlap=80)2021index = VectorStoreIndex.from_documents(22 documents,23 embed_model=embed_model,24 transformations=[splitter],25)2627index.storage_context.persist(28 persist_dir=os.environ["INDEX_DIRECTORY"]29)
- Run ingestion as a separate job:
1python ingest.py
- Representative chunks and their source metadata should be inspected before the index is accepted. Headings, document boundaries, tables, and permission metadata should survive ingestion appropriately.
- An ingestion manifest should be stored with the source version, embedding configuration, splitter settings, and application dependency versions. The persisted index should be treated as sensitive data because it contains document-derived information.
Expected result: A persisted index exists at the configured location, and its chunks contain usable evidence from the intended documents.
The example starts with 800 tokens per chunk and 80 tokens of overlap. These are illustrative configuration values, not benchmark results or universal recommendations. Alternatives should be evaluated against the real document structure and question set.
Local persistence keeps this example readable. It does not implement tenant isolation, distributed storage, or concurrent index-update coordination; those controls should be established before using the same pattern across production workloads.
Configure gateway-backed answer generation
LlamaIndex's OpenAILike adapter supplies the gateway connection explicitly. This FastRouter integration routes generation requests; it does not route the locally configured embedding calls.
- Create a query script that reloads the existing index and supplies the generation client directly:
1# query.py2import os3import sys45from llama_index.core import StorageContext, load_index_from_storage6from llama_index.embeddings.huggingface import HuggingFaceEmbedding7from llama_index.llms.openai_like import OpenAILike89embed_model = HuggingFaceEmbedding(10 model_name=os.environ["EMBEDDING_MODEL_NAME"]11)1213llm = OpenAILike(14 model=os.environ["FASTROUTER_MODEL"],15 api_base=os.environ["FASTROUTER_API_BASE"],16 api_key=os.environ["FASTROUTER_API_KEY"],17 is_chat_model=True,18 is_function_calling_model=False,19 timeout=30.0,20 max_retries=0,21)2223storage_context = StorageContext.from_defaults(24 persist_dir=os.environ["INDEX_DIRECTORY"]25)2627index = load_index_from_storage(28 storage_context,29 embed_model=embed_model,30)3132query_engine = index.as_query_engine(llm=llm)3334question = " ".join(sys.argv[1:]).strip()35if not question:36 raise SystemExit("Pass a question as command-line arguments")3738response = query_engine.query(question)39print(str(response))4041for source in response.source_nodes:42 print(source.node.node_id, source.score)
- Run a question whose answer appears in the approved documents:
1python query.py Summarize the documented escalation procedure
- The gateway should accept the exact model identifier, and the answer should use relevant retrieved evidence. The printed source node identifiers should be compared with the source documents.
- The chosen model's context and output constraints should be verified against the assembled prompts. Adapter metadata and tokenizer behavior should be configured using the documentation for the installed versions; OpenAI model metadata should not be assumed to apply to another model.
Expected result: The persisted index supplies evidence, the gateway handles generation, and the application returns an answer with inspectable source nodes.
The sample sets a 30-second request timeout and disables SDK retries to make initial failure behavior visible. Neither setting is a service guarantee. Production deadlines and retry behavior should be set from the application's latency budget, accounting for gateway failover and any surrounding retries.
The example enables chat behavior and disables function-calling assumptions. Streaming, structured output, and tool-calling support should be verified separately if the application requires them.
Configure release validation
A successful request proves connectivity. It does not prove groundedness, permitted routing, or acceptable degraded behavior.
- Retrieval: A versioned evaluation set should be run against the index before generated answers are judged. Whether the retrieved chunks contain the evidence needed to answer each question should be recorded.
- Generation: Factual support, citation accuracy, completeness, and refusal behavior should be checked for questions the documents cannot answer. Source-node output alone does not prove that every answer claim is supported.
- Validation: Controlled dependency failures should be exercised outside production. Configured fallback destinations should be verified to preserve required data-handling rules and produce acceptable answers with the same retrieved context.
- Release: The index version, generation configuration, routing policy, and evaluation results should be recorded together. Rollback criteria should be defined before switching application traffic.
Expected result: A repeatable release decision rather than an anecdotal demonstration.
For the 2026 rollout, retrieval duration, generation duration, end-to-end latency, errors, and usage should be instrumented separately. The actual responding model should be recorded when that information is exposed by the gateway's documented response or logging mechanism; it should not be inferred from the requested model alone.
Logging raw prompts and retrieved passages by default should be avoided. Redaction and access controls should be established before sensitive document content reaches an observability system.
Refresh the index when documents change
The adjacent workflow is document refresh, not gateway reconfiguration. A full index rebuild or incremental refresh should be chosen based on source identity and update requirements.
Workflow | Best for | Benefit | Trade-off |
|---|---|---|---|
Full index rebuild | Versioned document snapshots and straightforward rollback | Creates a separate index artifact that can be validated before switching | Reprocesses unchanged documents |
Incremental refresh | Sources with stable document identifiers and frequent edits | Updates an existing index without rebuilding every document | Requires explicit deletion handling and update coordination |
For a full rebuild, ingestion should be run against the new source snapshot and written to a separate index directory. The new artifact should be evaluated, the application's configured index location switched through the deployment process, and the previous artifact retained for rollback.
For incremental refresh, stable document identifiers should be assigned, and LlamaIndex's refresh_ref_docs method used with the updated document collection. Deleted source identifiers should be tracked and their indexed content removed explicitly; refreshing the documents still present is not a deletion policy.
The embedding configuration should stay unchanged during an incremental refresh. An embedding-model migration belongs in a separately rebuilt index. Concurrent read and write behavior for the selected storage backend should be validated rather than assuming the local-file example provides safe live updates.
Troubleshooting
Authentication or model errors
The injected API key, the documented API base URL, and the authorized model identifier should be checked. The returned error should be inspected before ingestion code changes; authentication failures do not justify rebuilding the index.
Empty or irrelevant retrieval
Ingestion should be confirmed to have loaded the expected documents, and querying should use the same embedding configuration. Chunks should be inspected directly, then splitting and retrieval settings evaluated. Changing the generation model does not repair missing evidence.
Context-length failures
The complete assembled request should be inspected, including instructions, retrieved chunks, and answer budget. Irrelevant retrieved content or chunk size should be reduced, and model metadata in the adapter verified. A fallback model must also accommodate the request it receives.
Duplicate retries and long waits
Retry behavior should be inventoried across the application, SDK, gateway, and job runner. One end-to-end deadline and bounded retry policy should be established. A timeout does not prove that upstream processing stopped, so repeated requests should be accounted for in usage monitoring.
Fallback answers fail evaluation
Answers should be compared using the same retrieved context across permitted generation routes. Routes that fail acceptance criteria should be removed, or the application contract adjusted and reevaluated. Connectivity alone is not evidence that a fallback model is suitable.
Customizing the workflow
Authorization should move before retrieval. Tenant and document-access restrictions should apply before evidence is selected, not after an answer has already received restricted content.
Retrieved text should be treated as untrusted input. Application instructions should stay separate from document content, prompt-injection cases should be tested, and the generation step should not receive unnecessary tool permissions.
Background ingestion, versioned index artifacts, and evaluation gates can be added next to the deployment pipeline. A 2026 configuration record should tie each release to its dependencies, embedding configuration, source snapshot, and routing policy.
Review your gateway fit
Assess unified model routing, automatic failover, and usage governance for a RAG generation path.
FAQ
How is LlamaIndex connected to FastRouter for production RAG?
LlamaIndex's OpenAILike adapter is configured with an authorized gateway API key, documented API base URL, and generation model identifier. That client is passed to the query engine while embeddings and retrieval are configured separately.
Does this integration send embeddings through the gateway?
No. This workflow uses a separately configured Hugging Face embedding model and sends answer-generation requests through the gateway. An embedding API integration requires its own verified endpoint and compatible client configuration.
Does the index need to be rebuilt when the generation model changes?
No, changing the generation model alone does not require rebuilding the retrieval index. Answer quality and context handling should be reevaluated; the index should be rebuilt when the embedding configuration changes.
Can automatic failover be used without changing the retrieval pipeline?
Yes, generation failover and retrieval can be configured independently. The gateway routing policy, permitted destinations, request compatibility, and fallback answer quality should be verified before the workflow is enabled for production traffic.
Is the persisted local index enough for an enterprise deployment?
Local persistence does not implement enterprise access controls, distributed operation, or coordinated live updates. Storage and deployment controls should meet the required isolation, security, concurrency, and recovery requirements.
What should be tested before releasing this RAG workflow in 2026?
Retrieval relevance, answer grounding, source attribution, permission boundaries, and controlled dependency failures should be tested. The source snapshot, embedding configuration, generation settings, and routing policy should be recorded with the evaluation results.
One last thing
A better fallback model cannot recover evidence that retrieval never supplied. The retrieved context should be preserved in a controlled evaluation artifact, then generation routes compared against that identical evidence. For a 2026 production release, this separates retrieval defects from generation defects and gives every routing change a testable acceptance gate.
Related Articles
.png&w=3840&q=75)
.png&w=3840&q=75)
RBAC on FastRouter: Scoping Models, Budgets, and Keys by Team
Roles, model scopes, and budgets are three separate controls on FastRouter, none of which substitutes for the others. How to set up all three.


Can an LLM gateway support realtime voice over WebSocket?
An LLM gateway supports realtime voice over WebSocket with explicit audio protocol support. Check session control, interruptions, and recovery first.


Does an LLM gateway support virtual model aliases?
LLM gateway virtual model aliases keep application names stable as model targets change. Learn how aliases differ from routing and what to validate.