--- title: RAG with a Langchain search agent type: guide tier: all order: 45 hide_menu: true hide_frontmatter_title: true meta_title: RAG with a Langchain search agent meta_description: Use Langchain, OpenAI, and Google to generate responses based on Google search results. categories: - Generative AI - Retrieval Augmented Generation - Google - OpenAI - Langchain image: "/guide/ml_tutorials/langchain.png" --- # Langchain search agent This example demonstrates how to use Label Studio with a custom Machine Learning backend. It uses a [Langchain](https://www.langchain.com/)-based agent that accepts a text input, searches for Google, and returns the answer based on the search results (a.k.a Retrieval Augmented Generation). ## Before you begin Before you begin, you must install the [Label Studio ML backend](https://github.com/HumanSignal/label-studio-ml-backend?tab=readme-ov-file#quickstart). This tutorial uses the [`langchain_search_agent` example](https://github.com/HumanSignal/label-studio-ml-backend/tree/master/label_studio_ml/examples/langchain_search_agent). ## Prerequisites ### Use Google Search To use the Google search engine, you need to have a Google Custom Search Engine (CSE) API key and a search engine ID. ``` GOOGLE_API_KEY= GOOGLE_CSE_ID= ``` For more information, see [Programmable Search Engine ID](https://support.google.com/programmable-search/answer/12499034?hl=en). ### Use OpenAI To use OpenAI, you need to have an OpenAI API key. ``` OPENAI_API_KEY= ``` For more information, see [Where do I find my OpenAI API Key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key). ## Labeling interface The labeling interface must include: - Input prompt - LLM response - Search results snippets - Classification labels #### Example ```xml