<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Databricks for RAG: Build, Run, Evaluate in Community Articles</title>
    <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127482#M543</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Aug 2025 15:16:54 GMT</pubDate>
    <dc:creator>snehamore811</dc:creator>
    <dc:date>2025-08-05T15:16:54Z</dc:date>
    <item>
      <title>Databricks for RAG: Build, Run, Evaluate</title>
      <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127317#M540</link>
      <description>&lt;P&gt;&lt;STRONG&gt;What is RAG?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RAG (Retrieval-Augmented Generation) on Databricks&lt;/STRONG&gt; refers to building and running AI applications that combine:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Retrieval systems&lt;/STRONG&gt; (like vector databases or search over documents)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Generative AI models&lt;/STRONG&gt; (such as LLMs like GPT)&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;within the Databricks platform&amp;nbsp;&lt;/H3&gt;&lt;P&gt;RAG on Databricks allows you to&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Store and index data&lt;/STRONG&gt; (e.g., using Delta Lake or vector search)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Retrieve relevant information&lt;/STRONG&gt; for a user query&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Feed that into an LLM&lt;/STRONG&gt; to generate accurate, context-aware responses&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;Key Components for RAG on Databricks:&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Databricks Vector Search&lt;/STRONG&gt; for fast retrieval&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;MLflow&lt;/STRONG&gt; for model tracking and deployment&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Foundational Models (like Dolly or external LLMs)&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Databricks Notebooks&lt;/STRONG&gt; or &lt;STRONG&gt;Lakehouse AI Agents&lt;/STRONG&gt; for orchestration&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Unity Catalog&lt;/STRONG&gt; for governance and security.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;How to build a RAG evaluation pipeline using MLflow evaluation functions?&lt;/STRONG&gt;&lt;/P&gt;&lt;H1 id="0a2f"&gt;Prerequisites&lt;/H1&gt;&lt;P class=""&gt;Before you start, ensure you meet the following requirements:&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;Use Databricks Runtime 15.4.x-cpu-ml-scala2.12.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;Install the required libraries by running the following command&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install -U -qq databricks-vectorsearch langchain==0.3.7 flashrank langchain-databricks PyPDF2

dbutils.library.restartPython()&lt;/LI-CODE&gt;&lt;P class=""&gt;Focusing on creating a complete RAG pipeline.&lt;/P&gt;&lt;OL class=""&gt;&lt;LI&gt;A user asks a question.&lt;/LI&gt;&lt;LI&gt;The question is sent to a serverless chatbot RAG endpoint.&lt;/LI&gt;&lt;LI&gt;The endpoint computes embeddings and retrieves relevant documents using the Vector Search Index.&lt;/LI&gt;&lt;LI&gt;The retrieved documents are used to enrich the prompt.&lt;/LI&gt;&lt;LI&gt;The enriched prompt is sent to the Foundation Model endpoint for a response.&lt;/LI&gt;&lt;LI&gt;The system displays the output to the user.&lt;/LI&gt;&lt;/OL&gt;&lt;H2 id="33ea"&gt;Task 1: Setup the Retriever Component&lt;/H2&gt;&lt;P class=""&gt;The retriever is responsible for fetching relevant documents from the Vector Search Index. Follow these steps:&lt;/P&gt;&lt;H2 id="8be9"&gt;Define the Components&lt;/H2&gt;&lt;LI-CODE lang="python"&gt;vs_endpoint_prefix = "vs_endpoint_"
vs_endpoint_name = vs_endpoint_prefix + str(get_fixed_integer(DA.unique_name("_")))
print(f"Assigned Vector Search endpoint name: {vs_endpoint_name}.")

vs_index_fullname = f"{DA.catalog_name}.{DA.schema_name}.pdf_text_self_managed_vs_index"
from databricks.vector_search.client import VectorSearchClient
from langchain_databricks import DatabricksEmbeddings
from langchain_core.runnables import RunnableLambda
from langchain.docstore.document import Document
from flashrank import Ranker, RerankRequest&lt;/LI-CODE&gt;&lt;H2 id="1ab7"&gt;Set Up the Retriever&lt;/H2&gt;&lt;P class=""&gt;Define the retriever to return 3 relevant documents:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_retriever(cache_dir=f"{DA.paths.working_dir}/opt"):
    def retrieve(query, k: int=3):
        if isinstance(query, dict):
            # Code to process query and return results&lt;/LI-CODE&gt;&lt;P class=""&gt;Test the retriever with a sample prompt.&lt;/P&gt;&lt;H2 id="ae69"&gt;Task 2: Setup the Foundation Model&lt;/H2&gt;&lt;P class=""&gt;Use a Foundation Model like llama-3.1 to generate responses.&lt;/P&gt;&lt;H2 id="c414"&gt;Define and Test the Model&lt;/H2&gt;&lt;LI-CODE lang="python"&gt;from langchain_databricks import ChatDatabricks

