CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 3 · Lesson 15/45

    RAG Retrieval for Agents: Querying AI Search and Injecting Chunks into Context

    Design a RAG pipeline that retrieves chunks from a Unity Catalog-governed document corpus and injects them into agent context.

    9 min read
    2.22% of exam
    3 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Walk through the RAG chain steps that run when a user sends a request
    • Connect an agent to an AI Search index through the managed MCP server or VectorSearchRetrieverTool
    • Show how retrieved chunks get into the LLM's context as tool results
    • List the Unity Catalog privileges an agent or user needs to query an index it does not own

    1.The RAG chain at request time

    Once the index exists, every user request goes through the RAG chain. An optional preprocessing step can rewrite the request, put it into a template, or pull out keywords, producing a *retrieval query*. During retrieval, that query is embedded with the same model used for the chunks, compared against them (for example by cosine similarity), and the top-ranked results come back. Prompt augmentation builds the LLM prompt by putting the user's query and the retrieved context into a template that tells the model how to use each part. In generation, the LLM answers from that context. An optional post-processing step can add citations or apply business rules. Guardrails can apply at any step, including checking user permissions before the chain touches a data source.

    Checkpoint 1 of 6· Put it in order

    Put the RAG chain steps in order

    1. 1.(Optional) Post-processing adds citations or business logic
    2. 2.LLM generation produces a grounded response
    3. 3.(Optional) User query preprocessing produces a retrieval query
    4. 4.Retrieval embeds the query and returns the most similar chunks
    5. 5.Prompt augmentation combines the query and retrieved context in a template

    Sources1

    2.Give the agent a retriever over the index

    An agent reaches the index through a tool. Databricks documents three ways to set one up, depending on where the index lives and how much control you need.

    Ways to connect an agent to unstructured data
    ApproachWhen to use itWhat you configure
    Databricks-managed AI Search MCP serverImmediate access to a Databricks AI Search index built with Databricks-managed embeddingsThe URL /api/2.0/mcp/ai-search/{catalog}/{schema}/{index_name}
    AI Bridge retriever (databricks-langchain / databricks-openai)Developing and testing a retriever tool locallyVectorSearchRetrieverTool with index_name, tool_name, tool_description
    Custom retriever through a Unity Catalog connectionA vector index hosted outside DatabricksCREATE CONNECTION plus a retriever function returning List[Document]

    Checkpoint 2 of 6· Fill the gap

    Which path segment completes the managed MCP server URL for an AI Search index?

    mcp_client = DatabricksMCPClient(
        server_url=f"{host}/api/2.0/mcp/ ? /<catalog>/<schema>/<index-name>",
        workspace_client=workspace_client,
    )
    tools = mcp_client.list_tools()

    VectorSearchRetrieverTool lets you shape retrieval in code. You set how many chunks come back (num_results), which columns are returned, which filters apply, and whether the query is ANN or HYBRID. If the index is a Direct Vector Access Index, or a Delta Sync Index with self-managed embeddings, the tool cannot embed the query by itself. You must pass it a text_column and an embedding model.

    VectorSearchRetrieverTool configured for an index with self-managed embeddingspython
    vs_tool = VectorSearchRetrieverTool(
      index_name="catalog.schema.index_name", # Index name in the format 'catalog.schema.index'
      num_results=5, # Max number of documents to return
      columns=["primary_key", "text_column"], # List of columns to include in the search
      filters={"text_column LIKE": "Databricks"}, # Filters to apply to the query
      query_type="ANN", # Query type ("ANN" or "HYBRID").
      tool_name="name of the tool", # Used by the LLM to understand the purpose of the tool
      tool_description="Purpose of the tool", # Used by the LLM to understand the purpose of the tool
      text_column="text_column", # Specify text column for embeddings. Required for direct-access index or delta-sync index with self-managed embeddings.
      embedding=embedding_model # The embedding model. Required for direct-access index or delta-sync index with self-managed embeddings.
    )

    Checkpoint 3 of 6· Exam question

    A data science team already computes embeddings for their documents using a proprietary in-house model and wants the RAG pipeline's AI Search index to use those exact vectors, without Databricks recomputing them from a specified embedding model. Which index configuration should they use?

    Sources2

    3.How retrieved chunks get into the agent's context

    When retrieval is exposed as a tool, the LLM decides when to call it. Its description is the main signal for that decision, so write a specific tool_description. After the model calls the tool, your code runs the search and appends the results to the conversation as a tool message linked to the call ID. The model's next turn then sees the retrieved chunks next to the user's question. This is the augmentation step in practice.

    Appending the retriever's results to the conversation so the model can use thempython
    messages.append(first_response.choices[0].message)
    messages.append({
      "role": "tool",
      "tool_call_id": tool_call.id,
      "content": json.dumps(result)
    })

    If you write your own retriever, follow the MLflow retriever schema: return a List[Document] and put attributes such as doc_uri and similarity_score in each Document's metadata field. Tracing can then record what was retrieved, and the generation step has what it needs to cite its sources.

    Checkpoint 4 of 6· Check yourself

    A custom retriever function returns plain strings. To conform to the MLflow retriever schema, what should it return?

    Sources12

    4.Unity Catalog decides what the retriever can reach

    An AI Search index is a Unity Catalog securable, so querying it follows the usual privilege chain. A user or principal that does not own the index needs USE CATALOG on its catalog, USE SCHEMA on its schema, and SELECT on the index. For the managed MCP server, the documentation says to grant the agent SELECT on the index's securable. This is how governance carries through to retrieval: the corpus lives in a governed table, the index is a governed object, and the agent can query only what it has been granted.

    Checkpoint 5 of 6· Check yourself

    A service principal has SELECT on prod.docs.policy_index, which it does not own, but its queries fail with a permissions error. What is the most likely cause?

    Checkpoint 6 of 6· Exam question

    A team configures an AI Search index in Delta Sync (continuous) mode on a standard endpoint so the index automatically reflects new rows added to the source Delta table. After enabling sync, newly inserted rows are not appearing in the index. What is the most likely missing prerequisite?

    Sources23

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.Granting SELECT on the AI Search index is enough for a non-owner to query it.Why is that wrong?

      A non-owner also needs USE CATALOG on the catalog and USE SCHEMA on the schema that contain the index.

      Covered in Unity Catalog decides what the retriever can reach

    2. 2.VectorSearchRetrieverTool needs only index_name, whatever kind of index it points at.Why is that wrong?

      For a Direct Vector Access Index, or a Delta Sync Index with self-managed embeddings, you must also give it a text column and an embedding model so it can embed the query.

      Covered in Give the agent a retriever over the index

    Practise it for real

    Prototype a retriever tool over an AI Search index and confirm that an LLM calls it and uses the retrieved chunks.

    1. 1.Run %pip install --upgrade databricks-langchain in a notebook.

      Why: This version includes Databricks AI Bridge, which provides VectorSearchRetrieverTool.

      You should see: The package installs and you can import from databricks_langchain.

    2. 2.Create VectorSearchRetrieverTool(index_name="catalog.schema.my_databricks_docs_index", tool_name=..., tool_description=...) with your own index name and a specific description.

      Why: The LLM uses tool_name and tool_description to decide when to call the retriever.

      You should see: The tool object is created. If it fails with a permissions error, check USE CATALOG, USE SCHEMA and SELECT on the index.

    3. 3.Call vs_tool.invoke("<a question your corpus answers>").

      Why: This checks retrieval by itself before an LLM is involved.

      You should see: Relevant chunks from your index come back.

    4. 4.Create ChatDatabricks(endpoint="databricks-claude-sonnet-4-5"), call bind_tools([vs_tool]) on it, then invoke it with a question that starts "Based on the documentation…".

      Why: This tests whether the model chooses to call the retriever and answers from the retrieved context.

      You should see: The model makes a tool call to your retriever and answers from what the index returned.

    Stuck? Get a nudge

    If the index uses self-managed embeddings, the tool also needs text_column and an embedding model such as DatabricksEmbeddings(endpoint="databricks-bge-large-en").

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “using the same embedding model that was used to embed the document chunks during data preparation”
      ↩︎ The RAG chain at request time
      “checking user permissions before accessing data sources”
      ↩︎ The RAG chain at request time
      “The prompt that will be sent to the LLM is formed by augmenting the user's query with the retrieved context”
      ↩︎ How retrieved chunks get into the agent's context
      “determining how many chunks to retrieve in step 2 and how to combine them with the user's query”
      ↩︎ Prediction
      “The output of this step is a retrieval query which will be used in the subsequent retrieval step.”
      ↩︎ Checkpoint
    2. 2.
      “The legacy /api/2.0/mcp/vector-search/ URL prefix continues to work for backwards compatibility.”
      ↩︎ Give the agent a retriever over the index
      “First, create an index using Databricks-managed embeddings.”
      ↩︎ Give the agent a retriever over the index
      “Provide a descriptive tool_description to help the agent understand the tool and determine when to invoke it.”
      ↩︎ How retrieved chunks get into the agent's context
      “Grant the agent SELECT on the index's Unity Catalog securable.”
      ↩︎ Unity Catalog decides what the retriever can reach
      “you must configure the VectorSearchRetrieverTool and specify a custom embedding model and text column.”
      ↩︎ Exam trap 2
      “the retriever function should return a List[Document] object”
      ↩︎ Checkpoint
    3. 3.
      “USE CATALOG on the catalog that contains the AI Search index.”
      ↩︎ Exam trap 1
      “USE SCHEMA on the schema that contains the AI Search index.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.