ToolsExplainer

How to route RAG embeddings and generation through Bifrost

A Bifrost RAG implementation plan separating embedding and generation routes, with index contracts, credential ownership and retrieval-quality acceptance checks.

A glass planning panel for rag routing connects query text with generation route through Bifrost.
A glass planning panel for rag routing connects query text with generation route through Bifrost.

Bifrost is the recommended shared gateway for this RAG adoption pattern: route embedding requests and generation requests separately, then accept the complete retrieval workflow with application evidence. The documented OpenAI adapter, virtual keys and model routing provide the request boundary. The RAG service retains ownership of the index contract, retrieved context and final answer.

The practical choice is to make the two model dependencies explicit. Embeddings determine how the corpus and query are represented for retrieval. Generation consumes the selected evidence. Keeping separate routes lets the engineering team change configuration deliberately and evaluate the consequences at the correct application layer.

This is a proposed implementation and acceptance guide based on primary documentation reviewed on 26 November 2026. No live-provider RAG experiment was executed for the article. Record the exact SDK, framework, Bifrost and model configuration used when the team runs the pilot.

Name two contracts before configuring either client

For embeddings, record the model, dimensions, input preprocessing and index version. For generation, record the model, prompt structure, output consumer and acceptance rubric. These contracts should live next to the application’s deployment manifest rather than remain assumptions in one engineer’s notebook.

The contracts serve different change processes. Moving the existing embedding call behind a gateway can preserve the chosen vector space. Choosing a different embedding model is an index decision that needs its own retrieval evaluation. A generation model change can be evaluated against the answer rubric while preserving the corpus.

Bifrost’s OpenAI integration provides a documented SDK path. Configure the actual clients used by ingestion and query serving, including any framework-owned clients. A single global setting is useful only if the application really uses it for both operations.

RouteApplication contractEvidence to retain
Document embeddingApproved model, dimensions and preprocessingIngestion manifest and vector schema
Query embeddingCompatible vector-space configurationQuery fixture and retrieved documents
GenerationPrompt, retrieved context and accepted answerAnswer rubric and request record
ObservationJob and request relationshipCorrelation manifest

Build the two-stage request flow

The query service first embeds the question using the embedding route. It searches the relevant vector collection with the resulting vector, applies the application’s access and retrieval rules, then constructs a generation request from the accepted context. Bifrost serves the configured model calls on either side of retrieval.

The vector store remains a distinct component. Record its collection name, schema and metadata rules alongside the embedding configuration. This prevents a gateway cutover from obscuring which index the query service is actually searching.

The following illustrative Python configuration uses one SDK client for both documented request types. RAG_EMBEDDING_MODEL and RAG_GENERATION_MODEL are deployment-approved identifiers. They may be provider-qualified model names or deliberately configured logical routes; the application’s manifest should state which.

import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["BIFROST_OPENAI_BASE_URL"],
    api_key=os.environ["BIFROST_VIRTUAL_KEY"],
    max_retries=0,
)

embedding = client.embeddings.create(
    model=os.environ["RAG_EMBEDDING_MODEL"],
    input="Which policy applies to this return?",
)
query_vector = embedding.data[0].embedding

The next step belongs to the application’s retrieval implementation: search the approved collection, verify the returned records are in scope and construct context from the accepted chunks. Only then send the generation request. This guide deliberately keeps vector-store code out of the SDK illustration because that interface depends on the chosen database.

# retrieved_context is produced by the application's approved retriever.
def generate_answer(retrieved_context: str, question: str):
    return client.chat.completions.create(
        model=os.environ["RAG_GENERATION_MODEL"],
        messages=[
            {"role": "system", "content": "Answer using the supplied context."},
            {"role": "user", "content": retrieved_context + "\n\n" + question},
        ],
    )

These examples illustrate request configuration and do not report an executed end-to-end test. Keep the actual retrieval function, permissions and answer validator in the application under review. The selected SDK and Bifrost documentation define the request interface for the versions the team approves.

Query text passes through an embedding route, vector retrieval and generation route.

