Skip to main content
Exa (formerly Metaphor Search) is a search engine fully designed for use by LLMs. Search for documents on the internet using natural language queries, then retrieve cleaned HTML content from desired documents. Unlike keyword-based search (Google), Exa’s neural search capabilities allow it to semantically understand queries and return relevant documents. For example, we could search "fascinating article about cats" and compare the search results from Google and Exa. Google gives us SEO-optimized listicles based on the keyword “fascinating”. Exa just works. This page goes over how to use ExaSearchResults with LangChain.

Overview

Integration details

Setup

The integration lives in the @langchain/exa package.

Credentials

First, get an Exa API key and add it as an environment variable. Get 1000 free searches/month by signing up for Exa.
It’s also helpful (but not needed) to set up LangSmith for best-in-class observability:

Instantiation

Here we show how to instantiate an instance of the ExaSearchResults tool:

Invocation

Invoke directly with args

Invoke with ToolCall

We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:

Chaining

We can use our tool in a chain by first binding it to a tool-calling model and then calling it:

With an Agent

We can create LangChain tools which use the ExaRetriever and the createRetrieverTool Using these tools we can construct a simple search agent that can answer questions about any topic. We’ll use LangGraph to create the agent. Make sure you have @langchain/langgraph installed:
Then, define the LLM to use with the agent

API reference

For detailed documentation of all ExaSearchResults features and configurations head to the API reference