Skip to content

Ferret + LangChain Integration

This directory provides LangChain-compatible tools for the Ferret web search engine.

Tools

ToolDescriptionEndpoint
FerretSearchToolMulti-engine web searchGET /search
FerretResearchToolDeep research with aggregationPOST /research
FerretExtractToolExtract raw content from URLGET /extract
FerretCrawlToolCrawl URL for raw contentGET /crawl/v1

Quick Start

from langchain_ferret import FerretSearchTool, FerretResearchTool

# Search
search = FerretSearchTool()
results = search.run("latest AI news")
print(results)

# Research
research = FerretResearchTool()
answer = research.run("Impact of quantum computing on cryptography")
print(answer)

Usage with LangChain Agent

from langchain.agents import initialize_agent, AgentType
from langchain_ferret import FerretSearchTool, FerretExtractTool
from langchain_openai import ChatOpenAI

tools = [FerretSearchTool(), FerretExtractTool()]
llm = ChatOpenAI(model="gpt-4")
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)
agent.run("Search for latest AI news and extract the content from the top result")

Requirements

pip install langchain requests
# or: pip install langchain-openai  # for OpenAI-based agents

Make sure Ferret is running on http://localhost:9093:

ferret serve