跳到主要内容
Exa 是为人工智能和开发者提供的知识 API。

安装和设置

Exa 集成存在于其自己的合作伙伴包中。您可以通过以下方式安装它
pip install -qU langchain-exa
为了使用该包,您还需要将 EXA_API_KEY 环境变量设置为您的 Exa API 密钥。

检索器

您可以在标准检索管道中使用 ExaSearchRetriever。您可以按如下方式导入它。 请参阅使用示例
from langchain_exa import ExaSearchRetriever

工具

您可以按照Exa 工具调用文档中的描述,将 Exa 用作代理工具。 请参阅使用示例

ExaFindSimilarResults

一个查询 Metaphor 搜索 API 并返回 JSON 的工具。
from langchain_exa.tools import ExaFindSimilarResults

ExaSearchResults

Exa 搜索工具。
from langchain_exa.tools import ExaSearchResults

Exa 搜索检索器

您可以按如下方式检索搜索结果
from langchain_exa import ExaSearchRetriever

exa_api_key = "YOUR API KEY"

# Create a new instance of the ExaSearchRetriever
exa = ExaSearchRetriever(exa_api_key=exa_api_key)

# Search for a query and save the results
results  = exa.invoke("What is the capital of France?")

# Print the results
print(results)

高级功能

您可以使用文本限制、摘要和实时抓取等高级功能
from langchain_exa import ExaSearchRetriever, TextContentsOptions

# Create a new instance with advanced options
exa = ExaSearchRetriever(
    exa_api_key="YOUR API KEY",
    k=20,  # Number of results (1-100)
    type="auto",  # Can be "neural", "keyword", or "auto"
    livecrawl="always",  # Can be "always", "fallback", or "never"
    summary=True,  # Get an AI-generated summary of each result
    text_contents_options={"max_characters": 3000}  # Limit text length
)

# Search for a query with custom summary prompt
exa_with_custom_summary = ExaSearchRetriever(
    exa_api_key="YOUR API KEY",
    summary={"query": "generate one line summary in simple words."}  # Custom summary prompt
)

Exa 搜索结果

您可以按如下方式运行 ExaSearchResults 模块
from langchain_exa import ExaSearchResults

# Initialize the ExaSearchResults tool
search_tool = ExaSearchResults(exa_api_key="YOUR API KEY")

# Perform a search query
search_results = search_tool._run(
    query="When was the last time the New York Knicks won the NBA Championship?",
    num_results=5,
    text_contents_options=True,
    highlights=True
)

print("Search Results:", search_results)

Exa 查找相似结果

您可以按如下方式运行 ExaFindSimilarResults 模块
from langchain_exa import ExaFindSimilarResults

# Initialize the ExaFindSimilarResults tool
find_similar_tool = ExaFindSimilarResults(exa_api_key="YOUR API KEY")

# Find similar results based on a URL
similar_results = find_similar_tool._run(
    url="http://espn.com",
    num_results=5,
    text_contents_options=True,
    highlights=True
)

print("Similar Results:", similar_results)

配置选项

所有 Exa 工具都支持以下通用参数
  • num_results (1-100):要返回的搜索结果数量
  • type:搜索类型 - “neural”(神经网络)、“keyword”(关键词)或“auto”(自动)
  • livecrawl:实时抓取模式 - “always”(始终)、“fallback”(回退)或“never”(从不)
  • summary:获取 AI 生成的摘要(True/False 或自定义提示字典)
  • text_contents_options:用于限制文本长度的字典(例如 {"max_characters": 2000}
  • highlights:包含高亮文本片段(True/False)

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.