exa-rag
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExa RAG Integration
Exa RAG集成
Quick Reference
快速参考
| Topic | When to Use | Reference |
|---|---|---|
| LangChain | Building RAG chains with LangChain | langchain.md |
| LlamaIndex | Using Exa as a LlamaIndex data source | llamaindex.md |
| Vercel AI SDK | Adding web search to Next.js AI apps | vercel-ai.md |
| MCP & Tools | Claude MCP server, OpenAI tools, function calling | mcp-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
集成方案选择
| Framework | Best For | Key Feature |
|---|---|---|
| LangChain | Complex chains, agents | ExaSearchRetriever, tool integration |
| LlamaIndex | Document indexing, Q&A | ExaReader, query engines |
| Vercel AI SDK | Next.js apps, streaming | Tool definitions, edge-ready |
| OpenAI Compat | Drop-in replacement | Minimal code changes |
| Claude MCP | Claude Desktop, Claude Code | Native tool calling |
| 框架 | 最佳适用场景 | 核心特性 |
|---|---|---|
| LangChain | 复杂链、Agent | ExaSearchRetriever、工具集成 |
| LlamaIndex | 文档索引、问答系统 | ExaReader、查询引擎 |
| Vercel AI SDK | Next.js应用、流式处理 | 工具定义、边缘就绪 |
| OpenAI兼容 | 直接替换方案 | 代码改动最小 |
| Claude MCP | Claude桌面端、Claude代码工具 | 原生工具调用 |
Common Mistakes
常见误区
- Not using highlights for RAG - Full text wastes context; use for relevant snippets
highlights=True - Missing source attribution - Always include in citations for grounded responses
result.url - Ignoring summaries - provides concise context without full page overhead
summary=True - Over-fetching results - Start with 3-5 results; more isn't always better for RAG quality
- Not filtering domains - Use to limit to authoritative sources
include_domains - Skipping date filters - For current events, always add to avoid stale info
start_published_date - Forgetting async patterns - Use async retrievers in production for better throughput
- 未在RAG中使用高亮功能 - 全文内容会浪费上下文;使用获取相关片段
highlights=True - 缺失来源归因 - 为保证基于事实的响应,务必在引用中包含
result.url - 忽略摘要功能 - 可提供简洁上下文,避免全页内容的开销
summary=True - 过度获取结果 - 初始设置3-5条结果即可;结果数量过多并不一定提升RAG质量
- 未过滤域名 - 使用限制为权威来源
include_domains - 跳过日期过滤 - 针对时事内容,务必添加以避免过时信息
start_published_date - 忘记异步模式 - 生产环境中使用异步检索器可提升吞吐量