跳到主要内容
Valyu 允许 AI 应用和代理搜索互联网和专有数据源,以获取 LLM 就绪的相关信息。
本笔记本介绍了如何在 LangChain 中使用 Valyu。 首先,获取 Valyu API 密钥并将其添加为环境变量。通过在此处注册可获得 10 美元的免费积分。

设置

该集成位于 langchain-valyu 包中。
pip install -qU langchain-valyu
为了使用该包,您还需要将 VALYU_API_KEY 环境变量设置为您的 Valyu API 密钥。

上下文检索器

您可以在标准检索管道中使用ValyuContextRetriever
from langchain_valyu import ValyuRetriever

valyu_api_key = "YOUR API KEY"

# Create a new instance of the ValyuRetriever
valyu_retriever = ValyuRetriever(
    k=5,
    search_type="all",
    relevance_threshold=0.5,
    max_price=20.0,
    start_date="2024-01-01",
    end_date="2024-12-31",
    valyu_api_key=valyu_api_key,
)

# Search for a query and save the results
docs = valyu_retriever.invoke("What are the benefits of renewable energy?")

# Print the results
for doc in docs:
    print(doc.page_content)
    print(doc.metadata)

上下文搜索工具

您可以将 ValyuSearchTool 用于高级搜索查询。
from langchain_valyu import ValyuSearchTool

# Initialize the ValyuSearchTool
search_tool = ValyuSearchTool(valyu_api_key="YOUR API KEY")

# Perform a search query
search_results = search_tool._run(
    query="What are agentic search-enhanced large reasoning models?",
    search_type="all",
    max_num_results=5,
    relevance_threshold=0.5,
    max_price=20.0,
    start_date="2024-01-01",
    end_date="2024-12-31",
)

print("Search Results:", search_results)

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