exa-rag

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Exa RAG Integration

Exa RAG集成

Quick Reference

快速参考

TopicWhen to UseReference
LangChainBuilding RAG chains with LangChainlangchain.md
LlamaIndexUsing Exa as a LlamaIndex data sourcellamaindex.md
Vercel AI SDKAdding web search to Next.js AI appsvercel-ai.md
MCP & ToolsClaude MCP server, OpenAI tools, function callingmcp-tools.md
主题适用场景参考文档
LangChain使用LangChain构建RAG链langchain.md
LlamaIndex将Exa用作LlamaIndex数据源llamaindex.md
Vercel AI SDK为Next.js AI应用添加网页搜索功能vercel-ai.md
MCP & 工具Claude MCP服务器、OpenAI工具、函数调用mcp-tools.md

Essential Patterns

核心模式

LangChain Retriever

LangChain检索器

python
from langchain_exa import ExaSearchRetriever

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

docs = retriever.invoke("latest AI research papers")
python
from langchain_exa import ExaSearchRetriever

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

docs = retriever.invoke("latest AI research papers")

LlamaIndex Reader

LlamaIndex阅读器

python
from llama_index.readers.web import ExaReader

reader = ExaReader(api_key="your-key")
documents = reader.load_data(
    query="machine learning best practices",
    num_results=10
)
python
from llama_index.readers.web import ExaReader

reader = ExaReader(api_key="your-key")
documents = reader.load_data(
    query="machine learning best practices",
    num_results=10
)

Vercel AI SDK Tool

Vercel AI SDK工具

typescript
import { exa } from "@agentic/exa";
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const result = await generateText({
  model: openai("gpt-4"),
  tools: { search: exa.searchAndContents },
  prompt: "Search for the latest TypeScript features",
});
typescript
import { exa } from "@agentic/exa";
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const result = await generateText({
  model: openai("gpt-4"),
  tools: { search: exa.searchAndContents },
  prompt: "Search for the latest TypeScript features",
});

OpenAI-Compatible Endpoint

OpenAI兼容端点

python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.exa.ai/v1",
    api_key="your-exa-key"
)

response = client.chat.completions.create(
    model="exa",
    messages=[{"role": "user", "content": "What are the latest AI trends?"}]
)
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.exa.ai/v1",
    api_key="your-exa-key"
)

response = client.chat.completions.create(
    model="exa",
    messages=[{"role": "user", "content": "What are the latest AI trends?"}]
)

Integration Selection

集成方案选择

FrameworkBest ForKey Feature
LangChainComplex chains, agentsExaSearchRetriever, tool integration
LlamaIndexDocument indexing, Q&AExaReader, query engines
Vercel AI SDKNext.js apps, streamingTool definitions, edge-ready
OpenAI CompatDrop-in replacementMinimal code changes
Claude MCPClaude Desktop, Claude CodeNative tool calling
框架最佳适用场景核心特性
LangChain复杂链、AgentExaSearchRetriever、工具集成
LlamaIndex文档索引、问答系统ExaReader、查询引擎
Vercel AI SDKNext.js应用、流式处理工具定义、边缘就绪
OpenAI兼容直接替换方案代码改动最小
Claude MCPClaude桌面端、Claude代码工具原生工具调用

Common Mistakes

常见误区

  1. Not using highlights for RAG - Full text wastes context; use
    highlights=True
    for relevant snippets
  2. Missing source attribution - Always include
    result.url
    in citations for grounded responses
  3. Ignoring summaries -
    summary=True
    provides concise context without full page overhead
  4. Over-fetching results - Start with 3-5 results; more isn't always better for RAG quality
  5. Not filtering domains - Use
    include_domains
    to limit to authoritative sources
  6. Skipping date filters - For current events, always add
    start_published_date
    to avoid stale info
  7. Forgetting async patterns - Use async retrievers in production for better throughput
  1. 未在RAG中使用高亮功能 - 全文内容会浪费上下文;使用
    highlights=True
    获取相关片段
  2. 缺失来源归因 - 为保证基于事实的响应,务必在引用中包含
    result.url
  3. 忽略摘要功能 -
    summary=True
    可提供简洁上下文,避免全页内容的开销
  4. 过度获取结果 - 初始设置3-5条结果即可;结果数量过多并不一定提升RAG质量
  5. 未过滤域名 - 使用
    include_domains
    限制为权威来源
  6. 跳过日期过滤 - 针对时事内容,务必添加
    start_published_date
    以避免过时信息
  7. 忘记异步模式 - 生产环境中使用异步检索器可提升吞吐量