Skip to main content
Ctrl+K

๐Ÿฆœ๐Ÿ”— LangChain 0.0.107

Getting Started

  • Quickstart Guide

Modules

  • Prompt Templates
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Create a custom prompt template
      • Create a custom example selector
      • Provide few shot examples to a prompt
      • Prompt Serialization
      • Example Selectors
    • Reference
      • PromptTemplates
      • Example Selector
  • LLMs
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Generic Functionality
        • Custom LLM
        • Fake LLM
        • LLM Caching
        • LLM Serialization
        • Token Usage Tracking
      • Integrations
        • AI21
        • Aleph Alpha
        • Anthropic
        • Azure OpenAI LLM Example
        • Banana
        • CerebriumAI LLM Example
        • Cohere
        • DeepInfra LLM Example
        • ForefrontAI LLM Example
        • GooseAI LLM Example
        • Hugging Face Hub
        • Manifest
        • Modal
        • OpenAI
        • Petals LLM Example
        • PromptLayer OpenAI
        • Self-Hosted Models via Runhouse
        • StochasticAI
        • Writer
      • Async API for LLM
      • Streaming with LLMs
    • Reference
  • Document Loaders
    • Key Concepts
    • How To Guides
      • CoNLL-U
      • Airbyte JSON
      • AZLyrics
      • College Confidential
      • Copy Paste
      • CSV Loader
      • Directory Loader
      • Email
      • EverNote
      • Facebook Chat
      • GCS Directory
      • GCS File Storage
      • GitBook
      • Google Drive
      • Gutenberg
      • Hacker News
      • HTML
      • iFixit
      • Images
      • IMSDb
      • Markdown
      • Microsoft Word
      • Notebook
      • Notion
      • Obsidian
      • Online PDF
      • PDF
      • PowerPoint
      • ReadTheDocs Documentation
      • Roam
      • s3 Directory
      • s3 File
      • Subtitle Files
      • Telegram
      • Unstructured File Loader
      • URL
      • Web Base
      • Word Documents
      • YouTube
  • Utils
    • Key Concepts
    • Generic Utilities
      • Bash
      • Bing Search
      • Google Search
      • Google Serper API
      • IFTTT WebHooks
      • Python REPL
      • Requests
      • SearxNG Search API
      • SerpAPI
      • Wolfram Alpha
    • Reference
      • Python REPL
      • SerpAPI
      • SearxNG Search
      • Docstore
      • Text Splitter
      • Embeddings
      • VectorStores
  • Indexes
    • Getting Started
    • Key Concepts
    • How To Guides
      • Embeddings
      • Hypothetical Document Embeddings
      • Text Splitter
      • VectorStores
      • AtlasDB
      • Chroma
      • Deep Lake
      • ElasticSearch
      • FAISS
      • Milvus
      • OpenSearch
      • Pinecone
      • Qdrant
      • Weaviate
      • Analyze Document
      • Chat Vector DB
      • Graph QA
      • Question Answering with Sources
      • Question Answering
      • Summarization
      • Vector DB Question/Answering
      • VectorDB Question Answering with Sources
      • Vector DB Text Generation
  • Chains
    • Getting Started
    • How-To Guides
      • Generic Chains
        • Loading from LangChainHub
        • LLM Chain
        • Sequential Chains
        • Serialization
        • Transformation Chain
      • Utility Chains
        • API Chains
        • Self-Critique Chain with Constitutional AI
        • BashChain
        • LLMCheckerChain
        • LLM Math
        • LLMRequestsChain
        • LLMSummarizationCheckerChain
        • Moderation
        • PAL
        • SQLite example
      • Async API for Chain
    • Key Concepts
    • Reference
  • Agents
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Agents and Vectorstores
      • Async API for Agent
      • Custom Agent
      • Defining Custom Tools
      • Intermediate Steps
      • Loading from LangChainHub
      • Max Iterations
      • Multi Input Tools
      • Search Tools
      • Serialization
      • CSV Agent
      • JSON Agent
      • OpenAPI Agent
      • Pandas Dataframe Agent
      • Python Agent
      • SQL Database Agent
      • Vectorstore Agent
      • MRKL
      • MRKL Chat
      • ReAct
      • Self Ask With Search
    • Reference
  • Memory
    • Getting Started
    • Key Concepts
    • How-To Guides
      • ConversationBufferMemory
      • ConversationBufferWindowMemory
      • Entity Memory
      • Conversation Knowledge Graph Memory
      • ConversationSummaryMemory
      • ConversationSummaryBufferMemory
      • Adding Memory To an LLMChain
      • Adding Memory to a Multi-Input Chain
      • Adding Memory to an Agent
      • ChatGPT Clone
      • Conversation Agent
      • Conversational Memory Customization
      • Custom Memory
      • Multiple Memory
  • Chat
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Agent
      • Chat Vector DB
      • Few Shot Examples
      • Memory
      • PromptLayer ChatOpenAI
      • Streaming
      • Vector DB Question/Answering
      • VectorDB Question Answering with Sources

