>Nimble 的搜索 API 通过使用无头浏览器浏览实时网络而非查询预构建索引来提供实时网络搜索。该工具处理 JavaScript 渲染、动态内容和复杂的导航流程,适用于需要访问当前网络数据的代理工作流,包括分页、过滤器和客户端渲染背后的内容。
概览
集成详情
| 类 | 包 | 可序列化 | JS 支持 | 包最新版本 |
|---|---|---|---|---|
NimbleSearchTool | langchain-nimble | ❌ | ❌ | !PyPI - 版本 |
工具特性
| 返回产物 | 原生异步 | 返回数据 | 定价 |
|---|---|---|---|
| ❌ | ✅ | title, URL, content (markdown/plain_text/HTML), metadata | 免费试用可用 |
主要特性:
- 快速模式与深度模式: **深度模式** (默认)用于完整内容提取和 JavaScript 渲染,或 **快速模式** 用于快速获取仅限 SERP 的结果
- AI 生成的摘要:与原始搜索结果一起提供的可选简明答案
- 域名和日期过滤:按特定域名或日期范围过滤以获得精确结果
- 基于主题的路由:针对通用、新闻或基于位置的查询进行优化的路由
- 灵活的输出格式:纯文本_、markdown(默认)或简化_html
- Production-ready:原生异步支持、自动重试、连接池
设置
集成位于 langchain-nimble package.
pip install -U langchain-nimble
uv add langchain-nimble
凭证
您需要一个 Nimble API 密钥来使用此工具。在 Nimble 注册以获取您的 API 密钥并访问他们的免费试用。
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 的完整示例:
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."
stream = agent.stream_events({"messages": user_input}, version="v3")
for snapshot in stream.values:
snapshot["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_results | int | 10 | 返回的最大结果数量(1-20) |
deep_search | bool | True | **深度模式** (默认)用于完整内容提取,或 **快速模式** (False)用于仅限 SERP 的结果 |
topic | str | "general" | 针对特定内容类型优化搜索:"general"、"news" 或 "location" |
include_answer | bool | False | 与搜索结果一起生成 AI 驱动的摘要答案 |
include_domains | list[str] | None | 白名单特定域名(例如 ["wikipedia.org", ".edu"]) |
exclude_domains | list[str] | None | 要过滤掉的黑名单特定域名 |
start_date | str | None | 按日期过滤结果,在该日期之后 (YYYY-MM-DD 或 YYYY) |
end_date | str | None | 按日期过滤结果,在该日期之前 (YYYY-MM-DD 或 YYYY) |
parsing_type | str | "markdown" | 输出格式: "plain_text"、"markdown" 或 "simplified_html" |
locale | str | "en" | 搜索语言区域 (例如 "en-US") |
country | str | "US" | 本地化结果的国家代码 (例如 "US") |
api_key | str | env var | Nimble API 密钥 (默认为 NIMBLE_API_KEY 环境变量) |
最佳实践
快速模式 vs 深度模式
- 深度模式 (
deep_search=True,默认): - - 从网页中提取完整内容
- - 最适合详细分析、RAG 应用和综合研究
- - 处理 JavaScript 渲染和动态内容
- 快速模式 (
deep_search=False): - - 仅返回快速的 SERP 结果,包含标题和摘要
- - 针对需要高速的高容量查询进行优化
- - 每次查询成本更低
何时使用 include_answer
- - 启用
include_answer=True当您除了原始搜索结果之外还需要简洁的 AI 生成摘要时 - - 有助于快速获取洞察,无需自行处理所有原始内容
过滤技巧
- 域名过滤:使用
include_domains用于学术研究或需要可信来源时。使用exclude_domains来过滤掉不需要的内容类型 - 日期过滤:结合使用
start_date和end_date来处理时间敏感的查询或最新新闻 - 主题路由:使用
topic参数来优化搜索一般网页内容、新闻文章或基于位置的信息
性能优化
- 选择正确的模式:使用 **快速模式** (
deep_search=False)用于需要速度的高容量查询; **深度模式** (默认)用于全面内容提取 - - 使用异步操作(
ainvoke)在同时运行多个搜索时 - - 调整
num_results至所需的最小结果数量以减少响应时间 - - 利用域名过滤来聚焦高质量来源并减少噪音
API 参考
有关所有 NimbleSearchRetriever 功能和配置的详细文档,请访问 Nimble API 文档.