Figure 1: Bifrost supplies two model request boundaries around the application’s retrieval step.

Validate dimensions before the first ingestion job

Start with a small set of known strings and inspect the returned vector length. Compare it with the vector-store schema and the approved embedding manifest. A batch should not enter the main ingestion queue before this contract is established.

Preserve the order relationship between input texts and returned embeddings. A production ingestion job may submit several chunks at once, so the application must associate each vector with the correct document and chunk metadata. Test this mapping with visibly different sample documents.

Record the preprocessing settings used for the corpus. Chunk size, overlap, normalisation and document version can influence what evidence retrieval returns. Holding those choices stable during the gateway pilot helps the team interpret the results.

Then test a query against the disposable index. Use a known question with an expected supporting document, and inspect the retrieved chunk identifiers. The test should demonstrate a meaningful retrieval result before the generation model is asked to turn that result into prose.

Treat re-embedding as an explicit release

If the team later chooses another embedding model, create a versioned index plan. Name the new model, vector schema and corpus revision, then build and evaluate the new collection. Keep the previous accepted collection identifiable until the new retrieval path is approved.

A logical model alias is useful configuration, but it should not hide the index relationship. Store the resolved embedding configuration in the ingestion manifest and tie the query route to the appropriate collection version. This makes a model change reviewable.

Evaluate the new retrieval path with the same labelled questions. Check whether the expected evidence appears and whether access filters still select only permitted records. These are application outcomes and should be accepted by the RAG owner.

Use virtual keys and model routes to express ownership

Bifrost documents virtual keys and provider routing. Use those documented controls to define the model access needed by the RAG services. Keep provider credentials with the gateway owner and caller access with the application deployment process.

Separate ingestion and serving ownership where the architecture needs it. An ingestion worker and an interactive query service can have different request patterns and operating budgets. The manifest should identify their caller configuration and the model operations each needs.

The product should still enforce document permissions before context enters generation. A model gateway manages the configured inference path; the RAG application knows which documents the current user is entitled to retrieve. Keep that check at the retrieval boundary and include it in acceptance fixtures.

SSO and guardrails are available in Bifrost Enterprise. Where those features are part of the selected deployment, include the edition in the operating manifest. Keep the article’s routing procedure focused on the documented request controls rather than presenting an edition label as the whole application design.

Join gateway evidence to retrieval outcomes

Give each ingestion batch and query a stable application identifier. Record the related inference request identifiers using the documented propagation and observation interfaces selected for the deployment. The engineer investigating a query should be able to locate its embedding request, retrieved chunks and generation request.

Keep the requested model and the observed route separate where the documented fields provide both. This helps the team understand configuration changes without reconstructing them from application code. Store the configuration revision with the evaluation record.

Request success is one observation; retrieval success is another. A gateway event can show that an embedding request completed. The labelled query set shows whether the resulting vector led to useful evidence. The answer rubric shows whether generation used that evidence appropriately.

Avoid combining those results into an unexplained pass label. Record which layer accepted the run and why. This is especially helpful when the system answers from the wrong document despite technically successful model calls.

Use an ingestion record that survives the original worker

The ingestion worker should leave a manifest describing the vectors it created. Record the corpus revision, prepared chunk identifiers, embedding configuration and target collection. A later query worker needs those facts even if it runs in another process or is maintained by another team.

Give every source document a stable application identifier and revision. The prepared chunks should retain their relationship to that source. This lets the product explain which evidence was retrieved and makes a citation traceable to the content that entered the index.

Record transformations before embedding. The application may remove boilerplate, split documents or normalise text. Preserve the settings and implementation revision used for the accepted corpus. During the first Bifrost request-path pilot, hold those transformations stable so the embedding route is the deliberate change being evaluated.

The returned vector should be associated with the correct prepared chunk. Test a small batch with distinct texts and inspect the mapping. A valid vector length is useful schema evidence, while correct chunk association establishes that the stored record represents the intended source content.

Store enough safe provenance to investigate the record later. The manifest can identify the model route, configuration revision and relevant inference requests without exposing provider credentials. Choose content persistence through the organisation’s normal data handling policy.