Use Cases

  • Agents
  • Chatbots
  • Generate Examples
  • Data Augmented Generation
  • Question Answering
  • Summarization
  • Evaluation
    • Data Augmented Question Answering
    • Using Hugging Face Datasets
    • Question Answering
  • Model Comparison

Reference

  • Installation
  • Integrations
  • API References
    • Prompts
      • PromptTemplates
      • Example Selector
    • Utilities
      • Python REPL
      • SerpAPI
      • SearxNG Search
      • Docstore
      • Text Splitter
      • Embeddings
      • VectorStores
    • Chains
    • Agents

Ecosystem

  • LangChain Ecosystem
    • AI21 Labs
    • AtlasDB
    • Banana
    • CerebriumAI
    • Chroma
    • Cohere
    • DeepInfra
    • Deep Lake
    • ForefrontAI
    • Google Search Wrapper
    • Google Serper Wrapper
    • GooseAI
    • Graphsignal
    • Hazy Research
    • Helicone
    • Hugging Face
    • Modal
    • NLPCloud
    • OpenAI
    • OpenSearch
    • Petals
    • Pinecone
    • PromptLayer
    • Runhouse
    • SearxNG Search API
    • SerpAPI
    • StochasticAI
    • Unstructured
    • Weaviate
    • Wolfram Alpha Wrapper
    • Writer

Additional Resources

  • LangChainHub
  • Glossary
  • LangChain Gallery
  • Deployments
  • Tracing
  • Discord
  • Production Support
  • .rst

SearxNG Search

Contents

  • Quick Start
  • Searching
  • Engine Parameters
  • Search Tips

SearxNG Search#

Utility for using SearxNG meta search API.

SearxNG is a privacy-friendly free metasearch engine that aggregates results from multiple search engines and databases and supports the OpenSearch specification.

More detailes on the installtion instructions here.

For the search API refer to https://docs.searxng.org/dev/search_api.html

Quick Start#

In order to use this tool you need to provide the searx host. This can be done by passing the named parameter searx_host or exporting the environment variable SEARX_HOST. Note: this is the only required parameter.

Then create a searx search instance like this:

from langchain.utilities import SearxSearchWrapper

# when the host starts with `http` SSL is disabled and the connection
# is assumed to be on a private network
searx_host='http://self.hosted'

search = SearxSearchWrapper(searx_host=searx_host)

You can now use the search instance to query the searx API.

Searching#

Use the run() and results() methods to query the searx API. Other methods are are available for convenience.

SearxResults is a convenience wrapper around the raw json result.

Example usage of the run method to make a search:

s.run(query="what is the best search engine?")

Engine Parameters#

You can pass any accepted searx search API parameters to the SearxSearchWrapper instance.

In the following example we are using the engines and the language parameters:

# assuming the searx host is set as above or exported as an env variable
s = SearxSearchWrapper(engines=['google', 'bing'],
                    language='es')

Search Tips#

Searx offers a special search syntax that can also be used instead of passing engine parameters.

For example the following query:

s = SearxSearchWrapper("langchain library", engines=['github'])

