Index of every page on this site: llms.txt
All skills
Run it yourself

Build RAG pipelines with Exa.ai for real-time web retrieval. Use when building retrieval-augmented generation, integrating Exa with LangChain, LlamaIndex, Vercel AI SDK, or implementing AI agents with web search capabilities. Triggers on: RAG pipeline, retrieval augmented generation, Exa LangChain, Exa LlamaIndex, ExaSearchRetriever, ExaSearchResults, Exa MCP, Exa tool calling, Claude tool use, AI agent web search, grounded generation, citation generation, fact checking, hallucination detection, OpenAI compatibility, chat completions.

Use this Skill: https://skilld.dev/gh/ejirocodes/agent-skills/exa-rag

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referenceslangchain.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

LangChain Integration Reference

Table of Contents


Installation

pip install langchain-exa

ExaSearchRetriever

The primary way to use Exa with LangChain for RAG.

Basic Usage

from langchain_exa import ExaSearchRetriever

retriever = ExaSearchRetriever(
    exa_api_key="your-key",  # or set EXA_API_KEY env var
    k=5
)

docs = retriever.invoke("latest developments in quantum computing")
for doc in docs:
    print(f"URL: {doc.metadata['url']}")
    print(f"Title: {doc.metadata['title']}")
    print(f"Content: {doc.page_content[:200]}...")

With Highlights

retriever = ExaSearchRetriever(
    exa_api_key="your-key",
    k=5,
    highlights=True,
    num_sentences=3
)

docs = retriever.invoke("React Server Components best practices")
# docs contain highlight snippets instead of full text

With Filters

retriever = ExaSearchRetriever(
    exa_api_key="your-key",
    k=10,
    include_domains=["github.com", "stackoverflow.com"],
    start_published_date="2024-01-01",
    type="neural"
)

Configuration Options

Parameter Type Description
exa_api_key str API key (or use env var)
k int Number of results
type str "auto", "neural", or "keyword"
include_domains list Limit to these domains
exclude_domains list Exclude these domains
start_published_date str Start date filter (YYYY-MM-DD)
end_published_date str End date filter
highlights bool Return highlights instead of full text
num_sentences int Sentences per highlight
text_length_limit int Max characters for text

ExaSearchResults Tool

For LangChain agents that need web search as a tool.

Basic Tool

from langchain_exa import ExaSearchResults
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_openai import ChatOpenAI

# Create the tool
search_tool = ExaSearchResults(
    exa_api_key="your-key",
    max_results=5
)

# Use in an agent
llm = ChatOpenAI(model="gpt-4")
agent = create_openai_functions_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool])

result = executor.invoke({"input": "What are the latest AI news today?"})

Tool with Custom Configuration

search_tool = ExaSearchResults(
    exa_api_key="your-key",
    max_results=10,
    text_length_limit=1000,
    highlights=True,
    include_domains=["techcrunch.com", "wired.com"]
)

RAG Chain Patterns

Basic RAG Chain

from langchain_exa import ExaSearchRetriever
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough

retriever = ExaSearchRetriever(exa_api_key="your-key", k=5, highlights=True)
llm = ChatOpenAI(model="gpt-4")

prompt = ChatPromptTemplate.from_template("""
Answer the question based on the following context. Include source URLs.

Context:
{context}

Question: {question}

Answer:
""")

def format_docs(docs):
    return "\n\n".join(
        f"Source: {doc.metadata['url']}\n{doc.page_content}"
        for doc in docs
    )

chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

answer = chain.invoke("What are the key features of Python 3.12?")

RAG with Citations

from langchain_core.pydantic_v1 import BaseModel, Field
from typing import List

class Citation(BaseModel):
    url: str
    title: str
    snippet: str

class AnswerWithCitations(BaseModel):
    answer: str
    citations: List[Citation]

def create_cited_answer(docs, question):
    context = format_docs(docs)
    llm_with_structure = llm.with_structured_output(AnswerWithCitations)

    prompt = f"""
    Based on the context below, answer the question and cite your sources.

    Context:
    {context}

    Question: {question}
    """

    return llm_with_structure.invoke(prompt)

Conversational RAG

from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationalRetrievalChain

retriever = ExaSearchRetriever(exa_api_key="your-key", k=5)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)

chain = ConversationalRetrievalChain.from_llm(
    llm=ChatOpenAI(model="gpt-4"),
    retriever=retriever,
    memory=memory
)

response = chain.invoke({"question": "What is LangChain?"})
response = chain.invoke({"question": "How does it compare to LlamaIndex?"})

Agent Integration

ReAct Agent with Exa

from langchain_exa import ExaSearchResults
from langchain.agents import AgentExecutor, create_react_agent
from langchain_openai import ChatOpenAI
from langchain import hub

# Get ReAct prompt
prompt = hub.pull("hwchase17/react")

# Create tools
search = ExaSearchResults(exa_api_key="your-key", max_results=5)
tools = [search]

# Create agent
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({
    "input": "Research the latest developments in AI agents and summarize the key trends"
})

Multi-Tool Agent

from langchain_exa import ExaSearchResults, ExaFindSimilar

search_tool = ExaSearchResults(
    exa_api_key="your-key",
    name="web_search",
    description="Search the web for current information"
)

similar_tool = ExaFindSimilar(
    exa_api_key="your-key",
    name="find_similar",
    description="Find pages similar to a given URL"
)

tools = [search_tool, similar_tool]
# Use with your preferred agent type

LangGraph Integration

from langgraph.graph import StateGraph, END
from langchain_exa import ExaSearchRetriever

retriever = ExaSearchRetriever(exa_api_key="your-key", k=5)

def search_node(state):
    query = state["query"]
    docs = retriever.invoke(query)
    return {"documents": docs}

def generate_node(state):
    docs = state["documents"]
    # Generate answer using docs
    return {"answer": answer}

# Build graph
workflow = StateGraph(dict)
workflow.add_node("search", search_node)
workflow.add_node("generate", generate_node)
workflow.set_entry_point("search")
workflow.add_edge("search", "generate")
workflow.add_edge("generate", END)

app = workflow.compile()

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides comprehensive documentation and code patterns for building RAG (Retrieval-Augmented Generation) pipelines using Exa.ai. It is well-structured and utilizes established libraries. The primary security consideration is the inherent risk of indirect prompt injection, as the agent is designed to ingest and process unverified web content, which could contain malicious instructions.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: MEDIUM · 1 issue

  • Runlayer9mo

    5 files scanned · No issues

  • ZeroLeaks7mo

    1 finding · Score: 82/100

Signed by skilld at 6e805e4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 10 months ago
metadata
{
  "author": "ejirocodes",
  "version": "1.0.0"
}

README badge

README badge for ejirocodes/agent-skills/exa-rag