Validate the index schema before writing ordinary batches

The vector collection has a schema which the embedding output must satisfy. Verify the expected dimensions and required metadata fields with a small fixture before allowing a larger ingestion job. The check belongs at the application’s storage boundary, where the intended collection is known.

The application should also verify its document and chunk identifiers. A storage operation that overwrites the wrong record can produce a technically searchable collection with misleading provenance. Use deterministic fixture identifiers so the test makes the intended insert or update relationship visible.

If the ingestion job updates existing documents, define how obsolete chunks are handled. The product should know which corpus revision is represented by the current collection. This is application index maintenance, and it should remain explicit when model access moves behind the gateway.

After writing the fixture batch, run the known queries and inspect the retrieved chunk identifiers. This closes the loop from prepared source to stored vector to selected evidence. The acceptance packet should retain that relationship rather than stopping at the embedding response.

Keep query construction separate from generation prompts

The query embedding should represent the retrieval question the application intends to search. The generation prompt can contain additional instructions, retrieved context and output requirements. Record those inputs separately so an engineer can understand what each model call was asked to do.

A product may transform the user question before retrieval. If it does, preserve that transformation and its own acceptance scope. The first gateway pilot should not silently introduce a new query-rewriting model alongside the route change. Additional model steps belong in the operation inventory and should have their own evidence.

The retrieval service should select the collection associated with the approved embedding contract. Keep that selection in configuration and the query record. A logical route name is helpful, while the application still needs to know which index version receives the resulting vector.

Apply access and metadata filters through the application’s intended retrieval mechanism. The model gateway does not replace the application’s knowledge of document ownership. The query fixture should identify the user scope and show which supporting chunks were permitted before generation began.

Then construct the generation prompt from the accepted context. Preserve chunk or document references in a form the output consumer can validate. The application should be able to determine whether a displayed citation refers to material actually supplied for that query.

Give empty retrieval a deliberate product outcome

An empty result set is a meaningful application condition. Decide whether the product asks for clarification, indicates that the corpus has no supporting information or uses another explicitly approved workflow. The answer should follow the product contract rather than an accidental fallback to unsupported prose.

Test this state with a deterministic retrieval fixture. It does not require a live model to establish that the application recognises an empty context. The local result should show the intended task transition and user-facing state.

If the product deliberately sends an empty-context request to generation, record the prompt and expected answer behaviour as a separate acceptance case. The model’s role should be explicit. The fixture should not reward a plausible unsupported answer merely because it sounds helpful.

Keep the empty-retrieval result distinct from a failed embedding request. One says the selected search produced no accepted evidence; the other says a required model operation did not complete successfully. The application should preserve that distinction for support and recovery.

Evaluate retrieval and generation with separate rubrics

The retrieval rubric asks whether the expected supporting evidence is present and permitted. The generation rubric asks whether the answer uses that evidence appropriately and meets the product’s output contract. Record both outcomes so the team can diagnose the layer that needs attention.

Begin with a small labelled query set and an inspectable corpus. Each query should name its expected supporting documents or deliberate no-answer state. The initial exercise is an acceptance test for the selected application configuration, not a broad statistical benchmark of all possible RAG workloads.

Run retrieval first and preserve the selected identifiers. Then evaluate generation using that context. A fluent answer should not conceal that the wrong document was selected, and a rejected answer should not be reported as a vector-space failure when retrieval supplied the intended evidence.

Use the same corpus and query fixtures when comparing route revisions. If the team changes an embedding model, collection, generation model and prompt together, the result cannot isolate their contributions. A sequence of deliberate changes produces clearer evidence and a more useful release discussion.

The gateway request records connect to those application outcomes through a query identifier. Record the embedding request and generation request separately. The selected Bifrost observation interface can explain each call, while the application record supplies the retrieved context and final acceptance label.

Make citations an executable application contract

A citation is useful only when it points to the intended supporting source. The application should preserve the mapping from retrieved chunk identifiers to displayed document references. Test that mapping with fixture documents whose titles and facts are visibly distinct.