# can also be written as:
s = SearxSearchWrapper("langchain library !github")
# or even:
s = SearxSearchWrapper("langchain library !gh")

In some situations you might want to pass an extra string to the search query. For example when the run() method is called by an agent. The search suffix can also be used as a way to pass extra parameters to searx or the underlying search engines.

# select the github engine and pass the search suffix
s = SearchWrapper("langchain library", query_suffix="!gh")


s = SearchWrapper("langchain library")
# select github the conventional google search syntax
s.run("large language models", query_suffix="site:github.com")

NOTE: A search suffix can be defined on both the instance and the method level. The resulting query will be the concatenation of the two with the former taking precedence.

See SearxNG Configured Engines and SearxNG Search Syntax for more details.

Notes

This wrapper is based on the SearxNG fork searxng/searxng which is better maintained than the original Searx project and offers more features.

Public searxNG instances often use a rate limiter for API usage, so you might want to use a self hosted instance and disable the rate limiter.

If you are self-hosting an instance you can customize the rate limiter for your own network as described here.

For a list of public SearxNG instances see https://searx.space/

class langchain.utilities.searx_search.SearxResults(data: str)[source]#

Dict like wrapper around search api results.

property answers: Any#

Helper accessor on the json result.

pydantic model langchain.utilities.searx_search.SearxSearchWrapper[source]#

Wrapper for Searx API.

To use you need to provide the searx host by passing the named parameter searx_host or exporting the environment variable SEARX_HOST.

In some situations you might want to disable SSL verification, for example if you are running searx locally. You can do this by passing the named parameter unsecure. You can also pass the host url scheme as http to disable SSL.

Example

from langchain.utilities import SearxSearchWrapper
searx = SearxSearchWrapper(searx_host="http://localhost:8888")
Example with SSL disabled:
from langchain.utilities import SearxSearchWrapper
# note the unsecure parameter is not needed if you pass the url scheme as
# http
searx = SearxSearchWrapper(searx_host="http://localhost:8888",
                                        unsecure=True)
Validators
  • disable_ssl_warnings ยป unsecure

  • validate_params ยป all fields

field engines: Optional[List[str]] = []#
field headers: Optional[dict] = None#
field k: int = 10#
field params: dict [Optional]#
field query_suffix: Optional[str] = ''#
field searx_host: str = ''#
field unsecure: bool = False#
results(query: str, num_results: int, engines: Optional[List[str]] = None, query_suffix: Optional[str] = '', **kwargs: Any) → List[Dict][source]#

Run query through Searx API and returns the results with metadata.

Parameters
  • query โ€“ The query to search for.

  • query_suffix โ€“ Extra suffix appended to the query.

  • num_results โ€“ Limit the number of results to return.

  • engines โ€“ List of engines to use for the query.

  • **kwargs โ€“ extra parameters to pass to the searx API.

Returns

{

snippet: The description of the result.

title: The title of the result.

link: The link to the result.

engines: The engines used for the result.

category: Searx category of the result.

}

Return type

Dict with the following keys

run(query: str, engines: Optional[List[str]] = None, query_suffix: Optional[str] = '', **kwargs: Any) → str[source]#

Run query through Searx API and parse results.

You can pass any other params to the searx query API.

Parameters
  • query โ€“ The query to search for.

  • query_suffix โ€“ Extra suffix appended to the query.

  • engines โ€“ List of engines to use for the query.

  • **kwargs โ€“ extra parameters to pass to the searx API.

Example

This will make a query to the qwant engine:

from langchain.utilities import SearxSearchWrapper
searx = SearxSearchWrapper(searx_host="http://my.searx.host")
searx.run("what is the weather in France ?", engine="qwant")

# the same result can be achieved using the `!` syntax of searx
# to select the engine using `query_suffix`
searx.run("what is the weather in France ?", query_suffix="!qwant")

previous

SerpAPI

next

Docstore

Contents
  • Quick Start
  • Searching
  • Engine Parameters
  • Search Tips

By Harrison Chase

ยฉ Copyright 2022, Harrison Chase.