Skip to main content
Nimble 的 Search API 通过无头浏览器实时浏览互联网提供实时网络搜索,而不是查询预构建的索引。该工具处理 JavaScript 渲染、动态内容和复杂的导航流,适用于需要访问当前网络数据的智能体工作流,包括分页、过滤器和客户端渲染背后的内容。

概述

集成详情

可序列化JS 支持最新包版本
NimbleSearchToollangchain-nimblePyPI - Version

工具功能

返回工件原生异步返回数据定价
标题、URL、内容(markdown/plain_text/HTML)、元数据提供免费试用
主要特性:
  • 快速模式与深度模式深度模式(默认)用于含 JavaScript 渲染的完整内容提取,快速模式用于仅获取 SERP 快速结果
  • AI 生成摘要:可选地在原始搜索结果旁边生成简洁的回答
  • 域名和日期过滤:按特定域名或日期范围过滤以获得精确结果
  • 基于主题的路由:针对通用、新闻或基于位置的查询进行优化路由
  • 灵活的输出格式:plain_text、markdown(默认)或 simplified_html
  • 生产就绪:原生异步支持、自动重试、连接池

设置

该集成位于 langchain-nimble 包中。
pip install -U langchain-nimble

凭证

您需要一个 Nimble API 密钥才能使用此工具。在 Nimble 注册以获取您的 API 密钥并访问免费试用。
import getpass
import os

if not os.environ.get("NIMBLE_API_KEY"):
    os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")

实例化

现在我们可以实例化工具:
from langchain_nimble import NimbleSearchTool

# Basic usage - uses environment variable for API key
tool = NimbleSearchTool()

在智能体中使用

我们可以将 Nimble 搜索工具与智能体结合使用,赋予其动态网络搜索能力。以下是使用 LangGraph 的完整示例:
import os
import getpass

from langchain_nimble import NimbleSearchTool
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

if not os.environ.get("OPENAI_API_KEY"):
    os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API key:\n")
if not os.environ.get("NIMBLE_API_KEY"):
    os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")

# Initialize Nimble Search Tool with deep search for comprehensive results
nimble_tool = NimbleSearchTool(
    k=5,
    deep_search=True,
    parsing_type="markdown"
)

# Create agent with the tool
model = init_chat_model(model="gpt-4o", model_provider="openai", temperature=0)
agent = create_agent(model, [nimble_tool])

# Ask the agent a question that requires web search
user_input = "What are the latest developments in quantum computing? Include only sources from academic institutions and reputable tech publications."

for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
================================ Human Message =================================

What are the latest developments in quantum computing? Include only sources from academic institutions and reputable tech publications.

================================== Ai Message ==================================
Tool Calls:
  nimble_search (call_abc123)
 Call ID: call_abc123
  Args:
    query: quantum computing latest developments 2025
    deep_search: True
    include_domains: ['mit.edu', 'stanford.edu', 'nature.com', 'science.org', 'ieee.org']
    k: 5

================================= Tool Message =================================
Name: nimble_search

[{"title": "Breakthrough in Quantum Error Correction | MIT News", "url": "https://news.mit.edu/quantum-error-correction", "content": "# Quantum Error Correction Breakthrough\n\nResearchers at MIT have achieved a significant milestone in quantum error correction...\n\n## Key Findings\n- New error correction codes reduce computational overhead\n- Scalability improvements for larger quantum systems...", "rank": 1}, {"title": "Quantum Computing Advances | Nature", "url": "https://www.nature.com/articles/quantum-2024"...

================================== Ai Message ==================================

Based on recent academic and technical sources, here are the latest developments in quantum computing:

**Error Correction:**
- MIT researchers have achieved breakthroughs in quantum error correction
- New codes significantly reduce computational overhead

**Hardware Advances:**
- Improved qubit coherence times and stability
- Progress toward fault-tolerant quantum computing...
[Agent continues with comprehensive summary]

高级配置

该工具支持针对不同使用场景的广泛配置:
参数类型默认值描述
num_resultsint10返回的最大结果数(1-20)
deep_searchboolTrue深度模式(默认)用于完整内容提取,快速模式(False)仅获取 SERP 结果
topicstr”general”针对特定内容类型优化搜索:“general”、“news” 或 “location”
include_answerboolFalse在搜索结果旁边生成 AI 驱动的摘要回答
include_domainslist[str]None白名单特定域名(如 [“wikipedia.org”, “.edu”])
exclude_domainslist[str]None黑名单特定域名以过滤掉不想要的内容
start_datestrNone过滤指定日期之后的结果(YYYY-MM-DD 或 YYYY)
end_datestrNone过滤指定日期之前的结果(YYYY-MM-DD 或 YYYY)
parsing_typestr”markdown”输出格式:“plain_text”、“markdown” 或 “simplified_html”
localestr”en”搜索区域(如 “en-US”)
countrystr”US”本地化结果的国家代码(如 “US”)
api_keystrenv varNimble API 密钥(默认为 NIMBLE_API_KEY 环境变量)

最佳实践

快速模式与深度模式

  • 深度模式deep_search=True,默认):
    • 从网页提取完整内容
    • 最适合详细分析、RAG 应用和全面研究
    • 处理 JavaScript 渲染和动态内容
  • 快速模式deep_search=False):
    • 仅包含标题和摘要的快速 SERP 结果
    • 针对速度至关重要的高吞吐量查询进行优化
    • 每次查询成本更低

何时使用 include_answer

  • 当您希望在原始搜索结果之外获得简洁的 AI 生成摘要时,启用 include_answer=True
  • 适用于无需自行处理所有原始内容即可快速获取洞见的场景

过滤技巧

  • 域名过滤:使用 include_domains 进行学术研究或需要可信来源时;使用 exclude_domains 过滤掉不需要的内容类型
  • 日期过滤:结合 start_dateend_date 进行时效性查询或最新新闻搜索
  • 主题路由:使用 topic 参数针对通用网页内容、新闻文章或基于位置的信息优化搜索

性能优化

  • 选择合适的模式:高吞吐量查询时使用快速模式deep_search=False);全面内容提取时使用深度模式(默认)
  • 并发运行多个搜索时使用异步操作(ainvoke
  • num_results 调整为所需的最小结果数以减少响应时间
  • 利用域名过滤聚焦于优质来源并减少噪音

API 参考

有关所有 NimbleSearchRetriever 功能和配置的详细文档,请访问 Nimble API 文档