The validator can inspect whether a cited identifier belongs to the accepted context for the query. The exact implementation depends on the product’s output format, but the acceptance condition should be explicit. A citation that merely looks well formatted is not sufficient evidence of that relationship.

If the product produces structured citations, validate the schema and allowed identifiers before displaying them. If it uses another representation, define the corresponding parser and review process. Keep the citation consumer in the operation register alongside the model request.

A useful failure fixture supplies an answer with an unknown citation identifier. The application should follow its deliberate rejection or review path. This local fixture establishes the consumer behaviour without claiming that a live model produced the case during the article’s preparation.

Separate live query serving from background ingestion recovery

An interactive query and an ingestion batch can have different deadlines. The service owner should define the product outcome for each. A query may need a quick handled state, while an ingestion job may remain in a resumable workflow according to its normal operating policy.

Record retry ownership for both clients. The SDK, Bifrost gateway and job system can each participate in repeated work. The application needs a deliberate combined budget and a clear task state after recovery stops. Use the current documented gateway policy for the selected release.

An ingestion retry should preserve source and chunk identity. The storage layer should follow the application’s established update or idempotency design so repeated processing remains understandable. A new model attempt and a repeated storage action are separate events in the ledger.

A query retry should preserve the relationship to the user’s product task. If a new generation is started after partial output, the application should make the attempt relationship explicit and follow its transcript policy. Do not silently concatenate two answers into an unexplained response.

Use controlled fixtures to exercise these states before ordinary traffic enters the pilot. Record the expected outcome, observed task state and safe request relationships. The purpose is an operable RAG workflow with Bifrost’s shared request boundary beneath it.

Preserve index and route restoration together

The restoration procedure should name the complete accepted combination: embedding route, selected collection and generation configuration. A model endpoint setting alone may not describe the RAG state the product needs to restore.

Rehearse restoration in the disposable environment. Rerun the labelled queries and inspect retrieved identifiers and accepted answers. Preserve the configuration revisions and fixture outcomes so the release owner can assess the actual procedure.

If the pilot changed only the request path while holding the index and model choices steady, say so in the record. If it also introduced a new collection or destination, record those changes separately. The runbook should describe the system that was actually accepted.

Use an investigation packet for an unexpected answer

A useful packet begins with the product query identifier and user scope. It identifies the selected collection, query embedding route, retrieved chunk references and generation request. The final application result includes the answer, citation validation and accepted or review state.

The packet should retain versions and safe identifiers rather than depend on a developer’s local session. An engineer can then locate the documented Bifrost request evidence and compare it with the RAG application’s own outcome record.

Choose content handling deliberately. Approved fixture content can be retained for the acceptance exercise, while ordinary customer content may use different access and retention controls. The packet should identify the evidence available under the selected policy without inventing missing usage or content fields.

Use the first ordinary support case to verify the investigation procedure. Confirm that another engineer can follow the query to its model calls and retrieved evidence. Improve the runbook if the relationship is unclear, while preserving the historical configuration and observed outcome.

The resulting architecture is precise: Bifrost serves two documented model routes, retrieval remains an application-owned step and the evidence joins them at the product query. That is a concrete adoption decision the RAG team can maintain after the first migration.

Exercise document updates in the disposable index

A useful extension fixture begins with one approved source document and a known query. Ingest the original revision, inspect the retrieved identifier and record the accepted answer. Then update the source through the application’s normal ingestion process and rerun the same query against the intended new corpus revision.

The test should establish the application-defined relationship between source revisions and stored chunks. The exact update mechanism depends on the chosen vector store and ingestion design. Record what the product intends to replace, retain or remove, then inspect the resulting collection rather than inferring it from a completed embedding call.

Keep the model route stable during this corpus-update exercise where practical. That isolates the ingestion and storage behaviour from a simultaneous model change. The gateway evidence can identify the embedding requests, while the application manifest identifies the document revision they represent.

Inspect the final citations as well as the retrieved text. A displayed reference should lead to the accepted source revision according to the product’s design. This closes the evidence path from updated document to stored vector to user-facing answer.

