Documentation Index
Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
Use this file to discover all available pages before exploring further.
Nimble 的搜索 API 提供实时网络搜索,通过无头浏览器浏览实时网络,而不是查询预构建的索引。该工具处理 JavaScript 渲染、动态内容和复杂的导航流程,使其适用于需要访问当前网络数据的代理工作流,包括分页、过滤器和客户端渲染后的内容。
集成详情
工具功能
| 返回工件 | 原生异步 | 返回数据 | 定价 |
|---|
| ❌ | ✅ | title, URL, content (markdown/plain_text/HTML), metadata | 提供免费试用 |
主要功能:
- 快速模式与深度模式:深度模式(默认)用于完整内容提取并启用 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_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 环境变量) |
最佳实践
快速模式与深度模式
-
深度模式 (
deep_search=True, 默认):
- 从网页中提取完整内容
- 最适合详细分析、RAG 应用和综合研究
- 处理 JavaScript 渲染和动态内容
-
快速模式 (
deep_search=False):
- 快速获取仅包含标题和摘要的 SERP 结果
- 针对速度至关重要的海量查询进行了优化
- 单次查询成本更低
何时使用 include_answer
- 当您希望在原始搜索结果之外获得简洁的 AI 生成摘要时,启用
include_answer=True
- 无需自行处理所有原始内容即可获得快速见解,非常有用
过滤技巧
- 域名过滤:使用
include_domains 进行学术研究或需要可信来源时。使用 exclude_domains 过滤不需要的内容类型
- 日期过滤:结合
start_date 和 end_date 用于对时间敏感的查询或最新新闻
- 主题路由:使用
topic 参数优化通用网络内容、新闻文章或基于位置信息的搜索
性能优化
- 选择合适的模式:对于速度至关重要的海量查询使用快速模式 (
deep_search=False);对于完整内容提取使用深度模式(默认)
- 并发运行多个搜索时使用异步操作 (
ainvoke)
- 将
num_results 调整为所需的最小结果数以减少响应时间
- 利用域名过滤专注于高质量来源并减少噪音
API 参考
有关所有 NimbleSearchRetriever 功能和配置的详细文档,请访问 Nimble API 文档。