chat_model = ChatDatabricks(endpoint="databricks-meta-llama-3-1-70b-instruct", max_tokens=275)
print(f"Test chat model: {chat_model.invoke('What is Generative AI?')}")&lt;/LI-CODE&gt;&lt;H2 id="b3ee"&gt;Task 3: Assemble the Complete RAG Solution&lt;/H2&gt;&lt;P class=""&gt;Integrate the retriever and foundation model into a unified pipeline.&lt;/P&gt;&lt;H2 id="7e59"&gt;Define the Prompt Template&lt;/H2&gt;&lt;LI-CODE lang="python"&gt;from langchain.chains import create_retrieval_chain
from langchain.prompts import PromptTemplate

TEMPLATE = """You are an assistant for GENAI teaching class. You are answering questions related to Generative AI and its impact on human life. If the question is not related to these topics, kindly decline to answer. If you don't know the answer, just say so."""&lt;/LI-CODE&gt;&lt;H2 id="acea"&gt;Create the Chain&lt;/H2&gt;&lt;LI-CODE lang="python"&gt;chain = create_retrieval_chain(
    retriever=get_retriever(),
    prompt=PromptTemplate(input_variables=["question"], template=TEMPLATE),
    llm=chat_model
)

question = {"input": "How does Generative AI impact humans?"}
answer = chain.invoke(question)
print(answer)&lt;/LI-CODE&gt;&lt;H2 id="72a2"&gt;Task 4: Save the Model to Model Registry in Unity Catalog&lt;/H2&gt;&lt;H2 id="5f66"&gt;Register the Model&lt;/H2&gt;&lt;LI-CODE lang="python"&gt;from mlflow.models import infer_signature
import mlflow

mlflow.set_registry_uri("databricks-uc")
model_name = f"{DA.catalog_name}.{DA.schema_name}.rag_app_demo4"

with mlflow.start_run(run_name="rag_app_demo4") as run:
    signature = infer_signature(question, answer)
    mlflow.log_param("model_type", "RAG")
    mlflow.pyfunc.log_model(
        artifact_path="model",
        python_model=chain,
        signature=signature,
    )
    mlflow.register_model(
        model_uri=f"runs:/{run.info.run_id}/model",
        name=model_name
    )&lt;/LI-CODE&gt;&lt;H1 id="63af"&gt;Clean Up Resources&lt;/H1&gt;&lt;P class=""&gt;Delete all resources created during this course to avoid unnecessary costs.&lt;/P&gt;&lt;H1 id="3eeb"&gt;Conclusion&lt;/H1&gt;&lt;P class=""&gt;In this article, we demonstrated how to construct a comprehensive RAG application using Databricks. We:&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;Assembled key components like the Vector Search retriever and Foundation Model.&lt;/LI&gt;&lt;LI&gt;Created a pipeline to retrieve relevant documents and generate enriched responses.&lt;/LI&gt;&lt;LI&gt;Evaluated the performance using MLflow.&lt;/LI&gt;&lt;LI&gt;Registered the RAG application in Unity Catalog for production use.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;#RAG #GenAI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 11:23:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127317#M540</guid>
      <dc:creator>snehamore811</dc:creator>
      <dc:date>2025-08-04T11:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks for RAG: Build, Run, Evaluate</title>
      <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127473#M542</link>
      <description>&lt;P&gt;hey thanks for sharing&lt;/P&gt;</description>
      <pubDate>Tue, 05 Aug 2025 14:46:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127473#M542</guid>
      <dc:creator>CT_snehamore</dc:creator>
      <dc:date>2025-08-05T14:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks for RAG: Build, Run, Evaluate</title>
      <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127482#M543</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Aug 2025 15:16:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/127482#M543</guid>
      <dc:creator>snehamore811</dc:creator>
      <dc:date>2025-08-05T15:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks for RAG: Build, Run, Evaluate</title>
      <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/128924#M570</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 23:50:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/128924#M570</guid>
      <dc:creator>WiliamRosa</dc:creator>
      <dc:date>2025-08-19T23:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks for RAG: Build, Run, Evaluate</title>
      <link>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/129451#M598</link>
      <description>&lt;P&gt;Thanks for sharing&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/171942"&gt;@snehamore811&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Aug 2025 18:39:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/community-articles/databricks-for-rag-build-run-evaluate/m-p/129451#M598</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-08-23T18:39:50Z</dc:date>
    </item>
  </channel>
</rss>