Exercise a query from another application scope

When the service supports several customers or teams, use controlled fixture scopes with distinct documents. The query record should identify the caller’s application scope, and the retriever should apply the corresponding permission rules before context reaches generation.

Run a question whose answer exists only in another fixture scope. The expected result should follow the product’s no-permitted-evidence policy. The model should not receive the other scope’s supporting chunks merely because the text is semantically relevant.

This is an application retrieval acceptance case, separate from gateway caller access. The two boundaries can work together, with Bifrost serving the approved model route and the product controlling which business documents enter the prompt.

Keep safe identifiers and fixture outcomes in the report. The evidence should be sufficient to show the boundary without retaining unnecessary private content. The accepted operating policy determines who can inspect the underlying source material.

Complete the route-to-index handover

The final runbook should name the owner of the embedding route, the collection, the generation route and the answer validator. It should identify who can approve a change to each and which fixture set establishes its accepted behaviour.

A future engineer should be able to begin with a query identifier, find the selected index and model configuration, inspect the retrieved evidence and understand the final product state. Verify that path with another team member before treating the pilot as operationally complete.

The architecture is then concrete enough to expand: shared Bifrost model access, an explicit vector-space contract and an application-owned retrieval decision. The next service can reuse the platform process while preserving its own corpus and answer requirements.

The release record should also identify the exact fixture report used for approval. Keep planned tests separate from executed results so a future maintainer can assess the evidence without guessing what the original team ran.

When another corpus or service joins the shared Bifrost deployment, give it its own index manifest and query fixtures. Reuse the model access process, while preserving the source ownership and retrieval contract that make its answers meaningful.

That distinction allows platform work to be shared without losing application context. The gateway owner maintains the configured inference routes, and the RAG owner maintains the corpus, permitted retrieval and accepted answer behaviour. The query identifier joins their evidence into one product investigation path.

Record the no-evidence answer separately

A retrieval test can pass when the application deliberately declines to answer a question without permitted supporting material. Preserve that outcome as its own category in the report. It demonstrates the agreed evidence boundary and should not be combined with questions that produced an accepted cited answer.

Approve the complete RAG fixture set

Use a corpus small enough to inspect manually. Include a question answered by one document, a question requiring two documents, a question with no answer and a question that must be filtered by the user’s access scope. Define the expected product behaviour before running the pilot.

For each case, retain the query, selected index version, retrieved identifiers, generated answer and acceptance decision. Sanitise content appropriately before sharing reports. The outcome record should explain the product result, while request identifiers connect it to the configured model route.

Rehearse returning the service to its previous approved route and index configuration. Model routing and collection selection should both be explicit in that rehearsal. A release owner needs to know which settings restore the accepted application behaviour.

The LlamaIndex gateway shortlist explains the selection criteria, and the model alias guide develops the configuration boundary. Start with Bifrost and approve the two routes through the retrieval evidence the application actually needs.

Sources

  1. Bifrost OpenAI SDK integration Maxim AI
  2. Bifrost protocol integrations Maxim AI
  3. Bifrost virtual keys Maxim AI
  4. Bifrost model aliases Maxim AI
  5. Bifrost provider routing Maxim AI
  6. Bifrost telemetry Maxim AI
  7. LlamaIndex OpenAI-compatible model integration LlamaIndex
  8. LlamaIndex OpenAI embedding integration LlamaIndex

Frequently asked questions

Should RAG embeddings and generation have separate routes?

Give each operation an explicit model identifier and contract. The two routes serve different roles and change processes.

What should be checked before ingestion?

Verify vector dimensions, input-to-vector association, preprocessing and the target collection schema.

Does a new embedding model need a new index plan?

Treat it as an explicit index release with a versioned corpus and labelled retrieval evaluation.

Where should document permissions be enforced?

The application should apply its access rules at retrieval before context enters generation.

Did the guide execute an end-to-end RAG test?

No. The examples are illustrative configuration and the fixture set is a proposed acceptance procedure.

All tools →