ai-rag
Adds retrieved documents to the prompt from a vector search.
ai-ragPriority 1060What it does
ai-rag adds documents from your own search index to a prompt before the model sees it. The question is turned into an embedding by the service under Embeddings provider, the index under Vector search provider is searched with it, and what the search answers is appended to the prompt as a user message. ai-proxy on the same route then sends the prompt to the model.
The client asks for the search in its body. Beside messages it sends an ai_rag object, with the question under embeddings.input and the vector field of the index under vector_search.fields. A request without that object is answered 400, so the route serves only clients written for it.
When to use it
- A support assistant on the orders API whose answers about shipping and returns should come from your own product documents, not from what the model knows.
- Product documents that change every week, kept in a search index that the assistant reads at the moment a customer asks.
- An index in Azure AI Search whose vectors were made by an Azure OpenAI deployment, which every chat request should consult first.
- A chat client your team writes, which can send the question and the vector field beside the messages of every request.
Not for sending the prompt to a model and its answer back to the client — see ai-proxy (Proxies requests to an LLM provider with a unified API), replacing the request body with what a model makes of it — see ai-request-rewrite (Rewrites the request body with an LLM before proxying) or refusing prompts that match a pattern — see ai-prompt-guard (Allows or denies prompts that match configured patterns).
Set it up
Add search results to a prompt that asks for them in an ai_rag object
Each request carries an ai_rag object beside its messages, with the question under `embeddings.input` and the vector field under `vector_search.fields`, and one without it is refused with 400. Both addresses are used as written, so they carry the api-version the service answers.
Fill Embeddings provider as in the JSON below and fill Vector search provider as in the JSON below.
{
"embeddings_provider": {
"azure_openai": {
"api_key": "<secret>",
"endpoint": "https://orders-ai.openai.azure.com/openai/deployments/text-embedding-3-large/embeddings?api-version=2024-02-01"
}
},
"vector_search_provider": {
"azure_ai_search": {
"api_key": "<secret>",
"endpoint": "https://orders-search.search.windows.net/indexes/product-docs/docs/search?api-version=2024-07-01"
}
}
}
Things to know
- Vector search provider — In the example the search answers
Orders ship within two working days, and the model receives that sentence together with the client's question. - Embeddings provider — Only a request body carrying ai_rag, with an embeddings input and vector search fields, is served, and any other is refused with 400. For example: "ai_rag": {"embeddings": {"input": "the question"}, "vector_search": {"fields": "contentVector"}}.
- Embeddings provider — Azure OpenAI is the one embeddings provider, and a configuration that names
openaiinstead is refused when you save. - Endpoint — Both addresses, this one and the search's, are used as written, so each carries the
api-versionquery parameter its service answers to. - AdviceKeep the route behind an authentication plugin, for example key-auth, so that only your own clients reach the index and the model.
Settings
The fields as the console shows them, section by section.
embeddings_providerobjectRequiredembeddings_provider.azure_openaiobjectRequiredembeddings_provider.azure_openai.api_keystringRequiredStored on the engine and shown only to roles that manage this object.
embeddings_provider.azure_openai.endpointstringRequiredThe full embeddings URL of the deployment, used exactly as written.
vector_search_providerobjectRequiredWhat the search answers with is appended to the prompt as a user message.
vector_search_provider.azure_ai_searchobjectRequiredvector_search_provider.azure_ai_search.api_keystringRequiredStored on the engine and shown only to roles that manage this object.
vector_search_provider.azure_ai_search.endpointstringRequiredThe full search URL of the index, used exactly as written.
ssl_verifybooleandefault trueChecks the certificates of both the embeddings and the search service, and turning it off is logged as a security risk.