Skip to main content
Open In ColabOpen on GitHub

ValyuContext

Valyu allows AI applications and agents to search the internet and proprietary data sources for relevant LLM ready information.

This notebook goes over how to use Valyu in LangChain.

First, get an Valyu API key and add it as an environment variable. Get $10 free credit by signing up here.

Setup

The integration lives in the langchain-valyu package.

%pip install -qU langchain-valyu

In order to use the package, you will also need to set the VALYU_API_KEY environment variable to your Valyu API key.

Context Retriever

You can use the ValyuContextRetriever in a standard retrieval pipeline.

from langchain_valyu import ValyuContextRetriever

valyu_api_key = "YOUR API KEY"

# Create a new instance of the ValyuContextRetriever
valyu_retriever = ValyuContextRetriever(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)

Context Search Tool

You can use the ValyuSearchTool for advanced search queries.

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,
similarity_threshold=0.4,
query_rewrite=False,
max_price=20.0,
)

print("Search Results:", search_results)

Was this page helpful?