Skip to main content

An integration package connecting Valyu and LangChain

Project description

langchain-valyu

This package contains the LangChain integration with Valyu

Installation

pip install -U langchain-valyu

Note: This package requires valyu >= 2.0.0 for the updated search API.

And you should configure credentials by setting the following environment variable:

  • VALYU_API_KEY (required): Your Valyu API key.

Valyu Search Tool

You can use ValyuSearchTool directly for search operations:

import os
from langchain_valyu import ValyuSearchTool

# Set your API key
os.environ["VALYU_API_KEY"] = "your-api-key-here"

# Initialize the search tool
tool = ValyuSearchTool()

# Perform a search
search_results = tool._run(
    query="What are agentic search-enhanced large reasoning models?",
    search_type="all",  # "all", "web", or "proprietary"
    max_num_results=5,
    relevance_threshold=0.5,
    max_price=30.0
)

print("Search Results:", search_results.results)

Valyu Retriever

You can retrieve search results from Valyu's deep search API as documents:

from langchain_valyu import ValyuRetriever

# Initialize retriever
retriever = ValyuRetriever(
    k=5,  # Number of results
    search_type="proprietary",
    relevance_threshold=0.6,
    max_price=30.0
)

# Search for a query and get documents
docs = retriever.get_relevant_documents("What are the benefits of renewable energy?")

# Print the results
for doc in docs:
    print(f"Title: {doc.metadata['title']}")
    print(f"Content: {doc.page_content[:200]}...")
    print(f"Source: {doc.metadata['url']}")
    print("---")

Agent Integration

The most powerful way to use Valyu is within LangChain agents, where the AI can dynamically decide when and how to search:

import os
from langchain_valyu import ValyuSearchTool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage

# Set API keys
os.environ["VALYU_API_KEY"] = "your-valyu-api-key"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-api-key"

# Initialize components
llm = ChatAnthropic(model="claude-3-5-sonnet-20241022")
valyu_search_tool = ValyuSearchTool()

# Create agent with Valyu search capability
agent = create_react_agent(llm, [valyu_search_tool])

# Use the agent
user_input = "What are the key factors driving recent stock market volatility, and how do macroeconomic indicators influence equity prices across different sectors?"

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

Academic Research Example

Configure for academic research with proprietary data sources:

from langchain_valyu import ValyuSearchTool

# Configure for academic research
academic_tool = ValyuSearchTool()

# Search academic sources specifically
academic_results = academic_tool._run(
    query="CRISPR gene editing safety protocols",
    search_type="proprietary",  # Focus on academic datasets
    max_num_results=8,
    relevance_threshold=0.6,
)

print("Academic Sources Found:", len(academic_results.results))
for result in academic_results.results:
    print(f"Title: {result['title']}")
    print(f"Source: {result['source']}")
    print(f"Relevance: {result['relevance_score']}")
    print("---")

You can learn more about our API from our docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_valyu-0.3.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_valyu-0.3.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file langchain_valyu-0.3.1.tar.gz.

File metadata

  • Download URL: langchain_valyu-0.3.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.9 Darwin/24.5.0

File hashes

Hashes for langchain_valyu-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b2834f3fc5eb7bed2dee3653f96d44d8a9bc0b27bc5b70cc6c2eeb36152d732c
MD5 64b2ac45ac5a28651c2c50890fec2c42
BLAKE2b-256 a2e417a686ceac05d588358c9c3c6cec9fe0e3ebc39a4b6ac005310d61b7692c

See more details on using hashes here.

File details

Details for the file langchain_valyu-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: langchain_valyu-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.9 Darwin/24.5.0

File hashes

Hashes for langchain_valyu-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f67321426e8c5d36ba981b7ad644703ed2387b50b4d9af2bccd37845caa898c
MD5 a385f6f2223636b4fbfde9da8544dea1
BLAKE2b-256 faf2e80a28c06eb49f43ce5d17f1f69f804dc3703217398bae2692c3a9557be0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page