Guide

RAG with LlmaIndex x Desearch

A quick-start guide on how to addDesearch retrieval to a LlamaIndex Agent Application.

LlamaIndex is a framework for building LLM applications powered by structured data. In this guide, we’ll use Desearch’s LlamaIndex integration to:

This guide demonstrates how to enhance a LlamaIndex agent with Desearch’s web search capabilities.

  1. Specify Desearch’s Search and Retrieve Tool as a LlamaIndex retriever
  2. Set up an OpenAI Agent that uses this tool in its response generation

🚀 Quick Start

1. Install Required Packages

pip install llama-index llama-index-core llama-index-desearch

2. Instantiate the Desearch Tool

* Also ensure API keys are initialized properly. The following code uses the DESEARCH_API_KEY as the relevant environment variable name.


from llama_index_desearch.tools import DesearchToolSpec
import os

desearch_tool = DesearchToolSpec(
    api_key=os.environ["DESEARCH_API_KEY"],
)

3. Select Desearch Methods to Use

For this example, we are only interested in passing the ai_search_tool method to our agent, so we specify this using the .to_tool_listLlamaIndex method.

search_and_retrieves_tool = desearch_tool.to_tool_list(
    spec_functions=["ai_search_tool"]
)

4. Set Up the OpenAI Agent

Set up the OpenAIAgent, passing the filtered down toolset from above.

from llama_index.agent.openai import OpenAIAgent

agent = OpenAIAgent.from_tools(
    search_and_retrieves_tool,
    verbose=True,
)

We can then use the chat method to interact with the agent.

agent.chat(
    "Can you summarize the news from the last month related to the US stock market?"
)

🛠️ Desearch Tool Functions

  • ai_search_tool: The Desearch API allows you to perform AI-powered web searches, gathering relevant information from multiple sources, including web pages, research papers, and social media discussions.
  • twitter_search_tool: The X Search API enables users to retrieve relevant links and tweets based on specified search queries without utilizing AI-driven models. It analyzes links from X posts that align with the provided search criteria.
  • web_search_tool: This API allows users to search for any information on the web. This replicates a typical search engine experience, where users can search for any information they need.

For more details, see Desearch Tool API Reference.


📚 Additional Resources